summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2015-08-24 20:48:35 +0200
committerHarald Eilertsen <haraldei@anduin.net>2015-08-24 20:48:35 +0200
commitea47219a2894d4fb304ae35e66b56e5e0e6e3827 (patch)
tree0e0855574748d34bcf811f38442b6998d393ae12
parent56eeb72ac5b71e70d2e14ae7b2fe620ab5e43441 (diff)
downloadnorsk-urskog-main-ea47219a2894d4fb304ae35e66b56e5e0e6e3827.tar.gz
norsk-urskog-main-ea47219a2894d4fb304ae35e66b56e5e0e6e3827.tar.bz2
norsk-urskog-main-ea47219a2894d4fb304ae35e66b56e5e0e6e3827.zip
Add new tag page_title to retreive translated page title if available.
If no translation exist, use default translation, and if no default translation, use the key unmodified. This makes the titles for posts work as expected.
-rw-r--r--blog/_includes/head.html7
-rw-r--r--blog/_includes/menubar.html4
-rw-r--r--blog/_plugins/page_title.rb21
3 files changed, 29 insertions, 3 deletions
diff --git a/blog/_includes/head.html b/blog/_includes/head.html
index 4a7c430..93f1512 100644
--- a/blog/_includes/head.html
+++ b/blog/_includes/head.html
@@ -2,7 +2,12 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
- <title>{{ site.title }}{% if page.title %} - {% t page.title %}{% endif %}</title>
+ <title>
+ {{ site.title }}
+ {% if page.title %}
+ - {% page_title page.title %}
+ {% endif %}
+ </title>
<meta name="description" content="{{ site.description }}">
<link rel="stylesheet" href="{{ "/css/main.css" | prepend: site.baseurl_root }}">
<link rel="canonical" href="{{ page.url | replace:'index.html','' | prepend: site.baseurl_root | prepend: site.url }}">
diff --git a/blog/_includes/menubar.html b/blog/_includes/menubar.html
index 04b6834..d81b896 100644
--- a/blog/_includes/menubar.html
+++ b/blog/_includes/menubar.html
@@ -1,8 +1,8 @@
<nav class="site-nav">
<a class="page-link" href="{{ site.baseurl }}">{% t titles.home %}</a>
{% for page in site.pages %}
- {% if page.title and page.hidden != true %}
- <a class="page-link" href="{{ page.url | prepend: site.baseurl }}">{% t {{ page.title }} %}</a>
+ {% if page.title %}
+ <a class="page-link" href="{{ page.url | prepend: site.baseurl }}">{% page_title page.title %}</a>
{% endif %}
{% endfor %}
</nav>
diff --git a/blog/_plugins/page_title.rb b/blog/_plugins/page_title.rb
new file mode 100644
index 0000000..039e859
--- /dev/null
+++ b/blog/_plugins/page_title.rb
@@ -0,0 +1,21 @@
+require "jekyll/multiple/languages/plugin"
+require "facets/kernel/silence"
+
+module Jekyll
+ class PageTitleTag < Liquid::Tag
+ def initialize(tag_name, text, tokens)
+ super
+ @key = text
+ end
+
+ def render(context)
+ text = silently do
+ t = Jekyll::LocalizeTag.new('t', @key, '')
+ t.render(context)
+ end
+ text || context[@key]
+ end
+ end
+end
+
+Liquid::Template.register_tag('page_title', Jekyll::PageTitleTag)