Created
October 13, 2022 14:23
-
-
Save kidsil/39b1d8a14b56bbf6a9c93becc348586b to your computer and use it in GitHub Desktop.
Ultimate Jekyll meta_description conditional
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% comment %} TODO this should likely be resolved by proper layout usage (dedicated paginator page layout for starters) {% endcomment %} | |
{% assign meta_desc = site.description %} | |
{% unless page.url == '/' %} | |
{% if page.meta_description %} | |
{% capture meta_desc %}{{ page.meta_description }}{% endcapture %} | |
{% elsif page.excerpt %} | |
{% capture meta_desc %}{{ page.excerpt | strip_html | strip_newlines | truncate: 160 }}{% endcapture %} | |
{% elsif page.content %} | |
{% if page.content contains "for post in paginator.posts" %} | |
{% capture meta_desc %}{{ paginator.posts | first | strip_html | strip_newlines | strip | split: " - " | first | truncate: 160 }}{% endcapture %} | |
{% else %} | |
{% capture meta_desc %}{{ page.content | strip_html | strip_newlines | strip | truncate: 160 }}{% endcapture %} | |
{% endif %} | |
{% endif %} | |
{% endunless %} | |
{% endcapture %} | |
<meta name="description" content="{{ meta_desc }}"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment