Skip to content

Commit

Permalink
Title template (#597)
Browse files Browse the repository at this point in the history
Move title generation to its own liquid template.
  • Loading branch information
bertuss authored Sep 20, 2021
1 parent de6250d commit 659bcb3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 39 deletions.
40 changes: 1 addition & 39 deletions _includes/head.html
Original file line number Diff line number Diff line change
@@ -1,43 +1,5 @@
{% include metadata %}

{% comment %} Determine the HTML <title>. Default is project title in meta.yml.
If we're in a book, the metadata include sets the book title as 'title'.
If the page has a title in its YAML frontmatter, append it after a colon,
unless (a) this is the home page, in which case only use the page title, or
(b) it's the same as the project/book title, in which case don't duplicate.

If we're generating a PDF, the first HTML doc in the file list will set
the entire PDF document title. So if we are outputting more than one file,
we want the doc name to be the book title, not only the first doc's title.
{% endcomment %}
{% capture html-title %}{{ project-name }}{% endcapture %}
{% if title and title != "" %}
{% capture html-title %}{{ title }}{% endcapture %}
{% endif %}
{% if page.title and page.title != "" %}
{% if html-title != page.title %}
{% if is-homepage %}
{% capture html-title %}{{ page.title }}{% endcapture %}
{% else %}
{% capture html-title %}{{ html-title }}: {{ page.title }}{% endcapture %}
{% endif %}
{% endif %}
{% endif %}

{% if site.output == "print-pdf" %}
{% if print-pdf-file-list.size > 1 %}
{% capture html-title %}{{ title }}{% endcapture %}
{% endif %}
{% endif %}

{% if site.output == "screen-pdf" %}
{% if screen-pdf-file-list.size > 1 %}
{% capture html-title %}{{ title }}{% endcapture %}
{% endif %}
{% endif %}

{% capture book-title %}{{ title }}{% endcapture %}

{% include title %}

{% if site.output == "print-pdf" %}
<!DOCTYPE html>
Expand Down
37 changes: 37 additions & 0 deletions _includes/title
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{% comment %}
Determine the HTML <title>. Default is project title in meta.yml.
If we're in a book, the metadata include sets the book title as 'title'.
If the page has a title in its YAML frontmatter, append it after a n-dash,
unless (a) this is the home page, in which case only use the page title, or
(b) it's the same as the project/book title, in which case don't duplicate.
{% endcomment %}

{% capture html-title %}{{ project-name }}{% endcapture %}
{% if title and title != "" %}
{% capture html-title %}{{ title }}{% endcapture %}
{% endif %}
{% if page.title and page.title != "" and html-title != page.title %}
{% if is-homepage %}
{% capture html-title %}{{ page.title }}{% endcapture %}
{% else %}
{% capture html-title %}{{ page.title }} &ndash; {{ html-title }}{% endcapture %}
{% endif %}
{% endif %}

{% comment %}
If we're generating a PDF, the first HTML doc in the file list will set
the entire PDF document title. So if we are outputting more than one file,
we want the doc name to be the book title, not only the first doc's title.
{% endcomment %}

{% if site.output == "print-pdf" %}
{% if print-pdf-file-list.size > 1 %}
{% capture html-title %}{{ title }}{% endcapture %}
{% endif %}
{% elsif site.output == "screen-pdf" %}
{% if screen-pdf-file-list.size > 1 %}
{% capture html-title %}{{ title }}{% endcapture %}
{% endif %}
{% endif %}

{% capture book-title %}{{ title }}{% endcapture %}

0 comments on commit 659bcb3

Please sign in to comment.