2025-2-26-fixed
This commit is contained in:
22
themes/fluid/scripts/generators/index-generator.js
Normal file
22
themes/fluid/scripts/generators/index-generator.js
Normal file
@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
const pagination = require('hexo-pagination');
|
||||
|
||||
module.exports = function(locals) {
|
||||
const config = this.config;
|
||||
const posts = locals.index_posts.sort(config.index_generator.order_by);
|
||||
|
||||
posts.data.sort((a, b) => (b.sticky || 0) - (a.sticky || 0));
|
||||
|
||||
const paginationDir = config.pagination_dir || 'page';
|
||||
const path = config.index_generator.path || '';
|
||||
|
||||
return pagination(path, posts, {
|
||||
perPage: config.index_generator.per_page,
|
||||
layout: 'index',
|
||||
format: paginationDir + '/%d/',
|
||||
data: {
|
||||
__index: true
|
||||
}
|
||||
});
|
||||
};
|
||||
68
themes/fluid/scripts/generators/local-search.js
Normal file
68
themes/fluid/scripts/generators/local-search.js
Normal file
@ -0,0 +1,68 @@
|
||||
/* global hexo */
|
||||
|
||||
'use strict';
|
||||
|
||||
hexo.extend.generator.register('_hexo_generator_search', function(locals) {
|
||||
const config = this.theme.config;
|
||||
if (!config.search.enable) {
|
||||
return;
|
||||
}
|
||||
|
||||
const nunjucks = require('nunjucks');
|
||||
const env = new nunjucks.Environment();
|
||||
const pathFn = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
env.addFilter('uriencode', function(str) {
|
||||
return encodeURI(str);
|
||||
});
|
||||
|
||||
env.addFilter('noControlChars', function(str) {
|
||||
// eslint-disable-next-line no-control-regex
|
||||
return str && str.replace(/[\x00-\x1F\x7F]/g, '');
|
||||
});
|
||||
|
||||
env.addFilter('urlJoin', function(str) {
|
||||
const base = str[0];
|
||||
const relative = str[1];
|
||||
return relative
|
||||
? base.replace(/\/+$/, '') + '/' + relative.replace(/^\/+/, '')
|
||||
: base;
|
||||
});
|
||||
|
||||
const searchTmplSrc = pathFn.join(hexo.theme_dir, './source/xml/local-search.xml');
|
||||
const searchTmpl = nunjucks.compile(fs.readFileSync(searchTmplSrc, 'utf8'), env);
|
||||
|
||||
const searchConfig = config.search;
|
||||
let searchField = searchConfig.field;
|
||||
const content = searchConfig.content && true;
|
||||
|
||||
let posts, pages;
|
||||
|
||||
if (searchField.trim() !== '') {
|
||||
searchField = searchField.trim();
|
||||
if (searchField === 'post') {
|
||||
posts = locals.posts.sort('-date');
|
||||
} else if (searchField === 'page') {
|
||||
pages = locals.pages;
|
||||
} else {
|
||||
posts = locals.posts.sort('-date');
|
||||
pages = locals.pages;
|
||||
}
|
||||
} else {
|
||||
posts = locals.posts.sort('-date');
|
||||
}
|
||||
|
||||
const xml = searchTmpl.render({
|
||||
config : config,
|
||||
posts : posts,
|
||||
pages : pages,
|
||||
content: content,
|
||||
url : hexo.config.root
|
||||
});
|
||||
|
||||
return {
|
||||
path: searchConfig.generate_path || '/local-search.xml',
|
||||
data: xml
|
||||
};
|
||||
});
|
||||
55
themes/fluid/scripts/generators/pages.js
Normal file
55
themes/fluid/scripts/generators/pages.js
Normal file
@ -0,0 +1,55 @@
|
||||
/* global hexo */
|
||||
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// generate 404 page
|
||||
if (!fs.existsSync(path.join(hexo.source_dir, '404.html'))) {
|
||||
hexo.extend.generator.register('_404', function(locals) {
|
||||
if (this.theme.config.page404.enable !== false) {
|
||||
return {
|
||||
path : '404.html',
|
||||
data : locals.theme,
|
||||
layout: '404'
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// generate tags Page
|
||||
hexo.extend.generator.register('_tags', function(locals) {
|
||||
if (this.theme.config.tag.enable !== false) {
|
||||
return {
|
||||
path : 'tags/index.html',
|
||||
data : locals.theme,
|
||||
layout: 'tags'
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
// generate categories Page
|
||||
hexo.extend.generator.register('_categories', function(locals) {
|
||||
if (this.theme.config.category.enable !== false) {
|
||||
return {
|
||||
path : 'categories/index.html',
|
||||
data : locals.theme,
|
||||
layout: 'categories'
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
// generate links page
|
||||
hexo.extend.generator.register('_links', function(locals) {
|
||||
if (this.theme.config.links.enable !== false) {
|
||||
return {
|
||||
path : 'links/index.html',
|
||||
data : locals.theme,
|
||||
layout: 'links'
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
// generate index page
|
||||
hexo.extend.generator.register('index', require('./index-generator'));
|
||||
Reference in New Issue
Block a user