remark42_hotfix_7_3_2
117 строк · 3.1 Кб
1const { format } = require('date-fns')2const htmlmin = require('html-minifier')3const syntaxHighlightPlugin = require('@11ty/eleventy-plugin-syntaxhighlight')4
5function noteContainer() {6const { utils } = require('markdown-it')()7const elementRegexp = /^note\s+(.*)$/8
9return {10validate(params) {11return params.trim().match(elementRegexp)12},13
14render(tokens, idx) {15const { info, nesting } = tokens[idx]16const matches = info.trim().match(elementRegexp)17
18if (nesting === 1) {19const icon = utils.escapeHtml(matches[1])20
21return `<aside class="relative pr-4 pl-12 py-1 bg-gray-50 dark:bg-gray-800"><span class="absolute left-4 top-6 text-xl">${icon}</span>`22}23
24return `</aside>`25},26}27}
28
29function markdownTableWrapper(md) {30md.renderer.rules.table_open = function (tokens, idx, options, _, self) {31return (32`<div class="overflow-x-auto">` + self.renderToken(tokens, idx, options)33)34}35md.renderer.rules.table_close = function (tokens, idx, options, _, self) {36return self.renderToken(tokens, idx, options) + `</div>`37}38}
39
40function getMarkdownLib() {41const markdownIt = require('markdown-it')42const markdownItAnchor = require('markdown-it-anchor')43const markdownItContainer = require('markdown-it-container')44
45return markdownIt({46html: true,47breaks: true,48linkify: true,49})50.use(markdownItAnchor, {51permalink: markdownItAnchor.permalink.linkInsideHeader({52placement: 'before',53class: 'header-anchor',54symbol: '',55}),56})57.use(markdownItContainer, 'note', noteContainer())58.use(markdownTableWrapper)59}
60
61module.exports = function (eleventyConfig) {62// TODO: create version with commit sha and current version of Remark4263eleventyConfig.addShortcode('version', () => `${Date.now()}`)64eleventyConfig.addShortcode('year', () => `${new Date().getFullYear()}`)65eleventyConfig.setUseGitIgnore(false)66eleventyConfig.addWatchTarget('./.tmp/style.css')67eleventyConfig.addPassthroughCopy({ './.tmp/style.css': './style.css' })68eleventyConfig.addPassthroughCopy({ './public': './' })69eleventyConfig.addPassthroughCopy('./src/**/*.{gif,jpg,png,svg}')70
71eleventyConfig.addCollection('pages', (collection) =>72collection.getFilteredByGlob('pages/*.md')73)74
75eleventyConfig.addFilter('humanizeDate', (date) =>76format(new Date(date), 'LLL dd, yyyy')77)78
79eleventyConfig.addFilter('robotizeDate', (date) =>80format(new Date(date), 'yyyy-MM-dd')81)82
83eleventyConfig.addFilter(84'debug',85(content = {}) => `<pre>${JSON.stringify(content, null, 2)}</pre>`86)87
88// Minify HTML output89eleventyConfig.addTransform('htmlmin', function (content, outputPath) {90if (!outputPath.endsWith('.html')) {91return content92}93
94return htmlmin.minify(content, {95removeComments: true,96collapseWhitespace: true,97})98})99
100eleventyConfig.setLibrary('md', getMarkdownLib())101eleventyConfig.addPlugin(syntaxHighlightPlugin)102
103eleventyConfig.addCollection('docs', (collection) =>104collection.getFilteredByGlob('src/docs/**/*.md')105)106
107return {108markdownTemplateEngine: false,109dir: {110input: 'src',111output: 'build',112data: 'data',113layouts: 'layouts',114includes: 'includes',115},116}117}
118