remark42_hotfix_7_3_2

Форк
0
117 строк · 3.1 Кб
1
const { format } = require('date-fns')
2
const htmlmin = require('html-minifier')
3
const syntaxHighlightPlugin = require('@11ty/eleventy-plugin-syntaxhighlight')
4

5
function noteContainer() {
6
	const { utils } = require('markdown-it')()
7
	const elementRegexp = /^note\s+(.*)$/
8

9
	return {
10
		validate(params) {
11
			return params.trim().match(elementRegexp)
12
		},
13

14
		render(tokens, idx) {
15
			const { info, nesting } = tokens[idx]
16
			const matches = info.trim().match(elementRegexp)
17

18
			if (nesting === 1) {
19
				const icon = utils.escapeHtml(matches[1])
20

21
				return `<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

24
			return `</aside>`
25
		},
26
	}
27
}
28

29
function markdownTableWrapper(md) {
30
	md.renderer.rules.table_open = function (tokens, idx, options, _, self) {
31
		return (
32
			`<div class="overflow-x-auto">` + self.renderToken(tokens, idx, options)
33
		)
34
	}
35
	md.renderer.rules.table_close = function (tokens, idx, options, _, self) {
36
		return self.renderToken(tokens, idx, options) + `</div>`
37
	}
38
}
39

40
function getMarkdownLib() {
41
	const markdownIt = require('markdown-it')
42
	const markdownItAnchor = require('markdown-it-anchor')
43
	const markdownItContainer = require('markdown-it-container')
44

45
	return markdownIt({
46
		html: true,
47
		breaks: true,
48
		linkify: true,
49
	})
50
		.use(markdownItAnchor, {
51
			permalink: markdownItAnchor.permalink.linkInsideHeader({
52
				placement: 'before',
53
				class: 'header-anchor',
54
				symbol: '',
55
			}),
56
		})
57
		.use(markdownItContainer, 'note', noteContainer())
58
		.use(markdownTableWrapper)
59
}
60

61
module.exports = function (eleventyConfig) {
62
	// TODO: create version with commit sha and current version of Remark42
63
	eleventyConfig.addShortcode('version', () => `${Date.now()}`)
64
	eleventyConfig.addShortcode('year', () => `${new Date().getFullYear()}`)
65
	eleventyConfig.setUseGitIgnore(false)
66
	eleventyConfig.addWatchTarget('./.tmp/style.css')
67
	eleventyConfig.addPassthroughCopy({ './.tmp/style.css': './style.css' })
68
	eleventyConfig.addPassthroughCopy({ './public': './' })
69
	eleventyConfig.addPassthroughCopy('./src/**/*.{gif,jpg,png,svg}')
70

71
	eleventyConfig.addCollection('pages', (collection) =>
72
		collection.getFilteredByGlob('pages/*.md')
73
	)
74

75
	eleventyConfig.addFilter('humanizeDate', (date) =>
76
		format(new Date(date), 'LLL dd, yyyy')
77
	)
78

79
	eleventyConfig.addFilter('robotizeDate', (date) =>
80
		format(new Date(date), 'yyyy-MM-dd')
81
	)
82

83
	eleventyConfig.addFilter(
84
		'debug',
85
		(content = {}) => `<pre>${JSON.stringify(content, null, 2)}</pre>`
86
	)
87

88
	// Minify HTML output
89
	eleventyConfig.addTransform('htmlmin', function (content, outputPath) {
90
		if (!outputPath.endsWith('.html')) {
91
			return content
92
		}
93

94
		return htmlmin.minify(content, {
95
			removeComments: true,
96
			collapseWhitespace: true,
97
		})
98
	})
99

100
	eleventyConfig.setLibrary('md', getMarkdownLib())
101
	eleventyConfig.addPlugin(syntaxHighlightPlugin)
102

103
	eleventyConfig.addCollection('docs', (collection) =>
104
		collection.getFilteredByGlob('src/docs/**/*.md')
105
	)
106

107
	return {
108
		markdownTemplateEngine: false,
109
		dir: {
110
			input: 'src',
111
			output: 'build',
112
			data: 'data',
113
			layouts: 'layouts',
114
			includes: 'includes',
115
		},
116
	}
117
}
118

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.