代码拉取完成,页面将自动刷新
const pluginRss = require('@11ty/eleventy-plugin-rss');
const pluginSyntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight');
const pluginNavigation = require('@11ty/eleventy-navigation');
const markdownIt = require('markdown-it');
const minify = require('html-minifier').minify;
module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPlugin(pluginSyntaxHighlight);
eleventyConfig.addPlugin(pluginNavigation);
eleventyConfig.addPassthroughCopy('assets');
eleventyConfig.addPassthroughCopy('css');
eleventyConfig.addPassthroughCopy('js');
eleventyConfig.addWatchTarget('./css/');
eleventyConfig.addWatchTarget('./js/');
let markdownLibrary = markdownIt({
html: true,
breaks: true,
linkify: true,
});
eleventyConfig.setLibrary('md', markdownLibrary);
eleventyConfig.addCollection('posts', (collection) => {
const posts = collection.getFilteredByTag('posts');
for(let i = 0; i < posts.length; i++) {
posts[i].data['index'] = i;
posts[i].data['prevPost'] = i === 0 ? null : posts[i - 1];
posts[i].data['nextPost'] = i === posts.length - 1 ? null : posts[i + 1];
}
return posts;
});
eleventyConfig.addCollection('postsByCategory', (collection) => {
const posts = collection.getFilteredByTag('posts').sort((a, b) => a.data.title.localeCompare(b.data.title));
const groups = posts.reduce((acc, item) => ((acc[item.data.category] = [...(acc[item.data.category] || []), item]), acc), {});
return Object.keys(groups).sort().reduce((p, c) => (p[c] = groups[c], p), {});
});
eleventyConfig.addFilter('countKeys', (arr) => {
return Object.keys(arr).length;
});
eleventyConfig.addFilter('randomItems', (arr, count) => {
return arr.concat().reduce((p, _, __, arr) => (p[0] < count) ? [p[0] + 1, p[1].concat(arr.splice(Math.random() * arr.length | 0, 1))] : p, [0, []])[1];
});
eleventyConfig.addFilter('sortBy', (arr, key) => {
return arr.sort((a, b) => (a[key] > b[key]) ? 1 : ((a[key] < b[key]) ? -1 : 0));
});
eleventyConfig.addFilter('chunk', (arr, size) => {
return arr.reduce((acc, e, i) => (i % size ? acc[acc.length - 1].push(e) : acc.push([e]), acc), []);
});
// Minify HTML
const minifyHtml = (rawContent, outputPath) => (
(outputPath && outputPath.endsWith('.html'))
? minify(rawContent, {
removeAttributeQuotes: true,
collapseBooleanAttributes: true,
collapseWhitespace: true,
removeComments: true,
sortClassName: true,
sortAttributes: true,
html5: true,
decodeEntities: true,
removeOptionalTags: true,
})
: rawContent
);
eleventyConfig.addTransform("minifyHtml", minifyHtml);
return {
templateFormats: ['md', 'njk', 'html', 'liquid'],
markdownTemplateEngine: 'liquid',
htmlTemplateEngine: 'njk',
dataTemplateEngine: 'njk',
dir: {
input: '.',
includes: '_includes',
data: '_data',
output: '_site',
},
};
};
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。