@apleasantview/eleventy-plugin-baseline 0.1.0-next.33 → 0.1.0-next.40
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.
- package/README.md +48 -23
- package/core/content-map-store.js +51 -0
- package/core/filters/index.js +4 -0
- package/core/filters/isString.js +1 -1
- package/core/filters/related-posts.js +1 -1
- package/core/global-functions/index.js +6 -0
- package/core/logging.js +54 -23
- package/core/page-context.js +310 -0
- package/core/registry.js +110 -0
- package/core/schema.js +70 -0
- package/core/shortcodes/image.js +8 -3
- package/core/shortcodes/index.js +2 -0
- package/core/slug-index.js +61 -0
- package/core/translation-map-store.js +46 -0
- package/core/types.js +73 -0
- package/core/utils/helpers.js +75 -0
- package/core/utils/pick.js +7 -0
- package/core/virtual-dir.js +111 -0
- package/core/wikilinks.js +152 -0
- package/index.js +364 -0
- package/modules/assets/index.js +162 -0
- package/modules/assets/processors/esbuild-process.js +68 -0
- package/modules/{assets-postcss/process.js → assets/processors/postcss-process.js} +39 -2
- package/modules/assets/schema.js +14 -0
- package/modules/head/drivers/capo-adapter.js +94 -0
- package/modules/head/drivers/posthtml-head-elements.js +140 -0
- package/modules/head/index.js +106 -0
- package/modules/head/schema.js +42 -0
- package/modules/head/utils/alternates.js +11 -0
- package/modules/head/utils/dedupe.js +47 -0
- package/modules/multilang/index.js +149 -0
- package/modules/navigator/index.js +140 -0
- package/modules/navigator/schema.js +13 -0
- package/modules/{navigator-core → navigator}/templates/navigator-core.html +10 -4
- package/{core → modules/navigator/utils}/debug.js +7 -1
- package/modules/sitemap/index.js +121 -0
- package/modules/{sitemap-core → sitemap}/templates/sitemap-core.html +2 -2
- package/modules/{sitemap-core → sitemap}/templates/sitemap-index.html +2 -2
- package/modules.js +6 -0
- package/package.json +15 -6
- package/core/filters.js +0 -9
- package/core/globals.js +0 -6
- package/core/helpers.js +0 -36
- package/core/modules.js +0 -18
- package/core/shortcodes.js +0 -3
- package/eleventy.config.js +0 -169
- package/modules/assets-core/plugins/assets-core.js +0 -197
- package/modules/assets-esbuild/process.js +0 -33
- package/modules/head-core/drivers/posthtml-head-elements.js +0 -127
- package/modules/head-core/plugins/head-core.js +0 -75
- package/modules/head-core/utils/head-utils.js +0 -249
- package/modules/multilang-core/plugins/multilang-core.js +0 -118
- package/modules/navigator-core/plugins/navigator-core.js +0 -57
- package/modules/sitemap-core/plugins/sitemap-core.js +0 -88
- /package/core/{globals → global-functions}/date.js +0 -0
- /package/modules/{assets-postcss/fallback → assets/configs}/postcss.config.js +0 -0
- /package/modules/{multilang-core → multilang}/filters/i18n-default-translation.js +0 -0
- /package/modules/{multilang-core → multilang}/filters/i18n-translation-in.js +0 -0
- /package/modules/{multilang-core → multilang}/filters/i18n-translations-for.js +0 -0
package/eleventy.config.js
DELETED
|
@@ -1,169 +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
|
-
eleventyConfig.versionCheck('>=3.0');
|
|
34
|
-
} catch (e) {
|
|
35
|
-
console.log(`[eleventy-plugin-baseline] WARN Eleventy plugin compatibility: ${e.message}`);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// --- Options ---
|
|
39
|
-
// Merge user options with defaults, detect environment capabilities,
|
|
40
|
-
// and expose everything as _baseline global data for templates.
|
|
41
|
-
const hasImageTransformPlugin = eleventyConfig.hasPlugin('eleventyImageTransformPlugin');
|
|
42
|
-
|
|
43
|
-
const userOptions = {
|
|
44
|
-
version,
|
|
45
|
-
name,
|
|
46
|
-
verbose: options.verbose ?? false,
|
|
47
|
-
hasImageTransformPlugin,
|
|
48
|
-
enableNavigatorTemplate: options.enableNavigatorTemplate ?? false,
|
|
49
|
-
enableSitemapTemplate: options.enableSitemapTemplate ?? true,
|
|
50
|
-
filterAllCollection: options.filterAllCollection ?? true,
|
|
51
|
-
assets: {
|
|
52
|
-
esbuild: options.assetsESBuild ?? {}
|
|
53
|
-
},
|
|
54
|
-
multilingual: options.multilingual ?? false,
|
|
55
|
-
...options
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
// --- Language normalization ---
|
|
59
|
-
// Accept languages as array or object; normalize to object map.
|
|
60
|
-
// Drives multilang-core registration and sitemap-core language config.
|
|
61
|
-
const normalizedLanguages = Array.isArray(userOptions.languages)
|
|
62
|
-
? Object.fromEntries(
|
|
63
|
-
userOptions.languages
|
|
64
|
-
.filter((lang) => typeof lang === 'string' && lang.trim())
|
|
65
|
-
.map((lang) => [lang.trim(), {}])
|
|
66
|
-
)
|
|
67
|
-
: userOptions.languages && typeof userOptions.languages === 'object'
|
|
68
|
-
? userOptions.languages
|
|
69
|
-
: null;
|
|
70
|
-
|
|
71
|
-
if (userOptions.verbose && Array.isArray(userOptions.languages)) {
|
|
72
|
-
const normalizedCount = normalizedLanguages ? Object.keys(normalizedLanguages).length : 0;
|
|
73
|
-
if (normalizedCount !== userOptions.languages.length) {
|
|
74
|
-
console.warn('[baseline] Some languages entries were invalid and were dropped.');
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
userOptions.languages = normalizedLanguages;
|
|
79
|
-
const languages = normalizedLanguages;
|
|
80
|
-
const hasLanguages = languages && Object.keys(languages).length > 0;
|
|
81
|
-
const isMultilingual = userOptions.multilingual === true && userOptions.defaultLanguage && hasLanguages;
|
|
82
|
-
|
|
83
|
-
// --- Core setup ---
|
|
84
|
-
// Global data, globals registration, static passthrough, drafts preprocessor.
|
|
85
|
-
eleventyConfig.addGlobalData('_baseline', userOptions);
|
|
86
|
-
globals(eleventyConfig);
|
|
87
|
-
eleventyConfig.addPassthroughCopy({ './src/static': '/' });
|
|
88
|
-
|
|
89
|
-
// Drafts preprocessor — skip draft pages during production builds.
|
|
90
|
-
// Guarded against double-registration; user config wins if already set.
|
|
91
|
-
if (!eleventyConfig.preprocessors.drafts) {
|
|
92
|
-
eleventyConfig.addPreprocessor('drafts', '*', (data) => {
|
|
93
|
-
if (data.draft && process.env.ELEVENTY_RUN_MODE === 'build') {
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// --- Modules ---
|
|
100
|
-
// Registration order matters: multilang first (sets up locale data),
|
|
101
|
-
// then assets, head, sitemap. Navigator is last (debug only).
|
|
102
|
-
|
|
103
|
-
if (isMultilingual) {
|
|
104
|
-
eleventyConfig.addPlugin(modules.multilangCore, {
|
|
105
|
-
defaultLanguage: userOptions.defaultLanguage,
|
|
106
|
-
languages
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
eleventyConfig.addPlugin(modules.EleventyHtmlBasePlugin, {
|
|
111
|
-
baseHref: process.env.URL || eleventyConfig.pathPrefix
|
|
112
|
-
});
|
|
113
|
-
eleventyConfig.addPlugin(modules.assetsCore, { esbuild: userOptions.assets.esbuild });
|
|
114
|
-
|
|
115
|
-
eleventyConfig.addPlugin(modules.headCore);
|
|
116
|
-
eleventyConfig.addPlugin(modules.sitemapCore, {
|
|
117
|
-
enableSitemapTemplate: userOptions.enableSitemapTemplate,
|
|
118
|
-
multilingual: isMultilingual,
|
|
119
|
-
languages
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
// --- Filters ---
|
|
123
|
-
eleventyConfig.addFilter('markdownify', filters.markdownFilter);
|
|
124
|
-
eleventyConfig.addFilter('relatedPosts', filters.relatedPostsFilter);
|
|
125
|
-
eleventyConfig.addFilter('isString', filters.isStringFilter);
|
|
126
|
-
|
|
127
|
-
// --- Shortcodes ---
|
|
128
|
-
eleventyConfig.addShortcode('image', shortcodes.imageShortcode);
|
|
129
|
-
|
|
130
|
-
// --- Image dev server ---
|
|
131
|
-
// Serves on-demand image transforms during `--serve` without writing to disk.
|
|
132
|
-
eleventyConfig.addPlugin(eleventyImageOnRequestDuringServePlugin);
|
|
133
|
-
|
|
134
|
-
// --- Debug ---
|
|
135
|
-
// Underscore-prefixed filters and navigator template for inspecting
|
|
136
|
-
// data at render time. Not part of the public API surface.
|
|
137
|
-
eleventyConfig.addFilter('_inspect', debug.inspect);
|
|
138
|
-
eleventyConfig.addFilter('_json', debug.json);
|
|
139
|
-
eleventyConfig.addFilter('_keys', debug.keys);
|
|
140
|
-
eleventyConfig.addPlugin(modules.navigatorCore, { enableNavigatorTemplate: userOptions.enableNavigatorTemplate });
|
|
141
|
-
|
|
142
|
-
// Temporary content map debug listener.
|
|
143
|
-
eleventyConfig.on('eleventy.contentMap', async ({ inputPathToUrl, urlToInputPath }) => {
|
|
144
|
-
let debuginput = inputPathToUrl;
|
|
145
|
-
let debugurl = urlToInputPath;
|
|
146
|
-
|
|
147
|
-
return (debuginput, debugurl);
|
|
148
|
-
});
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
// Set a named function identity so eleventyConfig.hasPlugin() can detect this plugin.
|
|
152
|
-
Object.defineProperty(plugin, 'name', { value: `${name}` });
|
|
153
|
-
return plugin;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// --- Eleventy directory and template config ---
|
|
157
|
-
// Exported separately so consuming sites can re-export without duplicating values.
|
|
158
|
-
export const config = {
|
|
159
|
-
dir: {
|
|
160
|
-
input: 'src',
|
|
161
|
-
output: 'dist',
|
|
162
|
-
data: '_data',
|
|
163
|
-
includes: '_includes',
|
|
164
|
-
assets: 'assets'
|
|
165
|
-
},
|
|
166
|
-
htmlTemplateEngine: 'njk',
|
|
167
|
-
markdownTemplateEngine: 'njk',
|
|
168
|
-
templateFormats: ['html', 'njk', 'md']
|
|
169
|
-
};
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { TemplatePath } from '@11ty/eleventy-utils';
|
|
3
|
-
import { addTrailingSlash, resolveAssetsDir } from '../../../core/helpers.js';
|
|
4
|
-
import { warnIfVerbose, getVerbose } from '../../../core/logging.js';
|
|
5
|
-
|
|
6
|
-
import assetsESbuild from '../../assets-esbuild/process.js';
|
|
7
|
-
import assetsPostCSS from '../../assets-postcss/process.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Sync the cache object with resolved directory paths.
|
|
11
|
-
* Called once at registration time and again on the eleventy.directories event
|
|
12
|
-
* when Eleventy finalizes its directory config.
|
|
13
|
-
*/
|
|
14
|
-
const syncCacheFromDirectories = (cache, dirs, rawDir) => {
|
|
15
|
-
const inputDir = TemplatePath.addLeadingDotSlash(dirs.input || './');
|
|
16
|
-
const outputDir = TemplatePath.addLeadingDotSlash(dirs.output || './');
|
|
17
|
-
const { assetsDir, assetsOutputDir } = resolveAssetsDir(inputDir, outputDir, rawDir);
|
|
18
|
-
|
|
19
|
-
cache.input = addTrailingSlash(inputDir);
|
|
20
|
-
cache.output = addTrailingSlash(outputDir);
|
|
21
|
-
cache.assetsInput = assetsDir;
|
|
22
|
-
cache.assetsOutput = assetsOutputDir;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Guard: resolve directories from eleventyConfig.dir if the eleventy.directories
|
|
27
|
-
* event hasn't fired yet (e.g. when global data or watch targets are read early).
|
|
28
|
-
*/
|
|
29
|
-
const ensureCache = (cache, eleventyConfig, rawDir, verbose) => {
|
|
30
|
-
if (cache.assetsInput) return;
|
|
31
|
-
syncCacheFromDirectories(cache, eleventyConfig.dir || {}, rawDir);
|
|
32
|
-
warnIfVerbose(verbose, 'Fallback directory resolution');
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* eleventy-plugin-assets-core
|
|
37
|
-
*
|
|
38
|
-
* The single assets plugin. Owns all Eleventy wiring for JS and CSS processing:
|
|
39
|
-
* directory resolution, template formats, extensions, compile guards, inline
|
|
40
|
-
* filters, watch targets, and global data. Processing logic lives in the
|
|
41
|
-
* pure functions imported from assets-esbuild and assets-postcss.
|
|
42
|
-
*
|
|
43
|
-
* Options:
|
|
44
|
-
* - verbose (boolean, default global baseline verbose): enable verbose logs.
|
|
45
|
-
* - esbuild (object): options forwarded to esbuild (minify, target).
|
|
46
|
-
* Defaults live in assets-esbuild/process.js — pass only overrides.
|
|
47
|
-
*/
|
|
48
|
-
/** @param {import("@11ty/eleventy").UserConfig} eleventyConfig */
|
|
49
|
-
export default function assetsCore(eleventyConfig, options = {}) {
|
|
50
|
-
const verbose = getVerbose(eleventyConfig) || options.verbose || false;
|
|
51
|
-
const userKey = 'assets';
|
|
52
|
-
|
|
53
|
-
// Extract raw directory value from config (can be done early).
|
|
54
|
-
const rawDir = eleventyConfig.dir?.[userKey] || userKey;
|
|
55
|
-
|
|
56
|
-
// Cache holds resolved paths. Initialized as nulls, populated immediately
|
|
57
|
-
// by syncCacheFromDirectories, then updated when eleventy.directories fires.
|
|
58
|
-
const cache = {
|
|
59
|
-
input: null,
|
|
60
|
-
output: null,
|
|
61
|
-
assetsInput: null,
|
|
62
|
-
assetsOutput: null
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
syncCacheFromDirectories(cache, eleventyConfig.dir || {}, rawDir);
|
|
66
|
-
|
|
67
|
-
// Update cache when Eleventy finalizes directories, and register a virtual
|
|
68
|
-
// `directories.assets` key so other code can read the resolved assets path.
|
|
69
|
-
eleventyConfig.on('eleventy.directories', (directories) => {
|
|
70
|
-
syncCacheFromDirectories(cache, directories, rawDir);
|
|
71
|
-
|
|
72
|
-
// Add a virtual directory key only if not already defined/configurable.
|
|
73
|
-
const existing = Object.getOwnPropertyDescriptor(eleventyConfig.directories, userKey);
|
|
74
|
-
if (existing && existing.configurable === false) {
|
|
75
|
-
warnIfVerbose(verbose, `directories[${userKey}] already defined; skipping`);
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
Object.defineProperty(eleventyConfig.directories, userKey, {
|
|
80
|
-
get() {
|
|
81
|
-
return cache.assetsInput;
|
|
82
|
-
},
|
|
83
|
-
enumerable: true,
|
|
84
|
-
configurable: false
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
// Expose resolved assets paths as global data for templates.
|
|
89
|
-
// Templates use _baseline.assets.input to build paths for inline filters.
|
|
90
|
-
eleventyConfig.addGlobalData('_baseline.assets', () => {
|
|
91
|
-
ensureCache(cache, eleventyConfig, rawDir, verbose);
|
|
92
|
-
return {
|
|
93
|
-
input: cache.assetsInput,
|
|
94
|
-
output: cache.assetsOutput
|
|
95
|
-
};
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
// Watch common asset formats so edits trigger reloads during --serve.
|
|
99
|
-
ensureCache(cache, eleventyConfig, rawDir, verbose);
|
|
100
|
-
const watchGlob = TemplatePath.join(cache.assetsInput, '**/*.{css,js,svg,png,jpeg,jpg,webp,gif,avif}');
|
|
101
|
-
eleventyConfig.addWatchTarget(watchGlob);
|
|
102
|
-
|
|
103
|
-
// --- JS (esbuild) ---
|
|
104
|
-
// Register js as a template format. Only index.js files under assets/js/
|
|
105
|
-
// are compiled; everything else (11tydata.js, non-entry scripts) is skipped
|
|
106
|
-
// by the compile guard. The inline filter wraps the same process function.
|
|
107
|
-
// Defaults (minify, target) live in assets-esbuild/process.js.
|
|
108
|
-
|
|
109
|
-
const esbuildOptions = options.esbuild || {};
|
|
110
|
-
const jsDir = `${cache.assetsInput}js/`;
|
|
111
|
-
|
|
112
|
-
eleventyConfig.addTemplateFormats('js');
|
|
113
|
-
|
|
114
|
-
// Prevent Eleventy from processing 11tydata.js files as templates.
|
|
115
|
-
// The compile guard below also filters these, but without this ignore
|
|
116
|
-
// Eleventy still enters them into the template graph (data cascade,
|
|
117
|
-
// permalink computation) before compile gets a chance to reject them.
|
|
118
|
-
eleventyConfig.ignores.add(`${cache.input}**/*.11tydata.js`);
|
|
119
|
-
|
|
120
|
-
eleventyConfig.addExtension('js', {
|
|
121
|
-
outputFileExtension: 'js',
|
|
122
|
-
useLayouts: false,
|
|
123
|
-
read: false,
|
|
124
|
-
compileOptions: {
|
|
125
|
-
permalink: true,
|
|
126
|
-
cache: true
|
|
127
|
-
},
|
|
128
|
-
// Compile guard: only process index.js files under the assets js directory.
|
|
129
|
-
// Returning undefined skips the file without error.
|
|
130
|
-
compile: async function (_inputContent, inputPath) {
|
|
131
|
-
if (
|
|
132
|
-
inputPath.includes('11tydata.js') ||
|
|
133
|
-
!inputPath.startsWith(jsDir) ||
|
|
134
|
-
path.basename(inputPath) !== 'index.js'
|
|
135
|
-
) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return async () => assetsESbuild(inputPath, esbuildOptions);
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
// Inline filter: bundle a JS file and wrap in <script> tags.
|
|
144
|
-
// Accepts per-call esbuild options (merged with defaults in process.js).
|
|
145
|
-
// Eleventy's addAsyncFilter handles the Nunjucks callback bridge,
|
|
146
|
-
// so this is a plain async function.
|
|
147
|
-
eleventyConfig.addAsyncFilter('inlineESbuild', async function (inputPath, opts = {}) {
|
|
148
|
-
try {
|
|
149
|
-
const js = await assetsESbuild(inputPath, opts);
|
|
150
|
-
return `<script>${js}</script>`;
|
|
151
|
-
} catch {
|
|
152
|
-
// Non-fatal: return an error comment so the build doesn't break.
|
|
153
|
-
return `<script>/* Error processing JS */</script>`;
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
// --- CSS (PostCSS) ---
|
|
158
|
-
// Register css as a template format. Only index.css files under assets/css/
|
|
159
|
-
// are compiled; non-entry CSS is skipped. Reads from disk (read: false) —
|
|
160
|
-
// the process function owns its own I/O. Config loading and caching live
|
|
161
|
-
// in assets-postcss/process.js.
|
|
162
|
-
|
|
163
|
-
const cssDir = `${cache.assetsInput}css/`;
|
|
164
|
-
|
|
165
|
-
eleventyConfig.addTemplateFormats('css');
|
|
166
|
-
|
|
167
|
-
eleventyConfig.addExtension('css', {
|
|
168
|
-
outputFileExtension: 'css',
|
|
169
|
-
useLayouts: false,
|
|
170
|
-
read: false,
|
|
171
|
-
compileOptions: {
|
|
172
|
-
permalink: true,
|
|
173
|
-
cache: true
|
|
174
|
-
},
|
|
175
|
-
// Compile guard: only process index.css files under the assets css directory.
|
|
176
|
-
compile: async function (_inputContent, inputPath) {
|
|
177
|
-
if (!inputPath.startsWith(cssDir) || path.basename(inputPath) !== 'index.css') {
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
return async () => assetsPostCSS(inputPath);
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
// Inline filter: process a CSS file through PostCSS and wrap in <style> tags.
|
|
186
|
-
// Eleventy's addAsyncFilter handles the Nunjucks callback bridge,
|
|
187
|
-
// so this is a plain async function.
|
|
188
|
-
eleventyConfig.addAsyncFilter('inlinePostCSS', async function (inputPath) {
|
|
189
|
-
try {
|
|
190
|
-
const css = await assetsPostCSS(inputPath);
|
|
191
|
-
return `<style>${css}</style>`;
|
|
192
|
-
} catch {
|
|
193
|
-
// Non-fatal: return an error comment so the build doesn't break.
|
|
194
|
-
return `<style>/* Error processing CSS */</style>`;
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import * as esbuild from 'esbuild';
|
|
2
|
-
|
|
3
|
-
const defaultOptions = { minify: true, target: 'es2020' };
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Bundle a JS file with esbuild.
|
|
7
|
-
*
|
|
8
|
-
* @param {string} jsFilePath - Absolute path to the entry file.
|
|
9
|
-
* @param {Object} [options] - esbuild options (merged with defaults).
|
|
10
|
-
* @param {boolean} [options.minify=true] - Minify output.
|
|
11
|
-
* @param {string} [options.target='es2020'] - esbuild target.
|
|
12
|
-
* @returns {Promise<string>} Bundled JS text, or an error comment on failure.
|
|
13
|
-
*/
|
|
14
|
-
export default async function assetsESbuild(jsFilePath, options = {}) {
|
|
15
|
-
const userOptions = { ...defaultOptions, ...options };
|
|
16
|
-
|
|
17
|
-
try {
|
|
18
|
-
let result = await esbuild.build({
|
|
19
|
-
entryPoints: [jsFilePath],
|
|
20
|
-
bundle: true,
|
|
21
|
-
minify: userOptions.minify,
|
|
22
|
-
target: userOptions.target,
|
|
23
|
-
write: false
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
// Return raw JS; markup wrapping is handled by the plugin registration.
|
|
27
|
-
return result.outputFiles[0].text;
|
|
28
|
-
} catch (error) {
|
|
29
|
-
console.error(error);
|
|
30
|
-
// Surface a safe JS comment so the caller can decide how to wrap it.
|
|
31
|
-
return '/* Error processing JS */';
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
// Based on posthtml-head-elements (MIT License).
|
|
2
|
-
// Original: https://github.com/posthtml/posthtml-head-elements
|
|
3
|
-
// Adapted for Baseline head-core.
|
|
4
|
-
|
|
5
|
-
import { createRequire } from 'node:module';
|
|
6
|
-
|
|
7
|
-
const require = createRequire(import.meta.url);
|
|
8
|
-
|
|
9
|
-
function nonString(type, attrsArr) {
|
|
10
|
-
return attrsArr.map(function (attrs) {
|
|
11
|
-
return { tag: type, attrs: attrs };
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function nonArray(type, content) {
|
|
16
|
-
return { tag: type, content: [content] };
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function findElmType(type, objectData) {
|
|
20
|
-
const elementType = {
|
|
21
|
-
meta: function () {
|
|
22
|
-
if (Array.isArray(objectData)) {
|
|
23
|
-
return nonString(type, objectData);
|
|
24
|
-
} else {
|
|
25
|
-
console.warn('posthtml-head-elements: Please use the correct syntax for a meta element');
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
title: function () {
|
|
29
|
-
if (typeof objectData === 'string') {
|
|
30
|
-
return nonArray('title', objectData);
|
|
31
|
-
} else {
|
|
32
|
-
console.warn('posthtml-head-elements: Please use the correct syntax for a title element');
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
link: function () {
|
|
36
|
-
if (Array.isArray(objectData)) {
|
|
37
|
-
return nonString(type, objectData);
|
|
38
|
-
} else {
|
|
39
|
-
console.warn('posthtml-head-elements: Please use the correct syntax for a link element');
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
linkCanonical: function () {
|
|
43
|
-
if (Array.isArray(objectData)) {
|
|
44
|
-
return nonString('link', objectData);
|
|
45
|
-
} else {
|
|
46
|
-
console.warn('posthtml-head-elements: Please use the correct syntax for a linkCanonical element');
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
script: function () {
|
|
50
|
-
if (Array.isArray(objectData)) {
|
|
51
|
-
return objectData.map(function (entry) {
|
|
52
|
-
const { content, ...attrs } = entry || {};
|
|
53
|
-
return content !== undefined ? { tag: 'script', attrs, content: [content] } : { tag: 'script', attrs };
|
|
54
|
-
});
|
|
55
|
-
} else {
|
|
56
|
-
console.warn('posthtml-head-elements: Please use the correct syntax for a script element');
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
style: function () {
|
|
60
|
-
if (Array.isArray(objectData)) {
|
|
61
|
-
return objectData.map(function (entry) {
|
|
62
|
-
const { content, ...attrs } = entry || {};
|
|
63
|
-
return content !== undefined ? { tag: 'style', attrs, content: [content] } : { tag: 'style', attrs };
|
|
64
|
-
});
|
|
65
|
-
} else {
|
|
66
|
-
console.warn('posthtml-head-elements: Please use the correct syntax for a style element');
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
base: function () {
|
|
70
|
-
if (Array.isArray(objectData)) {
|
|
71
|
-
return nonString(type, objectData);
|
|
72
|
-
} else {
|
|
73
|
-
console.warn('posthtml-head-elements: Please use the correct syntax for a base element');
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
default: function () {
|
|
77
|
-
console.warn('posthtml-head-elements: Please make sure the HTML head type is correct');
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
if (type.indexOf('_') !== -1) {
|
|
82
|
-
type = type.slice(0, type.indexOf('_'));
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return elementType[type]() || elementType['default']();
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function buildNewTree(headElements, EOL) {
|
|
89
|
-
const newHeadElements = [];
|
|
90
|
-
|
|
91
|
-
Object.keys(headElements).forEach(function (value) {
|
|
92
|
-
newHeadElements.push(findElmType(value, headElements[value]));
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
function cnct(arr) {
|
|
96
|
-
return Array.prototype.concat.apply([], arr);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return cnct(
|
|
100
|
-
cnct(newHeadElements).map(function (elem) {
|
|
101
|
-
return [elem, EOL];
|
|
102
|
-
})
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export default function (options) {
|
|
107
|
-
options = options || {};
|
|
108
|
-
options.headElementsTag = options.headElementsTag || 'posthtml-head-elements';
|
|
109
|
-
|
|
110
|
-
if (!options.headElements) {
|
|
111
|
-
console.warn(
|
|
112
|
-
"posthtml-head-elements: Don't forget to add a link to the JSON file containing the head elements to insert"
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
const jsonOne = typeof options.headElements !== 'string' ? options.headElements : require(options.headElements);
|
|
116
|
-
|
|
117
|
-
return function posthtmlHeadElements(tree) {
|
|
118
|
-
tree.match({ tag: options.headElementsTag }, function () {
|
|
119
|
-
return {
|
|
120
|
-
tag: false, // delete this node, safe content
|
|
121
|
-
content: buildNewTree(jsonOne, options.EOL || '\n')
|
|
122
|
-
};
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
return tree;
|
|
126
|
-
};
|
|
127
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import headElements from '../drivers/posthtml-head-elements.js';
|
|
2
|
-
import { getVerbose, logIfVerbose } from '../../../core/logging.js';
|
|
3
|
-
import { buildHead } from '../utils/head-utils.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* eleventy-plugin-head-core
|
|
7
|
-
*
|
|
8
|
-
* Manages the <head> for every page. Merges site-level defaults, page-level
|
|
9
|
-
* overrides, and computed values (canonical URL, open graph, structured data)
|
|
10
|
-
* into a single head spec, then injects the result into HTML via a PostHTML
|
|
11
|
-
* transform. Pages control their head through a `head` data key.
|
|
12
|
-
*
|
|
13
|
-
* Depends on: core/logging, head-core/utils/head-utils, head-core/drivers/posthtml-head-elements.
|
|
14
|
-
* No cross-module dependencies.
|
|
15
|
-
*/
|
|
16
|
-
/** @param {import("@11ty/eleventy").UserConfig} eleventyConfig */
|
|
17
|
-
export default function headCore(eleventyConfig, options = {}) {
|
|
18
|
-
const verbose = getVerbose(eleventyConfig) || options.verbose || false;
|
|
19
|
-
|
|
20
|
-
// Internal options — not part of the public API.
|
|
21
|
-
const userKey = options.dirKey || 'head';
|
|
22
|
-
const headElementsTag = options.headElementsTag || 'baseline-head';
|
|
23
|
-
const eol = options.EOL || '\n';
|
|
24
|
-
const pathPrefix = options.pathPrefix ?? eleventyConfig?.pathPrefix ?? '';
|
|
25
|
-
const siteUrl = options.siteUrl;
|
|
26
|
-
|
|
27
|
-
// Cache the content map so canonical URLs can resolve inputPath → URL.
|
|
28
|
-
// Updated each build when Eleventy emits the contentMap event.
|
|
29
|
-
let cachedContentMap = {};
|
|
30
|
-
eleventyConfig.on('eleventy.contentMap', ({ inputPathToUrl, urlToInputPath }) => {
|
|
31
|
-
cachedContentMap = { inputPathToUrl, urlToInputPath };
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
// Computed global data: build the head spec for every page through the
|
|
35
|
-
// data cascade. Templates access the result via `page.head`.
|
|
36
|
-
eleventyConfig.addGlobalData('eleventyComputed.page.head', () => {
|
|
37
|
-
return (data) =>
|
|
38
|
-
buildHead(data, {
|
|
39
|
-
userKey,
|
|
40
|
-
siteUrl,
|
|
41
|
-
pathPrefix,
|
|
42
|
-
contentMap: cachedContentMap,
|
|
43
|
-
pageUrlOverride: data?.page?.url,
|
|
44
|
-
verbose
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
// HTML transform: inject the head spec into the document <head> using
|
|
49
|
-
// PostHTML. Replaces the <baseline-head> placeholder tag with real elements.
|
|
50
|
-
// Falls back to building the spec from context if page.head isn't available.
|
|
51
|
-
eleventyConfig.htmlTransformer.addPosthtmlPlugin('html', function (context) {
|
|
52
|
-
logIfVerbose(verbose, 'head-core: injecting head elements for', context?.page?.inputPath || context?.outputPath);
|
|
53
|
-
|
|
54
|
-
const headElementsSpec =
|
|
55
|
-
context?.page?.head ||
|
|
56
|
-
buildHead(context, {
|
|
57
|
-
userKey,
|
|
58
|
-
siteUrl,
|
|
59
|
-
pathPrefix,
|
|
60
|
-
contentMap: cachedContentMap,
|
|
61
|
-
pageUrlOverride: context?.page?.url,
|
|
62
|
-
verbose
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
const plugin = headElements({
|
|
66
|
-
headElements: headElementsSpec,
|
|
67
|
-
headElementsTag,
|
|
68
|
-
EOL: eol
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
return async function asyncHead(tree) {
|
|
72
|
-
return plugin(tree);
|
|
73
|
-
};
|
|
74
|
-
});
|
|
75
|
-
}
|