Browse Source

Move title generation code to extension

pull/136/head
Pieter Robberechts 1 year ago
parent
commit
82bf4d80a4
3 changed files with 28 additions and 11 deletions
  1. 2
    0
      languages/en.yml
  2. 1
    11
      layout/_partial/head.ejs
  3. 25
    0
      scripts/page_title.js

+ 2
- 0
languages/en.yml View File

@@ -2,6 +2,8 @@ nav:
home: Home
about: About
articles: Writing
tag: Tag
category: Category
projects: Projects
search: Search


+ 1
- 11
layout/_partial/head.ejs View File

@@ -1,13 +1,3 @@
<%
var title = page.title ? page.title : config.title;
if (page.category) title = page.category;
if (page.tag) title = page.tag;
if (page.archive){
if (page.year) title = page.year + (page.month ? '/' + page.month : '');
else title = __('Writing');
}
%>

<head>
<!-- so meta -->
<meta charset="utf-8">
@@ -46,7 +36,7 @@ if (page.archive){
<% } %>
<% } %>
<!-- title -->
<title><%= title %></title>
<title><%= page_title() %></title>
<!-- styles -->
<%- css('css/style') %>
<!-- persian styles -->

+ 25
- 0
scripts/page_title.js View File

@@ -0,0 +1,25 @@
/**
* Page Title Helper
* @description Generate page title.
* @example
* <%- page_title() %>
*/
hexo.extend.helper.register("page_title", function () {
var title = this.page.title ? this.page.title : this.config.title;

if (this.is_archive()) {
title = this.__("nav.articles");

if (this.is_month()) {
title += ": " + this.page.year + "/" + this.page.month;
} else if (this.is_year()) {
title += ": " + this.page.year;
}
} else if (this.is_category()) {
title = this.__("nav.category") + ": " + this.page.category;
} else if (this.is_tag()) {
title = this.__("nav.tag") + ": " + this.page.tag;
}

return title;
});

Loading…
Cancel
Save