2025-2-26-fixed

This commit is contained in:
2025-02-26 09:16:07 +08:00
parent bf50b6c865
commit 4968d276dc
456 changed files with 27801 additions and 1 deletions

View File

@@ -0,0 +1,84 @@
/* global hexo */
'use strict';
const crypto = require('crypto');
hexo.extend.helper.register('next_inject', function(point) {
return hexo.theme.config.injects[point]
.map(item => this.partial(item.layout, item.locals, item.options))
.join('');
});
hexo.extend.helper.register('next_js', function(...urls) {
const { js } = hexo.theme.config;
return urls.map(url => this.js(`${js}/${url}`)).join('');
});
hexo.extend.helper.register('next_vendors', function(url) {
if (url.startsWith('//')) return url;
const internal = hexo.theme.config.vendors._internal;
return this.url_for(`${internal}/${url}`);
});
hexo.extend.helper.register('post_edit', function(src) {
const theme = hexo.theme.config;
if (!theme.post_edit.enable) return '';
return this.next_url(theme.post_edit.url + src, '<i class="fa fa-pencil-alt"></i>', {
class: 'post-edit-link',
title: this.__('post.edit')
});
});
hexo.extend.helper.register('post_nav', function(post) {
const theme = hexo.theme.config;
if (theme.post_navigation === false || (!post.prev && !post.next)) return '';
const prev = theme.post_navigation === 'right' ? post.prev : post.next;
const next = theme.post_navigation === 'right' ? post.next : post.prev;
const left = prev ? `
<a href="${this.url_for(prev.path)}" rel="prev" title="${prev.title}">
<i class="fa fa-chevron-left"></i> ${prev.title}
</a>` : '';
const right = next ? `
<a href="${this.url_for(next.path)}" rel="next" title="${next.title}">
${next.title} <i class="fa fa-chevron-right"></i>
</a>` : '';
return `
<div class="post-nav">
<div class="post-nav-item">${left}</div>
<div class="post-nav-item">${right}</div>
</div>`;
});
hexo.extend.helper.register('gitalk_md5', function(path) {
let str = this.url_for(path);
str.replace('index.html', '');
return crypto.createHash('md5').update(str).digest('hex');
});
hexo.extend.helper.register('canonical', function() {
// https://support.google.com/webmasters/answer/139066
const { permalink } = hexo.config;
let url = this.url.replace(/index\.html$/, '');
if (!permalink.endsWith('.html')) {
url = url.replace(/\.html$/, '');
}
return `<link rel="canonical" href="${url}">`;
});
/**
* Get page path given a certain language tag
*/
hexo.extend.helper.register('i18n_path', function(language) {
const { path, lang } = this.page;
const base = path.startsWith(lang) ? path.slice(lang.length + 1) : path;
return this.url_for(`${this.languages.indexOf(language) === 0 ? '' : '/' + language}/${base}`);
});
/**
* Get the language name
*/
hexo.extend.helper.register('language_name', function(language) {
const name = hexo.theme.i18n.__(language)('name');
return name === 'name' ? language : name;
});

View File

@@ -0,0 +1,29 @@
/* global hexo */
'use strict';
hexo.extend.helper.register('next_font', () => {
const config = hexo.theme.config.font;
if (!config || !config.enable) return '';
const fontDisplay = '&display=swap';
const fontSubset = '&subset=latin,latin-ext';
const fontStyles = ':300,300italic,400,400italic,700,700italic';
const fontHost = config.host || '//fonts.googleapis.com';
//Get a font list from config
let fontFamilies = ['global', 'title', 'headings', 'posts', 'codes'].map(item => {
if (config[item] && config[item].family && config[item].external) {
return config[item].family + fontStyles;
}
return '';
});
fontFamilies = fontFamilies.filter(item => item !== '');
fontFamilies = [...new Set(fontFamilies)];
fontFamilies = fontFamilies.join('|');
// Merge extra parameters to the final processed font string
return fontFamilies ? `<link rel="stylesheet" href="${fontHost}/css?family=${fontFamilies.concat(fontDisplay, fontSubset)}">` : '';
});

View File

@@ -0,0 +1,45 @@
/* global hexo */
'use strict';
const url = require('url');
/**
* Export theme config to js
*/
hexo.extend.helper.register('next_config', function() {
let { config, theme, next_version } = this;
config.algolia = config.algolia || {};
let exportConfig = {
hostname : url.parse(config.url).hostname || config.url,
root : config.root,
scheme : theme.scheme,
version : next_version,
exturl : theme.exturl,
sidebar : theme.sidebar,
copycode : theme.codeblock.copy_button,
back2top : theme.back2top,
bookmark : theme.bookmark,
fancybox : theme.fancybox,
mediumzoom: theme.mediumzoom,
lazyload : theme.lazyload,
pangu : theme.pangu,
comments : theme.comments,
algolia : {
appID : config.algolia.applicationID,
apiKey : config.algolia.apiKey,
indexName: config.algolia.indexName,
hits : theme.algolia_search.hits,
labels : theme.algolia_search.labels
},
localsearch: theme.local_search,
motion : theme.motion
};
if (config.search) {
exportConfig.path = config.search.path;
}
return `<script id="hexo-configurations">
var NexT = window.NexT || {};
var CONFIG = ${JSON.stringify(exportConfig)};
</script>`;
});

View File

@@ -0,0 +1,61 @@
/* global hexo */
'use strict';
const { htmlTag } = require('hexo-util');
const url = require('url');
hexo.extend.helper.register('next_url', function(path, text, options = {}) {
const { config } = this;
const data = url.parse(path);
const siteHost = url.parse(config.url).hostname || config.url;
const theme = hexo.theme.config;
let exturl = '';
let tag = 'a';
let attrs = { href: this.url_for(path) };
// If `exturl` enabled, set spanned links only on external links.
if (theme.exturl && data.protocol && data.hostname !== siteHost) {
tag = 'span';
exturl = 'exturl';
const encoded = Buffer.from(path).toString('base64');
attrs = {
class : exturl,
'data-url': encoded
};
}
for (let key in options) {
/**
* If option have `class` attribute, add it to
* 'exturl' class if `exturl` option enabled.
*/
if (exturl !== '' && key === 'class') {
attrs[key] += ' ' + options[key];
} else {
attrs[key] = options[key];
}
}
if (attrs.class && Array.isArray(attrs.class)) {
attrs.class = attrs.class.join(' ');
}
// If it's external link, rewrite attributes.
if (data.protocol && data.hostname !== siteHost) {
attrs.external = null;
if (!theme.exturl) {
// Only for simple link need to rewrite/add attributes.
attrs.rel = 'noopener';
attrs.target = '_blank';
} else {
// Remove rel attributes for `exturl` in main menu.
attrs.rel = null;
}
}
return htmlTag(tag, attrs, decodeURI(text), false);
});