From 05945824e4f47e44a7a647a0e6c568181d4132f1 Mon Sep 17 00:00:00 2001 From: Tunghsiao Liu Date: Mon, 28 Nov 2016 21:43:57 +0800 Subject: [PATCH] feat(curtana): better meddia detection for Twitter Cards and Open Graph --- _app/_includes/_amsf.html | 30 +++++++++++++++---- .../themes/curtana/includes/open-graph.html | 10 ++----- .../themes/curtana/includes/top.html | 8 ++--- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/_app/_includes/_amsf.html b/_app/_includes/_amsf.html index fd1592fb1..4c54cf673 100644 --- a/_app/_includes/_amsf.html +++ b/_app/_includes/_amsf.html @@ -28,10 +28,8 @@ {% if page.permalink != '/' %} {% if page.desc %} {{ page.desc | strip_html | strip_newlines | xml_escape }} - {% elsif page.excerpt %} - {{ page.excerpt | strip_html | strip_newlines | xml_escape | truncatewords: 50 }} {% else %} - {{ page.content | markdownify | strip_html | xml_escape | truncatewords: 50 | truncate: 210 }} + {{ page.content | markdownify | strip_html | normalize_whitespace | xml_escape | truncate: 300 | truncatewords: 40 }} {% endif %} {% else %} {{ site.description }} @@ -58,6 +56,13 @@ {% endcomment %} {% capture amsf_user_assets %}{{ site.assets | prepend: site.base }}{% endcapture %} +{% comment %} + Favicons +{% endcomment %} +{% capture amsf_favicon %}{{ '/favicon.ico' | prepend: site.base }}{% endcapture %} +{% capture amsf_favicon_svg %}{{ '/favicon.svg' | prepend: site.base }}{% endcapture %} +{% capture amsf_apple_touch_icon %}{{ '/apple-touch-icon.png' | prepend: site.base }}{% endcapture %} + {% comment %} Feed URL {% endcomment %} @@ -78,7 +83,6 @@ {% endcomment %} {% capture amsf_page_pubdate %}{{ page.date }}{% endcapture %} - {% comment %} Page update date {% endcomment %} @@ -185,8 +189,24 @@ {% comment %} Page thumbnail {% endcomment %} +{% capture amsf_post_first_image %} + {% assign post_images = page.content | split: "" | first | match_regex: 'src="([^"]+)"' %} + {% break %} + {% endif %} + {% endfor %} + {{ hero_image }} +{% endcapture %} + {% capture amsf_page_thumb %} - {{ site.file }}/thumb/{% if page.thumb %}{{ page.thumb }}{% else %}na.png{% endif %} + {% if page.thumb %} + {{ site.file }}/thumb/{% if page.thumb %}{{ page.thumb }}{% else %}na.png{% endif %} + {% else %} + {{ amsf_post_first_image }} + {% endif %} {% endcapture %} {% comment %} diff --git a/_app/_includes/themes/curtana/includes/open-graph.html b/_app/_includes/themes/curtana/includes/open-graph.html index 08e9cd88c..de3262484 100644 --- a/_app/_includes/themes/curtana/includes/open-graph.html +++ b/_app/_includes/themes/curtana/includes/open-graph.html @@ -7,16 +7,17 @@ + + -{% if page.path contains '_posts' %} +{% if page.path contains "_posts" %} - @@ -30,8 +31,3 @@ {% if author.twitter %} {% endif %} - -{% if page.thumb %} - - -{% endif %} diff --git a/_app/_includes/themes/curtana/includes/top.html b/_app/_includes/themes/curtana/includes/top.html index 1ec178dd6..67af369b4 100644 --- a/_app/_includes/themes/curtana/includes/top.html +++ b/_app/_includes/themes/curtana/includes/top.html @@ -16,12 +16,12 @@ {% if site.base != "" %} - - + + {% endif %} - + @@ -30,7 +30,7 @@ -{% if page.permalink == '/' %}{% endif %} +{% if page.permalink == "/" %}{% endif %}