Fix SEO title when it contains a vertical bar (#3113)

* Do not markdownify title

* Support markup in titles

* Support markup in titles

* Fix seo.html as reviewed

* seo_title is now unconditionally computed

---------

Co-authored-by: iBug <git@ibugone.com>
This commit is contained in:
Lars Olesen 2024-05-05 12:07:23 +02:00 committed by GitHub
parent 9c386c5509
commit dfaac405f0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 12 deletions

View File

@ -4,15 +4,13 @@
{%- endif -%}
{%- assign seo_url = seo_url | default: site.github.url -%}
{% assign title_separator = site.title_separator | default: '-' | replace: '|', '&#124;' %}
{% assign title_separator = site.title_separator | default: '-' %}
{%- if page.title -%}
{%- assign seo_title = page.title | append: " " | append: title_separator | append: " " | append: site.title -%}
{%- endif -%}
{%- assign page_title = page.title | default: site.title | replace: '|', '&#124;' -%}
{%- assign seo_title = page_title | append: " " | append: title_separator | append: " " | append: site.title | replace: '|', '&#124;' -%}
{%- if seo_title -%}
{%- assign seo_title = seo_title | markdownify | strip_html | strip_newlines | escape_once -%}
{%- endif -%}
{%- assign page_title = page_title | markdownify | strip_html | strip_newlines | escape_once -%}
{%- assign seo_title = seo_title | markdownify | strip_html | strip_newlines | escape_once -%}
{% if page.canonical_url %}
{%- assign canonical_url = page.canonical_url %}
@ -47,7 +45,7 @@
{%- assign og_type = "website" -%}
{%- endif -%}
<title>{{ seo_title | default: site.title }}{% if paginator %}{% unless paginator.page == 1 %} {{ title_separator }} {{ site.data.ui-text[site.locale].page | default: "Page" }} {{ paginator.page }}{% endunless %}{% endif %}</title>
<title>{{ seo_title }}{% if paginator %}{% unless paginator.page == 1 %} {{ title_separator }} {{ site.data.ui-text[site.locale].page | default: "Page" }} {{ paginator.page }}{% endunless %}{% endif %}</title>
<meta name="description" content="{{ seo_description }}">
{% if author.name %}
@ -60,7 +58,7 @@
<meta property="og:type" content="{{ og_type }}">
<meta property="og:locale" content="{{ site.locale | replace: "-", "_" | default: "en_US" }}">
<meta property="og:site_name" content="{{ site.title }}">
<meta property="og:title" content="{{ page.title | default: site.title | markdownify | strip_html | strip_newlines | escape_once }}">
<meta property="og:title" content="{{ page_title }}">
<meta property="og:url" content="{{ canonical_url }}">
{% if seo_description %}
@ -75,7 +73,7 @@
{% if site.twitter.username %}
<meta name="twitter:site" content="@{{ site.twitter.username | replace: "@", "" }}">
<meta name="twitter:title" content="{{ page.title | default: site.title | markdownify | strip_html | strip_newlines | escape_once }}">
<meta name="twitter:title" content="{{ page_title }}">
<meta name="twitter:description" content="{{ seo_description }}">
<meta name="twitter:url" content="{{ canonical_url }}">

View File

@ -23,4 +23,4 @@ layout: default
{% endunless %}
{{ content }}
</div>
</div>
</div>

View File

@ -22,7 +22,7 @@ layout: default
{% include sidebar.html %}
<article class="page" itemscope itemtype="https://schema.org/CreativeWork">
{% if page.title %}<meta itemprop="headline" content="{{ page.title | markdownify | strip_html | strip_newlines | escape_once }}">{% endif %}
{% if page.title %}<meta itemprop="headline" content="{{ page.title | replace: '|', '&#124;' | markdownify | strip_html | strip_newlines | escape_once }}">{% endif %}
{% if page.excerpt %}<meta itemprop="description" content="{{ page.excerpt | markdownify | strip_html | strip_newlines | escape_once }}">{% endif %}
{% if page.date %}<meta itemprop="datePublished" content="{{ page.date | date_to_xmlschema }}">{% endif %}
{% if page.last_modified_at %}<meta itemprop="dateModified" content="{{ page.last_modified_at | date_to_xmlschema }}">{% endif %}