@apleasantview/eleventy-plugin-baseline 0.1.0-next.32 → 0.1.0-next.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/README.md +48 -23
  2. package/core/content-map-store.js +51 -0
  3. package/core/filters/index.js +4 -0
  4. package/core/filters/isString.js +6 -1
  5. package/core/filters/markdown.js +6 -0
  6. package/core/filters/related-posts.js +7 -1
  7. package/core/global-functions/index.js +6 -0
  8. package/core/logging.js +25 -25
  9. package/core/page-context.js +310 -0
  10. package/core/registry.js +110 -0
  11. package/core/schema.js +37 -0
  12. package/core/shortcodes/image.js +167 -144
  13. package/core/shortcodes/index.js +2 -0
  14. package/core/slug-index.js +61 -0
  15. package/core/translation-map-store.js +46 -0
  16. package/core/types.js +73 -0
  17. package/core/utils/helpers.js +75 -0
  18. package/core/utils/pick.js +7 -0
  19. package/core/virtual-dir.js +111 -0
  20. package/core/wikilinks.js +152 -0
  21. package/index.js +364 -0
  22. package/modules/assets/index.js +162 -0
  23. package/modules/assets/processors/esbuild-process.js +35 -0
  24. package/modules/assets/processors/postcss-process.js +52 -0
  25. package/modules/assets/schema.js +14 -0
  26. package/modules/head/drivers/capo-adapter.js +72 -0
  27. package/modules/head/drivers/posthtml-head-elements.js +140 -0
  28. package/modules/head/index.js +106 -0
  29. package/modules/head/schema.js +42 -0
  30. package/modules/head/utils/alternates.js +11 -0
  31. package/modules/head/utils/dedupe.js +47 -0
  32. package/modules/multilang/index.js +149 -0
  33. package/modules/navigator/index.js +140 -0
  34. package/modules/navigator/schema.js +13 -0
  35. package/modules/{navigator-core → navigator}/templates/navigator-core.html +14 -8
  36. package/modules/navigator/utils/debug.js +41 -0
  37. package/modules/sitemap/index.js +121 -0
  38. package/modules/sitemap/templates/sitemap-core.html +34 -0
  39. package/modules/{sitemap-core → sitemap}/templates/sitemap-index.html +2 -2
  40. package/modules.js +6 -0
  41. package/package.json +15 -6
  42. package/core/debug.js +0 -20
  43. package/core/filters.js +0 -9
  44. package/core/globals.js +0 -6
  45. package/core/helpers.js +0 -127
  46. package/core/modules.js +0 -22
  47. package/core/shortcodes.js +0 -3
  48. package/eleventy.config.js +0 -157
  49. package/modules/assets-core/plugins/assets-core.js +0 -84
  50. package/modules/assets-esbuild/filters/inline-esbuild.js +0 -24
  51. package/modules/assets-esbuild/plugins/assets-esbuild.js +0 -71
  52. package/modules/assets-postcss/filters/inline-postcss.js +0 -38
  53. package/modules/assets-postcss/plugins/assets-postcss.js +0 -75
  54. package/modules/head-core/drivers/posthtml-head-elements.js +0 -132
  55. package/modules/head-core/plugins/head-core.js +0 -57
  56. package/modules/head-core/utils/head-utils.js +0 -183
  57. package/modules/multilang-core/plugins/multilang-core.js +0 -101
  58. package/modules/navigator-core/plugins/navigator-core.js +0 -39
  59. package/modules/sitemap-core/plugins/sitemap-core.js +0 -65
  60. package/modules/sitemap-core/templates/sitemap-core.html +0 -25
  61. /package/core/{globals → global-functions}/date.js +0 -0
  62. /package/modules/{assets-postcss/fallback → assets/configs}/postcss.config.js +0 -0
  63. /package/modules/{multilang-core → multilang}/filters/i18n-default-translation.js +0 -0
  64. /package/modules/{multilang-core → multilang}/filters/i18n-translation-in.js +0 -0
  65. /package/modules/{multilang-core → multilang}/filters/i18n-translations-for.js +0 -0
package/core/helpers.js DELETED
@@ -1,127 +0,0 @@
1
- import path from 'node:path';
2
- import { TemplatePath } from '@11ty/eleventy-utils';
3
-
4
- /**
5
- * Helper function to add trailing slash to a path
6
- * @param {string} path
7
- * @returns {string}
8
- */
9
- export function addTrailingSlash(path) {
10
- if (path.slice(-1) === '/') {
11
- return path;
12
- }
13
- return path + '/';
14
- }
15
-
16
- /**
17
- * Resolves the assets directory path from config
18
- * Follows Eleventy's pattern: join inputDir + rawDir, then normalize and add trailing slash
19
- * @param {string} inputDir - The input directory (e.g., "./src/")
20
- * @param {string} rawDir - Raw directory value from config (e.g., "assets")
21
- * @returns {{assetsDir: string, assetsDirRelative: string}}
22
- */
23
- export function resolveAssetsDir(inputDir, outputDir, rawDir) {
24
- // Join input/output with assets subdir and normalize
25
- const joinedInput = TemplatePath.join(inputDir, rawDir || '');
26
- const joinedOutput = TemplatePath.join(outputDir, rawDir || '');
27
-
28
- const assetsDir = addTrailingSlash(TemplatePath.standardizeFilePath(joinedInput));
29
- const assetsOutputDir = addTrailingSlash(TemplatePath.standardizeFilePath(joinedOutput));
30
-
31
- return {
32
- assetsDir,
33
- assetsOutputDir
34
- };
35
- }
36
-
37
- /**
38
- * Builds glob patterns for fast-glob (absolute paths)
39
- * @param {string[]} patterns - User-provided patterns
40
- * @param {string} assetsDir - Assets directory (relative, e.g., "./src/assets/")
41
- * @returns {string[]} Absolute glob patterns
42
- */
43
- export function buildGlobPatterns(patterns, assetsDir) {
44
- const assetsDirAbsolute = TemplatePath.absolutePath(TemplatePath.stripLeadingDotSlash(assetsDir));
45
-
46
- return patterns.map((pattern) => {
47
- const normalized = TemplatePath.standardizeFilePath(pattern);
48
- return normalized.startsWith('/') || path.isAbsolute(normalized)
49
- ? normalized
50
- : TemplatePath.join(assetsDirAbsolute, normalized);
51
- });
52
- }
53
-
54
- /**
55
- * Extracts file metadata from a file path
56
- * @param {string} filePath - Normalized file path
57
- * @returns {{basename: string, fileSlug: string, inputFileExtension: string}}
58
- */
59
- export function extractFileMetadata(filePath) {
60
- const ext = path.extname(filePath); // Returns extension with dot (e.g., ".css") or ""
61
- const inputFileExtension = ext && ext.length > 0 ? ext.slice(1) : '';
62
- const basename = TemplatePath.getLastPathSegment(filePath, false);
63
- const fileSlug = ext ? basename.slice(0, -ext.length) : basename;
64
-
65
- return { basename, fileSlug, inputFileExtension };
66
- }
67
-
68
- /**
69
- * Creates a collection item from a relative file path
70
- * @param {string} inputPath - Relative path from project root (e.g., "./src/assets/css/index.css")
71
- * @param {string} inputDir - Input directory (e.g., "./src/")
72
- * @param {string} outputDir - Output directory (e.g., "./dist/")
73
- * @param {string} assetsDirRelative - Assets directory relative to input (e.g., "assets")
74
- * @param {string} passthroughOutput - Output path for passthrough
75
- * @param {boolean} passthrough - Whether passthrough is enabled
76
- * @returns {object} Collection item
77
- */
78
- export function createCollectionItem(
79
- inputPath,
80
- inputDir,
81
- outputDir,
82
- assetsDirRelative,
83
- passthroughOutput,
84
- passthrough
85
- ) {
86
- const { basename, fileSlug, inputFileExtension } = extractFileMetadata(inputPath);
87
-
88
- // Get path relative to input directory
89
- // e.g., inputPath = "./src/assets/css/index.css", inputDir = "./src/"
90
- // relToInput = "assets/css/index.css"
91
- const relToInput = TemplatePath.stripLeadingSubPath(inputPath, TemplatePath.addLeadingDotSlash(inputDir));
92
-
93
- // outputPath: prepend output directory (with leading ./)
94
- // e.g., relToInput = "assets/css/index.css", outputDir = "./dist/"
95
- // outputPath = "./dist/assets/css/index.css"
96
- const outputPath = TemplatePath.addLeadingDotSlash(
97
- TemplatePath.normalize(TemplatePath.join(TemplatePath.addLeadingDotSlash(outputDir), relToInput))
98
- );
99
-
100
- // relToAssets: path relative to assets directory for URL generation
101
- // e.g., inputPath = "./src/assets/css/index.css", assetsDirRelative = "assets"
102
- // relToAssets = "css/index.css"
103
- const assetsDirPath = TemplatePath.addLeadingDotSlash(TemplatePath.join(inputDir, assetsDirRelative));
104
- const relToAssets = TemplatePath.stripLeadingSubPath(inputPath, assetsDirPath);
105
-
106
- const url = passthrough ? TemplatePath.join(passthroughOutput, relToAssets).replace(/\/$/, '') : undefined;
107
-
108
- // filePathStem: path relative to input without extension, with leading slash
109
- // e.g., relToInput = "assets/css/index.css"
110
- // filePathStem = "/assets/css/index"
111
- const filePathStem =
112
- '/' +
113
- (inputFileExtension
114
- ? relToInput.slice(0, -inputFileExtension.length - 1) // Remove extension and dot
115
- : relToInput);
116
-
117
- return {
118
- inputPath,
119
- outputPath,
120
- basename,
121
- fileSlug,
122
- inputFileExtension,
123
- filePathStem,
124
- dir: TemplatePath.getDirFromFilePath(inputPath),
125
- url
126
- };
127
- }
package/core/modules.js DELETED
@@ -1,22 +0,0 @@
1
- // Eleventy plugins
2
- import { EleventyHtmlBasePlugin } from '@11ty/eleventy';
3
-
4
- // Custom plugins
5
- import multilangCore from '../modules/multilang-core/plugins/multilang-core.js';
6
- import navigatorCore from '../modules/navigator-core/plugins/navigator-core.js';
7
- import assetsCore from '../modules/assets-core/plugins/assets-core.js';
8
- import assetsPostCSS from '../modules/assets-postcss/plugins/assets-postcss.js';
9
- import assetsESBuild from '../modules/assets-esbuild/plugins/assets-esbuild.js';
10
- import headCore from '../modules/head-core/plugins/head-core.js';
11
- import sitemapCore from '../modules/sitemap-core/plugins/sitemap-core.js';
12
-
13
- export default {
14
- EleventyHtmlBasePlugin,
15
- multilangCore,
16
- navigatorCore,
17
- assetsCore,
18
- assetsPostCSS,
19
- assetsESBuild,
20
- headCore,
21
- sitemapCore
22
- };
@@ -1,3 +0,0 @@
1
- import { imageShortcode } from './shortcodes/image.js';
2
-
3
- export default { imageShortcode };
@@ -1,157 +0,0 @@
1
- import 'dotenv/config';
2
- import globals from './core/globals.js';
3
- import debug from './core/debug.js';
4
- import filters from './core/filters.js';
5
- import modules from './core/modules.js';
6
- import shortcodes from './core/shortcodes.js';
7
- import { eleventyImageOnRequestDuringServePlugin } from '@11ty/eleventy-img';
8
-
9
- import { createRequire } from 'node:module';
10
- const __require = createRequire(import.meta.url);
11
-
12
- const { name, version } = __require('./package.json');
13
-
14
- /**
15
- * Eleventy Plugin Baseline.
16
- *
17
- * @typedef {Object} BaselineOptions
18
- * @property {boolean} [verbose=false] Enable extra logging from the plugin.
19
- * @property {boolean} [enableNavigatorTemplate=false] Register navigator template/routes.
20
- * @property {boolean} [enableSitemapTemplate=true] Register sitemap template/routes.
21
- * @property {boolean} [multilingual=false] Enable multilang core (requires defaultLanguage + languages).
22
- * @property {string} [defaultLanguage] IETF/BCP47 default language code (used when multilingual=true).
23
- * @property {Record<string, unknown>} [languages={}] Language definition map (shape not enforced; only presence/keys checked).
24
- * @property {Object} [assetsESBuild] Options forwarded to assets-esbuild (minify/target).
25
- *
26
- * @param {BaselineOptions} [options={}] Custom options for the plugin.
27
- * @returns {(eleventyConfig: import("@11ty/eleventy").UserConfig) => Promise<void>}
28
- */
29
- export default function baseline(options = {}) {
30
- /** @param {import("@11ty/eleventy").UserConfig} eleventyConfig */
31
- const plugin = async function (eleventyConfig) {
32
- try {
33
- // Emit a warning message if the application is not using Eleventy 3.0 or newer (including prereleases).
34
- eleventyConfig.versionCheck('>=3.0');
35
- } catch (e) {
36
- console.log(`[eleventy-plugin-baseline] WARN Eleventy plugin compatibility: ${e.message}`);
37
- }
38
-
39
- const hasImageTransformPlugin = eleventyConfig.hasPlugin('eleventyImageTransformPlugin');
40
-
41
- const userOptions = {
42
- version,
43
- name,
44
- verbose: options.verbose ?? false,
45
- hasImageTransformPlugin,
46
- enableNavigatorTemplate: options.enableNavigatorTemplate ?? false,
47
- enableSitemapTemplate: options.enableSitemapTemplate ?? true,
48
- filterAllCollection: options.filterAllCollection ?? true,
49
- assets: {
50
- esbuild: options.assetsESBuild ?? { minify: true, target: 'es2020' }
51
- },
52
- multilingual: options.multilingual ?? false,
53
- ...options
54
- };
55
-
56
- // Core functions.
57
-
58
- // Normalize languages to an object map; if missing or invalid, use null.
59
- const normalizedLanguages = Array.isArray(userOptions.languages)
60
- ? Object.fromEntries(
61
- userOptions.languages
62
- .filter((lang) => typeof lang === 'string' && lang.trim())
63
- .map((lang) => [lang.trim(), {}])
64
- )
65
- : userOptions.languages && typeof userOptions.languages === 'object'
66
- ? userOptions.languages
67
- : null;
68
-
69
- if (userOptions.verbose && Array.isArray(userOptions.languages)) {
70
- const normalizedCount = normalizedLanguages ? Object.keys(normalizedLanguages).length : 0;
71
- if (normalizedCount !== userOptions.languages.length) {
72
- console.warn('[baseline] Some languages entries were invalid and were dropped.');
73
- }
74
- }
75
-
76
- userOptions.languages = normalizedLanguages;
77
- const languages = normalizedLanguages;
78
- const hasLanguages = languages && Object.keys(languages).length > 0;
79
- const isMultilingual = userOptions.multilingual === true && userOptions.defaultLanguage && hasLanguages;
80
-
81
- eleventyConfig.addGlobalData('_baseline', userOptions);
82
- globals(eleventyConfig);
83
- eleventyConfig.addPassthroughCopy({ './src/static': '/' });
84
-
85
- // Prevents double-registering the preprocessor, user config wins.
86
- if (!eleventyConfig.preprocessors.drafts) {
87
- eleventyConfig.addPreprocessor('drafts', '*', (data) => {
88
- if (data.draft && process.env.ELEVENTY_RUN_MODE === 'build') {
89
- return false;
90
- }
91
- });
92
- }
93
-
94
- if (isMultilingual) {
95
- eleventyConfig.addPlugin(modules.multilangCore, {
96
- defaultLanguage: userOptions.defaultLanguage,
97
- languages
98
- });
99
- }
100
-
101
- // Modules.
102
- eleventyConfig.addPlugin(modules.EleventyHtmlBasePlugin, {
103
- baseHref: process.env.URL || eleventyConfig.pathPrefix
104
- });
105
- eleventyConfig.addPlugin(modules.assetsCore);
106
- eleventyConfig.addPlugin(modules.assetsPostCSS);
107
- eleventyConfig.addPlugin(modules.assetsESBuild, userOptions.assets.esbuild);
108
-
109
- if (userOptions.filterAllCollection) {
110
- // Override the default collection behavior. Adding js as template format collects 11tydata.js files.
111
- eleventyConfig.addCollection('all', (collectionApi) =>
112
- collectionApi.getAll().filter((item) => !item.inputPath.endsWith('11tydata.js'))
113
- );
114
- }
115
-
116
- eleventyConfig.addPlugin(modules.headCore);
117
- eleventyConfig.addPlugin(modules.sitemapCore, {
118
- enableSitemapTemplate: userOptions.enableSitemapTemplate,
119
- multilingual: isMultilingual,
120
- languages
121
- });
122
-
123
- // Filters — Module filters might move to their respective module.
124
- eleventyConfig.addFilter('markdownify', filters.markdownFilter);
125
- eleventyConfig.addFilter('relatedPosts', filters.relatedPostsFilter);
126
- eleventyConfig.addFilter('isString', filters.isStringFilter);
127
-
128
- // Shortcodes.
129
- eleventyConfig.addShortcode('image', shortcodes.imageShortcode);
130
-
131
- // Add the dev server middleware for images.
132
- eleventyConfig.addPlugin(eleventyImageOnRequestDuringServePlugin);
133
-
134
- // Debug filters and navigators.
135
- eleventyConfig.addFilter('_inspect', debug.inspect);
136
- eleventyConfig.addFilter('_json', debug.json);
137
- eleventyConfig.addFilter('_keys', debug.keys);
138
- eleventyConfig.addPlugin(modules.navigatorCore, { enableNavigatorTemplate: userOptions.enableNavigatorTemplate });
139
- };
140
-
141
- // Set plugin name so `eleventyConfig.hasPlugin()` can detect it.
142
- Object.defineProperty(plugin, 'name', { value: `${name}` });
143
- return plugin;
144
- }
145
-
146
- export const config = {
147
- dir: {
148
- input: 'src',
149
- output: 'dist',
150
- data: '_data',
151
- includes: '_includes',
152
- assets: 'assets'
153
- },
154
- htmlTemplateEngine: 'njk',
155
- markdownTemplateEngine: 'njk',
156
- templateFormats: ['html', 'njk', 'md']
157
- };
@@ -1,84 +0,0 @@
1
- import { TemplatePath } from '@11ty/eleventy-utils';
2
- import { addTrailingSlash, resolveAssetsDir } from '../../../core/helpers.js';
3
- import { warnIfVerbose, getVerbose } from '../../../core/logging.js';
4
-
5
- const syncCacheFromDirectories = (cache, dirs, rawDir) => {
6
- const inputDir = TemplatePath.addLeadingDotSlash(dirs.input || './');
7
- const outputDir = TemplatePath.addLeadingDotSlash(dirs.output || './');
8
- const { assetsDir, assetsOutputDir } = resolveAssetsDir(inputDir, outputDir, rawDir);
9
-
10
- cache.input = addTrailingSlash(inputDir);
11
- cache.output = addTrailingSlash(outputDir);
12
- cache.assetsInput = assetsDir;
13
- cache.assetsOutput = assetsOutputDir;
14
- };
15
-
16
- const ensureCache = (cache, eleventyConfig, rawDir, verbose) => {
17
- if (cache.assetsInput) return;
18
- syncCacheFromDirectories(cache, eleventyConfig.dir || {}, rawDir);
19
- warnIfVerbose(verbose, 'Fallback directory resolution');
20
- };
21
-
22
- /**
23
- * eleventy-plugin-assets-core
24
- *
25
- * Resolve assets input/output directories, register a virtual
26
- * `directories.assets`, expose the resolved paths via global data, and add
27
- * a watch target under the resolved assets input directory.
28
- *
29
- * Options:
30
- * - verbose (boolean, default global baseline verbose): enable verbose logs.
31
- */
32
- /** @param {import("@11ty/eleventy").UserConfig} eleventyConfig */
33
- export default function assetsCore(eleventyConfig, options = {}) {
34
- const verbose = getVerbose(eleventyConfig) || options.verbose || false;
35
- const userKey = 'assets';
36
-
37
- // Extract raw directory value from config (can be done early)
38
- const rawDir = eleventyConfig.dir?.[userKey] || userKey;
39
-
40
- // Cache object (raw values; normalized later by syncCacheFromDirectories)
41
- const cache = {
42
- input: eleventyConfig.dir?.input || null,
43
- output: eleventyConfig.dir?.output || null,
44
- assetsInput: eleventyConfig.dir?.assets ?? userKey ?? null,
45
- assetsOutput: null
46
- };
47
-
48
- syncCacheFromDirectories(cache, eleventyConfig.dir || {}, rawDir);
49
-
50
- eleventyConfig.on('eleventy.directories', (directories) => {
51
- syncCacheFromDirectories(cache, directories, rawDir);
52
-
53
- // Add a virtual directory key only if not already defined/configurable.
54
- const existing = Object.getOwnPropertyDescriptor(eleventyConfig.directories, userKey);
55
- if (existing && existing.configurable === false) {
56
- warnIfVerbose(verbose, `directories[${userKey}] already defined; skipping`);
57
- return;
58
- }
59
-
60
- Object.defineProperty(eleventyConfig.directories, userKey, {
61
- get() {
62
- return cache.assetsInput;
63
- },
64
- enumerable: true,
65
- configurable: false
66
- });
67
- });
68
-
69
- eleventyConfig.addGlobalData('_baseline.assets', () => {
70
- ensureCache(cache, eleventyConfig, rawDir, verbose);
71
- // Merge with existing _baseline.assets (e.g., esbuild config)
72
- const existing = eleventyConfig.globalData?._baseline?.assets || {};
73
- return {
74
- input: cache.assetsInput,
75
- output: cache.assetsOutput,
76
- ...existing
77
- };
78
- });
79
-
80
- // Watch target — use resolved assets input dir.
81
- ensureCache(cache, eleventyConfig, rawDir, verbose);
82
- const watchGlob = TemplatePath.join(cache.assetsInput, '**/*.{css,js,svg,png,jpeg,jpg,webp,gif,avif}');
83
- eleventyConfig.addWatchTarget(watchGlob);
84
- }
@@ -1,24 +0,0 @@
1
- import * as esbuild from 'esbuild';
2
-
3
- const defaultOptions = { minify: true, target: 'es2020' };
4
-
5
- export default async function inlineESbuild(jsFilePath, options = {}) {
6
- const userOptions = { ...defaultOptions, ...options };
7
-
8
- try {
9
- let result = await esbuild.build({
10
- entryPoints: [jsFilePath],
11
- bundle: true,
12
- minify: userOptions.minify,
13
- target: userOptions.target,
14
- write: false
15
- });
16
-
17
- // Return raw JS; markup wrapping is handled by the plugin registration.
18
- return result.outputFiles[0].text;
19
- } catch (error) {
20
- console.error(error);
21
- // Surface a safe JS comment so the caller can decide how to wrap it.
22
- return '/* Error processing JS */';
23
- }
24
- }
@@ -1,71 +0,0 @@
1
- import path from 'node:path';
2
- import * as esbuild from 'esbuild';
3
- import { resolveAssetsDir } from '../../../core/helpers.js';
4
- import inlineESbuild from '../filters/inline-esbuild.js';
5
-
6
- /**
7
- * assets-esbuild
8
- *
9
- * - Registers `js` as a template format and bundles/minifies `index.js` entries under the resolved assets `js` dir.
10
- * - Registers `inlineESbuild` filter to inline arbitrary JS by bundling it with esbuild.
11
- * - Filters the `all` collection to drop `11tydata.js` files (added by the `js` template format).
12
- *
13
- * Options:
14
- * - minify (boolean, default true): pass-through to esbuild minify flag.
15
- * - target (string|string[], default "es2020"): pass-through to esbuild target.
16
- */
17
- /** @param {import("@11ty/eleventy").UserConfig} eleventyConfig */
18
- export default function assetsESBuild(eleventyConfig, options = {}) {
19
- const defaultOptions = { minify: true, target: 'es2020' };
20
- const { assetsDir } = resolveAssetsDir(
21
- eleventyConfig.dir?.input || './',
22
- eleventyConfig.dir?.output || './',
23
- eleventyConfig.dir?.assets || 'assets'
24
- );
25
- const jsDir = `${assetsDir}js/`;
26
- const userOptions = { ...defaultOptions, ...options };
27
-
28
- eleventyConfig.addTemplateFormats('js');
29
-
30
- eleventyConfig.addExtension('js', {
31
- outputFileExtension: 'js',
32
- useLayouts: false,
33
- compile: async function (_inputContent, inputPath) {
34
- if (
35
- inputPath.includes('11tydata.js') ||
36
- !inputPath.startsWith(jsDir) ||
37
- path.basename(inputPath) !== 'index.js'
38
- ) {
39
- return;
40
- }
41
-
42
- return async () => {
43
- let result = await esbuild.build({
44
- entryPoints: [inputPath],
45
- bundle: true,
46
- minify: userOptions.minify,
47
- target: userOptions.target,
48
- write: false
49
- });
50
-
51
- return result.outputFiles[0].text;
52
- };
53
- }
54
- });
55
-
56
- // Filter to inline a bundled entry; supports callback style (Nunjucks/Liquid) and Promise return.
57
- eleventyConfig.addAsyncFilter('inlineESbuild', async function (jsFilePath, callback) {
58
- const done = typeof callback === 'function' ? callback : null;
59
- try {
60
- const js = await inlineESbuild(jsFilePath);
61
- const html = `<script>${js}</script>`;
62
- if (done) return done(null, html);
63
- return html;
64
- } catch {
65
- // Non-fatal fallback: return an error comment wrapped in script tags.
66
- const html = `<script>/* Error processing JS */</script>`;
67
- if (done) return done(null, html);
68
- return html;
69
- }
70
- });
71
- }
@@ -1,38 +0,0 @@
1
- import fs from 'fs/promises';
2
- import postcss from 'postcss';
3
- import loadPostCSSConfig from 'postcss-load-config';
4
- import fallbackPostCSSConfig from '../fallback/postcss.config.js';
5
-
6
- // Resolve user PostCSS config from the project root (cwd), not the Eleventy input dir.
7
- const configRoot = process.cwd();
8
-
9
- export default async function inlinePostCSS(cssFilePath) {
10
- try {
11
- let cssContent = await fs.readFile(cssFilePath, 'utf8');
12
-
13
- let plugins;
14
- let options;
15
-
16
- try {
17
- // Prefer the consuming project's PostCSS config (postcss.config.* or package.json#postcss).
18
- ({ plugins, options } = await loadPostCSSConfig({}, configRoot));
19
- } catch {
20
- // If none is found, fall back to the bundled Baseline config to keep builds working.
21
- const { plugins: fallbackPlugins, ...fallbackOptions } = fallbackPostCSSConfig;
22
- plugins = fallbackPlugins;
23
- options = fallbackOptions;
24
- }
25
-
26
- let result = await postcss(plugins).process(cssContent, {
27
- from: cssFilePath,
28
- map: options?.map
29
- });
30
-
31
- // Return raw CSS; markup wrapping is handled in the plugin registration.
32
- return result.css;
33
- } catch (error) {
34
- console.error(error);
35
- // Surface a safe CSS string so the caller can decide how to wrap it.
36
- return '/* Error processing CSS */';
37
- }
38
- }
@@ -1,75 +0,0 @@
1
- import path from 'node:path';
2
- import postcss from 'postcss';
3
- import loadPostCSSConfig from 'postcss-load-config';
4
- import fallbackPostCSSConfig from '../fallback/postcss.config.js';
5
- import inlinePostCSS from '../filters/inline-postcss.js';
6
- import { resolveAssetsDir } from '../../../core/helpers.js';
7
-
8
- /**
9
- * assets-postcss
10
- *
11
- * - Registers `css` as a template format and processes `index.css` entries under the resolved assets `css` dir with PostCSS.
12
- * - Registers `inlinePostCSS` filter to inline arbitrary CSS by processing it with PostCSS.
13
- * - No module-specific options (inherits global Baseline verbose only).
14
- */
15
- /** @param {import("@11ty/eleventy").UserConfig} eleventyConfig */
16
- export default function assetsPostCSS(eleventyConfig) {
17
- const { assetsDir } = resolveAssetsDir(
18
- eleventyConfig.dir?.input || './',
19
- eleventyConfig.dir?.output || './',
20
- eleventyConfig.dir?.assets || 'assets'
21
- );
22
- const cssDir = `${assetsDir}css/`;
23
-
24
- // Resolve user PostCSS config from the project root (cwd), not the Eleventy input dir.
25
- const configRoot = process.cwd();
26
-
27
- eleventyConfig.addTemplateFormats('css');
28
-
29
- eleventyConfig.addExtension('css', {
30
- outputFileExtension: 'css',
31
- useLayouts: false,
32
- compile: async function (_inputContent, inputPath) {
33
- if (!inputPath.startsWith(cssDir) || path.basename(inputPath) !== 'index.css') {
34
- return;
35
- }
36
-
37
- return async () => {
38
- let plugins;
39
- let options;
40
-
41
- try {
42
- // Prefer the consuming project's PostCSS config (postcss.config.* or package.json#postcss).
43
- ({ plugins, options } = await loadPostCSSConfig({}, configRoot));
44
- } catch {
45
- // If none is found, fall back to the bundled Baseline config to keep builds working.
46
- ({ plugins, ...options } = fallbackPostCSSConfig);
47
- }
48
-
49
- const result = await postcss(plugins).process(_inputContent, {
50
- from: inputPath,
51
- map: options?.map,
52
- ...options
53
- });
54
-
55
- return result.css;
56
- };
57
- }
58
- });
59
-
60
- // Filter to inline a bundled entry; supports callback style (Nunjucks/Liquid) and Promise return.
61
- eleventyConfig.addAsyncFilter('inlinePostCSS', async function (cssFilePath, callback) {
62
- const done = typeof callback === 'function' ? callback : null;
63
- try {
64
- const css = await inlinePostCSS(cssFilePath);
65
- const html = `<style>${css}</style>`;
66
- if (done) return done(null, html);
67
- return html;
68
- } catch {
69
- // Keep behavior non-fatal: return a styled error comment instead of throwing.
70
- const html = `<style>/* Error processing CSS */</style>`;
71
- if (done) return done(null, html);
72
- return html;
73
- }
74
- });
75
- }