This commit is contained in:
xaoxuu 2021-02-21 04:01:17 +08:00
parent 2468337f69
commit b0f60fb917
5 changed files with 19 additions and 53 deletions

View File

@ -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

View File

@ -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 '<meta name="robots" content="' + page.robots + '">';
} else {
// default rule
if (['post', 'wiki', 'index'].includes(page.layout) == false) {
return '<meta name="robots" content="noindex,nofollow">';
}
}
}
function og_args() {
var args = {};
@ -28,7 +38,7 @@ function og_args() {
<head hexo-theme='<%- stellar_info("tree") %>'>
<%- meta_generator() %>
<meta charset="utf-8">
<meta name='robots' content='<%- stellar_meta("robots", page) %>'>
<%- generate_robots() %>
<meta http-equiv='x-dns-prefetch-control' content='on' />
<link rel='dns-prefetch' href='https://cdn.jsdelivr.net'>
@ -41,7 +51,7 @@ function og_args() {
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title><%- getTitle() %></title>
<title><%- generate_title() %></title>
<% if (theme.open_graph && theme.open_graph.enable) { %>
<%- open_graph(og_args()) %>

View File

@ -1,6 +1,5 @@
<% let post = page; %>
<div class='related-posts-wrap'><%-
popular_posts_wrapper({
title: __('meta.related_posts'),
json: popular_posts_json({ maxCount: 5 , ulClass: 'related-posts' , PPMixingRate: 0.2 , isImage: true , isExcerpt: true} , post )
json: popular_posts_json({ maxCount: 5 , ulClass: 'related-posts' , PPMixingRate: 0.2 , isImage: true , isExcerpt: true} , page )
}) %></div>

View File

@ -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 () {

View File

@ -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 '';
});