1
const { format } = require('date-fns')
2
const htmlmin = require('html-minifier')
3
const syntaxHighlightPlugin = require('@11ty/eleventy-plugin-syntaxhighlight')
5
function noteContainer() {
6
const { utils } = require('markdown-it')()
7
const elementRegexp = /^note\s+(.*)$/
11
return params.trim().match(elementRegexp)
15
const { info, nesting } = tokens[idx]
16
const matches = info.trim().match(elementRegexp)
19
const icon = utils.escapeHtml(matches[1])
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>`
29
function markdownTableWrapper(md) {
30
md.renderer.rules.table_open = function (tokens, idx, options, _, self) {
32
`<div class="overflow-x-auto">` + self.renderToken(tokens, idx, options)
35
md.renderer.rules.table_close = function (tokens, idx, options, _, self) {
36
return self.renderToken(tokens, idx, options) + `</div>`
40
function getMarkdownLib() {
41
const markdownIt = require('markdown-it')
42
const markdownItAnchor = require('markdown-it-anchor')
43
const markdownItContainer = require('markdown-it-container')
50
.use(markdownItAnchor, {
51
permalink: markdownItAnchor.permalink.linkInsideHeader({
53
class: 'header-anchor',
57
.use(markdownItContainer, 'note', noteContainer())
58
.use(markdownTableWrapper)
61
module.exports = function (eleventyConfig) {
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}')
71
eleventyConfig.addCollection('pages', (collection) =>
72
collection.getFilteredByGlob('pages/*.md')
75
eleventyConfig.addFilter('humanizeDate', (date) =>
76
format(new Date(date), 'LLL dd, yyyy')
79
eleventyConfig.addFilter('robotizeDate', (date) =>
80
format(new Date(date), 'yyyy-MM-dd')
83
eleventyConfig.addFilter(
85
(content = {}) => `<pre>${JSON.stringify(content, null, 2)}</pre>`
89
eleventyConfig.addTransform('htmlmin', function (content, outputPath) {
90
if (!outputPath.endsWith('.html')) {
94
return htmlmin.minify(content, {
96
collapseWhitespace: true,
100
eleventyConfig.setLibrary('md', getMarkdownLib())
101
eleventyConfig.addPlugin(syntaxHighlightPlugin)
103
eleventyConfig.addCollection('docs', (collection) =>
104
collection.getFilteredByGlob('src/docs/**/*.md')
108
markdownTemplateEngine: false,
114
includes: 'includes',