From c33c11d8fd394413584a6f9ee5b8e9a8eae04c28 Mon Sep 17 00:00:00 2001 From: xaoxuu Date: Sun, 1 Mar 2020 00:21:57 +0800 Subject: [PATCH] =?UTF-8?q?SEO=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _config.yml | 8 +++ languages/en.yml | 4 ++ languages/zh-CN.yml | 4 ++ languages/zh-TW.yml | 4 ++ layout/_partial/head.ejs | 102 +++++++++++++++++++++++++-------------- 5 files changed, 86 insertions(+), 36 deletions(-) diff --git a/_config.yml b/_config.yml index 9b7d279..b1a4c3f 100755 --- a/_config.yml +++ b/_config.yml @@ -446,6 +446,14 @@ aplayer: list_max_height: 340px # list max height list_folded: true + +robots: + home: index,follow + archive: noindex,follow + category: noindex,follow + tag: noindex,follow +# 其它页面自己在front-matter中写 + ############################### 需要复制到根目录配置文件中 ############################### # 请复制到根目录配置文件! # copyright: '[Copyright © 2017-2020 Mr. X](https://xaoxuu.com)' diff --git a/languages/en.yml b/languages/en.yml index bfb2ff8..9afc34b 100755 --- a/languages/en.yml +++ b/languages/en.yml @@ -1,3 +1,7 @@ +navbar: + archive: Archive + category: Category + tag: Tag post: top: Top read_more: Read More diff --git a/languages/zh-CN.yml b/languages/zh-CN.yml index 1048e46..149f9f1 100755 --- a/languages/zh-CN.yml +++ b/languages/zh-CN.yml @@ -1,3 +1,7 @@ +navbar: + archive: 归档 + category: 分类 + tag: 标签 post: top: 置顶 read_more: 阅读全文 diff --git a/languages/zh-TW.yml b/languages/zh-TW.yml index 8e1e7d1..c9fc4ff 100755 --- a/languages/zh-TW.yml +++ b/languages/zh-TW.yml @@ -1,3 +1,7 @@ +navbar: + archive: 歸檔 + category: 分類 + tag: 標籤 post: top: 置頂 read_more: 閱讀全文 diff --git a/layout/_partial/head.ejs b/layout/_partial/head.ejs index 03026ad..6f54af8 100755 --- a/layout/_partial/head.ejs +++ b/layout/_partial/head.ejs @@ -1,47 +1,76 @@ - + - + + <% if (page.robots) { %> + + <% } else if (theme.robots) { %> + <% if (is_home()) { %> + + <% } else if (is_archive()) { %> + + <% } else if (is_category()) { %> + + <% } else if (is_tag()) { %> + + <% } %> + <% } %> + + + + + + + + + <% var title = page.title; + var keywords = page.keywords || ''; + var description = page.description || ''; if (is_archive()) { - title = 'Archives'; - if (is_month()) - title += ': ' + page.year + '/' + page.month; - else if (is_year()) - title += ': ' + page.year; + title = __('navbar.archive'); + if (is_month()) { + title += __('symbol.colon') + page.year + '/' + page.month; + } else if (is_year()) { + title += __('symbol.colon') + page.year; + } + } else if (is_category()) { + title = __('navbar.category') + __('symbol.colon') + page.category; + } else if (is_tag()) { + title = __('navbar.tag') + __('symbol.colon') + page.tag; + } + if (!keywords && page.tags && page.tags.length > 0) { + let tags = page.tags.map(function(t){return t.name}).join(','); + if (tags.length > 0) { + keywords += tags; + } + } + if (page.description == undefined) { + if (page.excerpt) { + description = truncate(strip_html(page.excerpt), {length: 240}); + } else if (page.more) { + description = truncate(strip_html(page.more), {length: 240}); + } } - else if (is_category()) - title = 'Category: ' + page.category; - else if (is_tag()) - title = 'Tag: ' + page.tag; %> - <% if (title) { %><%= title %> | <% } %><%= config.title %> - <% if (page.keywords && config.keywords){ %> - - <% } else if (page.keywords) { %> - - <% } else if (config.keywords) { %> - + <% if (title) { %><%= title %> - <% } %><%= config.title %> + <% if (keywords){ %> + <% } %> - <% if (page.description && config.description){ %> - - <% } else if (page.description) { %> - - <% } else if (config.description) { %> - + <% if (description){ %> + <% } %> + <% if (config.feed && config.feed.path){ %> - <%- feed_tag(config.feed.path, {title: config.title}) %> + <%- feed_tag(config.feed.path, {title: config.title}) %> <% } %> - - - - + <% if (config.import && config.import.meta){ %> - <% (config.import.meta||[]).forEach(function(item){ %> - <%- item %><% }) %> + <% (config.import.meta||[]).forEach(function(item){ %> + <%- item %> + <% }) %> <% } %> @@ -53,11 +82,6 @@ <%- css(theme.plugins.nodewaves.css) %> <% } %> - <% if (config.import && config.import.link){ %> - <% (config.import.link||[]).forEach(function(item){ %> - <%- item %><% }) %> - <% } %> - <% if (config.favicon) { %> <% } %> @@ -66,6 +90,12 @@ <% } %> + + <% if (config.import && config.import.link){ %> + <% (config.import.link||[]).forEach(function(item){ %> + <%- item %><% }) %> + <% } %> + <% if (config.use_cdn && theme.info && theme.info.cdn && theme.info.cdn.css && theme.info.cdn.css.style) { %> <%- css(theme.info.cdn.css.style) %> <% } else { %>