sass-site/source/helpers/engines.ts

45 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-05-24 22:49:22 +02:00
import slugify from '@sindresorhus/slugify';
2023-03-08 21:59:19 +01:00
import { Liquid } from 'liquidjs';
2023-04-24 18:28:42 +02:00
import markdown from 'markdown-it';
import markdownAnchor from 'markdown-it-anchor';
2023-03-08 21:59:19 +01:00
import markdownItAttrs from 'markdown-it-attrs';
import markdownDefList from 'markdown-it-deflist';
import path from 'path';
2023-04-21 21:01:43 +02:00
import { renderPermalink } from './components/anchors';
2023-03-08 21:59:19 +01:00
/**
* Returns Markdown engine with custom configuration and plugins.
*
* @see https://github.com/markdown-it/markdown-it
* @see https://github.com/markdown-it/markdown-it-deflist
* @see https://github.com/arve0/markdown-it-attrs
2023-05-24 01:48:36 +02:00
* @see https://github.com/valeriangalliat/markdown-it-anchor
2023-03-08 21:59:19 +01:00
*/
export const markdownEngine = markdown({
html: true,
typographer: true,
})
.use(markdownDefList)
2023-04-21 21:01:43 +02:00
.use(markdownItAttrs)
2023-04-24 18:28:42 +02:00
.use(markdownAnchor, {
2023-05-16 22:33:08 +02:00
level: 2,
2023-04-21 21:01:43 +02:00
permalink: renderPermalink,
2023-05-24 22:49:22 +02:00
slugify: (s) => slugify(s),
2023-04-21 21:01:43 +02:00
});
2023-03-08 21:59:19 +01:00
/**
* Returns LiquidJS engine with custom configuration.
*
* @see https://liquidjs.com/
*/
export const liquidEngine = new Liquid({
root: [
path.resolve(__dirname, '../_includes/'),
path.resolve(__dirname, '../'),
],
extname: '.liquid',
strictFilters: true,
jsTruthy: true,
});