-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
185 lines (165 loc) · 5.54 KB
/
Copy pathindex.js
File metadata and controls
185 lines (165 loc) · 5.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
Copyright the eleventy-plugin-fluid copyright holders.
See the AUTHORS.md file at the top-level directory of this distribution and at
https://github.com/fluid-project/eleventy-plugin-fluid/raw/main/AUTHORS.md.
Licensed under the New BSD license. You may not use this file except in compliance with this License.
You may obtain a copy of the New BSD License at
https://github.com/fluid-project/eleventy-plugin-fluid/raw/main/LICENSE.md.
*/
import path from 'node:path';
import fg from 'fast-glob';
import { EleventyRenderPlugin, EleventyI18nPlugin } from '@11ty/eleventy';
import rtlDetect from 'rtl-detect';
import { Merge as mergeUtility } from '@11ty/eleventy-utils';
import figureShortcode from './src/shortcodes/figure-shortcode.js';
import findFilter from './src/filters/find-filter.js';
import findAllFilter from './src/filters/find-all-filter.js';
import findTranslationFilter from './src/filters/find-translation-filter.js';
import formatDateFilter from './src/filters/format-date-filter.js';
import htmlMinifyTransform from './src/transforms/html-minify-transform.js';
import isoDateFilter from './src/filters/iso-date-filter.js';
import limitFilter from './src/filters/limit-filter.js';
import splitFilter from './src/filters/split-filter.js';
import uioShortcodes from './src/shortcodes/uio.js';
import uioAssets from './src/config/uio-assets.json' with { type: 'json' };
import languages from './src/config/languages.json' with { type: 'json' };
import compileCss from './src/compilers/compile-css.js';
import compileJs from './src/compilers/compile-js.js';
import { __ } from './src/utils/translation.js';
const fluidPlugin = {
initArguments: {},
configFunction(eleventyConfig, options = {}) {
options = mergeUtility({
uio: true,
markdown: {
options: {
html: true,
linkify: true,
typographer: true,
},
plugins: [],
},
css: {
basePath: `./${eleventyConfig.dir.input || 'src'}/assets/styles`,
enabled: true,
minify: true,
sourceMap: false,
drafts: {
nesting: true,
},
browserslist: '> 1%',
},
js: {
basePath: `./${eleventyConfig.dir.input || 'src'}/assets/scripts`,
enabled: true,
minify: true,
target: 'es2022',
outdir: `./${eleventyConfig.dir.output || '_site'}/assets/scripts`,
},
minify: {
enabled: true,
},
supportedLanguages: languages,
defaultLanguage: 'en',
i18n: true,
}, options);
/**
Plugins
*/
eleventyConfig.addPlugin(EleventyI18nPlugin, {
defaultLanguage: options.defaultLanguage,
});
eleventyConfig.addPlugin(EleventyRenderPlugin);
/**
Global Data
*/
eleventyConfig.addGlobalData('defaultLanguage', options.defaultLanguage);
eleventyConfig.addGlobalData('defaultLanguageDirection', rtlDetect.getLangDir(options.defaultLanguage));
eleventyConfig.addGlobalData('supportedLanguages', options.supportedLanguages);
/**
Filters
*/
eleventyConfig.addFilter('find', findFilter);
eleventyConfig.addFilter('findAll', findAllFilter);
eleventyConfig.addFilter('findTranslation', findTranslationFilter);
eleventyConfig.addFilter('formatDate', formatDateFilter);
eleventyConfig.addFilter('isoDate', isoDateFilter);
eleventyConfig.addFilter('limit', limitFilter);
eleventyConfig.addFilter('split', splitFilter);
eleventyConfig.addFilter('languageDirection', rtlDetect.getLangDir);
if (options.i18n) {
eleventyConfig.addShortcode('__', __);
}
eleventyConfig.addPairedShortcode('figure', figureShortcode);
if (options.uio) {
for (const [shortcodeName, value] of Object.entries(uioShortcodes)) {
eleventyConfig.addShortcode(shortcodeName, value);
}
for (const asset of uioAssets) {
const key = `node_modules/infusion/${asset}`;
const fileMapping = {
[key]: `lib/infusion/${asset.replace('dist/', '')}`,
};
eleventyConfig.addPassthroughCopy(fileMapping);
}
}
/**
Template Formats
*/
eleventyConfig.amendLibrary('md', (md) => {
md.set(options.markdown.options);
for (const plugin of options.markdown.plugins) {
if (Array.isArray(plugin)) {
const [pluginModule, pluginOptions = {}] = plugin;
md.use(pluginModule, pluginOptions);
} else {
md.use(plugin);
}
}
});
if (options.css.enabled) {
eleventyConfig.addTemplateFormats('css');
eleventyConfig.addExtension('css', {
outputFileExtension: 'css',
async getData() {
return {
eleventyExcludeFromCollections: true,
};
},
async compile(inputContent, inputPath) {
return compileCss(inputContent, inputPath, options.css);
},
});
}
if (options.js.enabled) {
eleventyConfig.addWatchTarget(options.js.basePath);
eleventyConfig.on('eleventy.before', async () => {
const entryPoints = await fg([`${options.js.basePath}/**/*.js`]);
for (const item of entryPoints) {
if (path.basename(item).startsWith('_')) {
continue;
}
compileJs(item, options.js);
const outputBasename = path.basename(options.js.outdir);
const relativePath = item.split(outputBasename)[1];
const outputDirectory = `./${path.dirname(path.join(options.js.outdir, relativePath))}`;
if (!eleventyConfig.quietMode) {
console.log(`[11ty] Writing ${path.join(outputDirectory, path.basename(item))} from ${item}`);
}
}
});
}
/**
Transforms
*/
if (options.minify.enabled) {
eleventyConfig.addTransform('htmlMinify', htmlMinifyTransform);
}
},
};
export default fluidPlugin;
export {
fluidPlugin,
};
export { default as generatePermalink } from './src/utils/generate-permalink.js';
export { __ } from './src/utils/translation.js';