-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path.eleventy.mjs
More file actions
171 lines (158 loc) · 5.38 KB
/
.eleventy.mjs
File metadata and controls
171 lines (158 loc) · 5.38 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
/*
* Copyright 2020-2025 G-Labs. All Rights Reserved.
* https://zuixjs.github.io/zuix
*
* Licensed under the MIT license. See LICENSE file.
*
*/
/*
*
* This file is part of
* zUIx, Javascript library for component-based development.
* https://zuixjs.github.io/zuix
*
* @author Generoso Martello - https://github.com/genemars
* @version 1.1
*
*/
import path from 'path';
import compress from 'compression';
import { readFileSync } from 'node:fs';
// 11ty
import { EleventyRenderPlugin } from "@11ty/eleventy";
// zuix.js
import zuix11ty from './.eleventy-zuix.js';
const zuixConfig = zuix11ty.getZuixConfig();
// LESS CSS compiler
import less from 'less';
const lessConfig = JSON.parse(readFileSync(new URL('./.lessrc.json', import.meta.url), 'utf8'));
// Linter (ESLint)
import { Linter as ESLintLinter } from 'eslint';
const linter = new ESLintLinter();
const lintConfig = JSON.parse(readFileSync(new URL('./.eslintrc.json', import.meta.url), 'utf8'));
export default function(eleventyConfig) {
// eleventyConfig.setEventEmitterMode('sequential');
eleventyConfig.setWatchJavaScriptDependencies(false);
eleventyConfig.addPlugin(EleventyRenderPlugin);
// Add ignores
[...zuixConfig.ignoreFiles, ...zuixConfig.componentsFolders].forEach((f) => {
f = path.join(zuixConfig.sourceFolder, f);
eleventyConfig.ignores.add(f);
});
// Ignore `zuix-editor` if mode is 'production'
if (process.env.NODE_ENV === 'production') {
eleventyConfig.ignores.add(path.join(zuixConfig.sourceFolder, 'editor/*'));
}
// Ignore "copy" files, because they are handled by zuix11ty
zuixConfig.copyFiles.forEach((f) => {
f = path.join(zuixConfig.sourceFolder, f);
eleventyConfig.ignores.add(f);
});
// from https://github.com/kkgthb/web-site-11ty-03-netlify-function/blob/main/.eleventy.js
// See if this helps with things that do not refresh
//module.exports = function (eleventyConfig) {
// eleventyConfig.setUseGitIgnore(false);
//};
// Make Liquid capable of rendering "partials"
eleventyConfig.setLiquidOptions({
cache: false,
dynamicPartials: true,
strictFilters: false,
});
// Safe JSON pipe
eleventyConfig.addFilter('jsonScriptSafe', function(value) {
let jsonString;
try {
jsonString = JSON.stringify(value);
} catch (e) {
console.error('Error stringifying value in jsonScriptSafe filter:', e);
}
jsonString = jsonString.replace(/<\/(script)/gi, '<\\/$1');
// Additional safe filters that could be applied:
// jsonString = jsonString.replace(/<!--/g, '<\\!--');
// jsonString = jsonString.replace(/]]>/g, ']]\\>');
return jsonString;
});
// Add custom file types and handlers
eleventyConfig.addTemplateFormats([ 'less', 'css', 'js' ]);
eleventyConfig.addExtension('less', {
read: true,
outputFileExtension: 'css',
compileOptions: {
permalink: () => false
},
compile: async function(inputContent, inputPath) {
try {
const output = await less.render(inputContent, {
...lessConfig,
filename: inputPath,
paths: [path.dirname(inputPath), ...(lessConfig.paths || [])]
});
return output.css;
} catch (error) {
console.error(chalk.red(`LESS compilation error in ${inputPath}:\n`), error);
return `/* LESS compilation error in ${inputPath}: \n${error.message}\nLine: ${error.line}, Column: ${error.column} */`;
}
}
});
// Add linter to report code errors
eleventyConfig.addLinter('eslint', function(content, inputPath, outputPath) {
if( inputPath.endsWith('.js') ) {
// TODO: collect and report at the end of the build (inside 'afterBuild' event handler)
const issues = linter.verify(content, lintConfig, inputPath);
if (issues.length > 0) {
console.log('[11ty] "%s" linter result', inputPath)
}
issues.forEach(function(m) {
if (m.fatal || m.severity > 1) {
console.error(' Error: %s (%s:%s)', m.message, m.line, m.column);
} else {
console.warn(' Warning: %s (%s:%s)', m.message, m.line, m.column);
}
});
}
});
// Add any BrowserSync config option here
eleventyConfig.setServerOptions({
module: "@11ty/eleventy-server-browsersync",
//reloadDelay: 2000,
files: [ ...zuixConfig.componentsFolders ],
notify: false,
cors: true,
middleware: [compress(), function(req, res, next) {
res.setHeader('Set-Cookie', 'SameSite=Lax; Secure');
next();
}],
callbacks: {
ready: function(err, browserSync) {
// setup zuix-11ty watcher
zuix11ty.startWatcher(eleventyConfig, browserSync.publicInstance);
}
},
/*
snippet: false,
snippetOptions: {
rule: {
match: /<head[^>]*>/i,
fn: function(snippet, match) {
return match + snippet;
}
}
}*/
});
zuix11ty.configure(eleventyConfig);
// Return 11ty configuration options:
return {
pathPrefix: zuixConfig.baseUrl,
dir: {
input: zuixConfig.sourceFolder,
output: zuixConfig.buildFolder,
data: zuixConfig.dataFolder,
includes: zuixConfig.includesFolder,
layouts: path.join(zuixConfig.includesFolder, "layouts")
},
//htmlTemplateEngine: false, // 'liquid'
markdownTemplateEngine: 'liquid',
templateFormats: ['html', 'liquid', 'ejs', 'md', 'hbs', 'mustache', 'haml', 'pug', 'njk', '11ty.js']
}
};