From b0f60fb917d5667d6c16ef4b432127e69478d293 Mon Sep 17 00:00:00 2001 From: xaoxuu Date: Sun, 21 Feb 2021 04:01:17 +0800 Subject: [PATCH] update --- _config.yml | 3 +- layout/_partial/head.ejs | 20 ++++++--- .../_partial/main/article/related_posts.ejs | 3 +- layout/_partial/scripts/issues.ejs | 2 +- scripts/helpers/stellar_meta.js | 44 ------------------- 5 files changed, 19 insertions(+), 53 deletions(-) delete mode 100644 scripts/helpers/stellar_meta.js diff --git a/_config.yml b/_config.yml index 36735de..fb4c7cb 100755 --- a/_config.yml +++ b/_config.yml @@ -64,7 +64,6 @@ article: # npm i hexo-related-popular-posts related_posts: enable: false - title: meta.related_posts max_count: 5 placeholder_img: https://7.dusays.com/2021/02/20/76b86c0226ffd.svg # 分享文章 @@ -134,6 +133,8 @@ plugins: enable: true css: https://unpkg.com/swiper/swiper-bundle.min.css js: https://unpkg.com/swiper/swiper-bundle.min.js + # issues api + issuesjs: /js/issues.js ## optional plugins ## # preload diff --git a/layout/_partial/head.ejs b/layout/_partial/head.ejs index ada81c5..7d4e811 100755 --- a/layout/_partial/head.ejs +++ b/layout/_partial/head.ejs @@ -1,5 +1,5 @@ <% -function getTitle() { +function generate_title() { if (page.seo_title || page.title || page.wiki || page.layout) { return (page.seo_title || page.title || page.wiki || page.layout) + ' - ' + config.title; } else if (page.category) { @@ -11,8 +11,18 @@ function getTitle() { } return ''; } -if (page.description == undefined) { - page.description = stellar_meta('description', page); +function generate_robots() { + if (is_home() == true) { + return ''; + } + if (page.robots) { + return ''; + } else { + // default rule + if (['post', 'wiki', 'index'].includes(page.layout) == false) { + return ''; + } + } } function og_args() { var args = {}; @@ -28,7 +38,7 @@ function og_args() { <%- meta_generator() %> - + <%- generate_robots() %> @@ -41,7 +51,7 @@ function og_args() { - <%- getTitle() %> + <%- generate_title() %> <% if (theme.open_graph && theme.open_graph.enable) { %> <%- open_graph(og_args()) %> diff --git a/layout/_partial/main/article/related_posts.ejs b/layout/_partial/main/article/related_posts.ejs index 882e881..b4bd2ad 100644 --- a/layout/_partial/main/article/related_posts.ejs +++ b/layout/_partial/main/article/related_posts.ejs @@ -1,6 +1,5 @@ -<% let post = page; %> diff --git a/layout/_partial/scripts/issues.ejs b/layout/_partial/scripts/issues.ejs index 24fef92..567cc1b 100644 --- a/layout/_partial/scripts/issues.ejs +++ b/layout/_partial/scripts/issues.ejs @@ -2,7 +2,7 @@ function loadIssuesJS() { const issues = document.getElementById('issues-api'); if (issues != undefined) { - loadScript('<%- url_for("/js/issues.js") %>'); + loadScript('<%- url_for(theme.plugins.issuesjs || "/js/issues.js") %>'); } }; $(function () { diff --git a/scripts/helpers/stellar_meta.js b/scripts/helpers/stellar_meta.js deleted file mode 100644 index 5a76a70..0000000 --- a/scripts/helpers/stellar_meta.js +++ /dev/null @@ -1,44 +0,0 @@ -'use strict'; - -var util = require('hexo-util'); - -hexo.extend.helper.register('stellar_meta', function(args, page){ - if (['robots', 'description'].includes(args) == false) { - return ''; - } - function meta(str) { - if (str && str.length > 0) { - return str; - } else { - return ''; - } - } - if (args == 'robots') { - if (page.__index == true) { - return ''; - } - if (page.robots) { - meta(page.robots); - } else { - // default rule - if (['post', 'wiki', 'index'].includes(page.layout) == false) { - meta('noindex,nofollow'); - } - } - } else if (args == 'description') { - if (page.__index == true) { - meta(hexo.config.description); - } else if (page.description) { - meta(util.stripHTML(page.description)); - } else if (['post', 'wiki'].includes(page.layout)) { - var description = ''; - if (page.excerpt && page.excerpt.length > 0) { - description = util.stripHTML(page.excerpt); - } else if (page.content && page.content.length > 0) { - description = util.truncate(util.stripHTML(page.content), {length: 160}); - } - meta(description); - } - } - return ''; -});