@apleasantview/eleventy-plugin-baseline 0.1.0-next.22 → 0.1.0-next.28
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 +3 -1
- package/core/debug.js +5 -5
- package/core/filters/isString.js +1 -1
- package/core/filters/markdown.js +3 -5
- package/core/filters/related-posts.js +4 -5
- package/core/filters.js +4 -4
- package/core/globals/date.js +4 -4
- package/core/globals.js +1 -1
- package/core/helpers.js +21 -33
- package/core/modules.js +8 -8
- package/core/shortcodes/image.js +30 -39
- package/core/shortcodes.js +1 -1
- package/eleventy.config.js +71 -38
- package/modules/assets-core/plugins/assets-core.js +12 -12
- package/modules/assets-esbuild/filters/inline-esbuild.js +3 -3
- package/modules/assets-esbuild/plugins/assets-esbuild.js +22 -25
- package/modules/assets-postcss/fallback/postcss.config.js +9 -11
- package/modules/assets-postcss/filters/inline-postcss.js +7 -7
- package/modules/assets-postcss/plugins/assets-postcss.js +19 -19
- package/modules/head-core/drivers/posthtml-head-elements.js +106 -122
- package/modules/head-core/plugins/head-core.js +14 -17
- package/modules/head-core/utils/head-utils.js +57 -67
- package/modules/multilang-core/filters/i18n-default-translation.js +14 -0
- package/modules/multilang-core/filters/i18n-translation-in.js +16 -0
- package/modules/multilang-core/filters/i18n-translations-for.js +10 -0
- package/modules/multilang-core/plugins/multilang-core.js +78 -12
- package/modules/navigator-core/plugins/navigator-core.js +16 -14
- package/modules/navigator-core/templates/navigator-core.html +33 -17
- package/modules/sitemap-core/plugins/sitemap-core.js +21 -21
- package/modules/sitemap-core/templates/sitemap-core.html +4 -4
- package/package.json +1 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { TemplatePath } from
|
|
2
|
-
import { addTrailingSlash, resolveAssetsDir } from
|
|
3
|
-
import { warnIfVerbose, getVerbose } from
|
|
1
|
+
import { TemplatePath } from '@11ty/eleventy-utils';
|
|
2
|
+
import { addTrailingSlash, resolveAssetsDir } from '../../../core/helpers.js';
|
|
3
|
+
import { warnIfVerbose, getVerbose } from '../../../core/logging.js';
|
|
4
4
|
|
|
5
5
|
const syncCacheFromDirectories = (cache, dirs, rawDir) => {
|
|
6
|
-
const inputDir = TemplatePath.addLeadingDotSlash(dirs.input ||
|
|
7
|
-
const outputDir = TemplatePath.addLeadingDotSlash(dirs.output ||
|
|
6
|
+
const inputDir = TemplatePath.addLeadingDotSlash(dirs.input || './');
|
|
7
|
+
const outputDir = TemplatePath.addLeadingDotSlash(dirs.output || './');
|
|
8
8
|
const { assetsDir, assetsOutputDir } = resolveAssetsDir(inputDir, outputDir, rawDir);
|
|
9
9
|
|
|
10
10
|
cache.input = addTrailingSlash(inputDir);
|
|
@@ -16,7 +16,7 @@ const syncCacheFromDirectories = (cache, dirs, rawDir) => {
|
|
|
16
16
|
const ensureCache = (cache, eleventyConfig, rawDir, verbose) => {
|
|
17
17
|
if (cache.assetsInput) return;
|
|
18
18
|
syncCacheFromDirectories(cache, eleventyConfig.dir || {}, rawDir);
|
|
19
|
-
warnIfVerbose(verbose,
|
|
19
|
+
warnIfVerbose(verbose, 'Fallback directory resolution');
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
/**
|
|
@@ -32,7 +32,7 @@ const ensureCache = (cache, eleventyConfig, rawDir, verbose) => {
|
|
|
32
32
|
/** @param {import("@11ty/eleventy").UserConfig} eleventyConfig */
|
|
33
33
|
export default function assetsCore(eleventyConfig, options = {}) {
|
|
34
34
|
const verbose = getVerbose(eleventyConfig) || options.verbose || false;
|
|
35
|
-
const userKey =
|
|
35
|
+
const userKey = 'assets';
|
|
36
36
|
|
|
37
37
|
// Extract raw directory value from config (can be done early)
|
|
38
38
|
const rawDir = eleventyConfig.dir?.[userKey] || userKey;
|
|
@@ -42,12 +42,12 @@ export default function assetsCore(eleventyConfig, options = {}) {
|
|
|
42
42
|
input: eleventyConfig.dir?.input || null,
|
|
43
43
|
output: eleventyConfig.dir?.output || null,
|
|
44
44
|
assetsInput: eleventyConfig.dir?.assets ?? userKey ?? null,
|
|
45
|
-
assetsOutput: null
|
|
45
|
+
assetsOutput: null
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
syncCacheFromDirectories(cache, eleventyConfig.dir || {}, rawDir);
|
|
49
49
|
|
|
50
|
-
eleventyConfig.on(
|
|
50
|
+
eleventyConfig.on('eleventy.directories', (directories) => {
|
|
51
51
|
syncCacheFromDirectories(cache, directories, rawDir);
|
|
52
52
|
|
|
53
53
|
// Add a virtual directory key only if not already defined/configurable.
|
|
@@ -62,11 +62,11 @@ export default function assetsCore(eleventyConfig, options = {}) {
|
|
|
62
62
|
return cache.assetsInput;
|
|
63
63
|
},
|
|
64
64
|
enumerable: true,
|
|
65
|
-
configurable: false
|
|
65
|
+
configurable: false
|
|
66
66
|
});
|
|
67
67
|
});
|
|
68
68
|
|
|
69
|
-
eleventyConfig.addGlobalData(
|
|
69
|
+
eleventyConfig.addGlobalData('_baseline.assets', () => {
|
|
70
70
|
ensureCache(cache, eleventyConfig, rawDir, verbose);
|
|
71
71
|
// Merge with existing _baseline.assets (e.g., esbuild config)
|
|
72
72
|
const existing = eleventyConfig.globalData?._baseline?.assets || {};
|
|
@@ -79,6 +79,6 @@ export default function assetsCore(eleventyConfig, options = {}) {
|
|
|
79
79
|
|
|
80
80
|
// Watch target — use resolved assets input dir.
|
|
81
81
|
ensureCache(cache, eleventyConfig, rawDir, verbose);
|
|
82
|
-
const watchGlob = TemplatePath.join(cache.assetsInput,
|
|
82
|
+
const watchGlob = TemplatePath.join(cache.assetsInput, '**/*.{css,js,svg,png,jpeg,jpg,webp,gif,avif}');
|
|
83
83
|
eleventyConfig.addWatchTarget(watchGlob);
|
|
84
84
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as esbuild from
|
|
1
|
+
import * as esbuild from 'esbuild';
|
|
2
2
|
|
|
3
|
-
const defaultOptions = { minify: true, target:
|
|
3
|
+
const defaultOptions = { minify: true, target: 'es2020' };
|
|
4
4
|
|
|
5
5
|
export default async function inlineESbuild(jsFilePath, options = {}) {
|
|
6
6
|
const userOptions = { ...defaultOptions, ...options };
|
|
@@ -19,6 +19,6 @@ export default async function inlineESbuild(jsFilePath, options = {}) {
|
|
|
19
19
|
} catch (error) {
|
|
20
20
|
console.error(error);
|
|
21
21
|
// Surface a safe JS comment so the caller can decide how to wrap it.
|
|
22
|
-
return
|
|
22
|
+
return '/* Error processing JS */';
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import path from
|
|
2
|
-
import * as esbuild from
|
|
3
|
-
import { resolveAssetsDir } from
|
|
4
|
-
import inlineESbuild from
|
|
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
5
|
|
|
6
6
|
/**
|
|
7
7
|
* assets-esbuild
|
|
@@ -16,22 +16,26 @@ import inlineESbuild from "../filters/inline-esbuild.js";
|
|
|
16
16
|
*/
|
|
17
17
|
/** @param {import("@11ty/eleventy").UserConfig} eleventyConfig */
|
|
18
18
|
export default function assetsESBuild(eleventyConfig, options = {}) {
|
|
19
|
-
const defaultOptions = { minify: true, target:
|
|
19
|
+
const defaultOptions = { minify: true, target: 'es2020' };
|
|
20
20
|
const { assetsDir } = resolveAssetsDir(
|
|
21
|
-
eleventyConfig.dir?.input ||
|
|
22
|
-
eleventyConfig.dir?.output ||
|
|
23
|
-
eleventyConfig.dir?.assets ||
|
|
21
|
+
eleventyConfig.dir?.input || './',
|
|
22
|
+
eleventyConfig.dir?.output || './',
|
|
23
|
+
eleventyConfig.dir?.assets || 'assets'
|
|
24
24
|
);
|
|
25
25
|
const jsDir = `${assetsDir}js/`;
|
|
26
26
|
const userOptions = { ...defaultOptions, ...options };
|
|
27
|
-
|
|
28
|
-
eleventyConfig.addTemplateFormats("js");
|
|
29
27
|
|
|
30
|
-
eleventyConfig.
|
|
31
|
-
|
|
28
|
+
eleventyConfig.addTemplateFormats('js');
|
|
29
|
+
|
|
30
|
+
eleventyConfig.addExtension('js', {
|
|
31
|
+
outputFileExtension: 'js',
|
|
32
32
|
useLayouts: false,
|
|
33
33
|
compile: async function (_inputContent, inputPath) {
|
|
34
|
-
if (
|
|
34
|
+
if (
|
|
35
|
+
inputPath.includes('11tydata.js') ||
|
|
36
|
+
!inputPath.startsWith(jsDir) ||
|
|
37
|
+
path.basename(inputPath) !== 'index.js'
|
|
38
|
+
) {
|
|
35
39
|
return;
|
|
36
40
|
}
|
|
37
41
|
|
|
@@ -45,30 +49,23 @@ export default function assetsESBuild(eleventyConfig, options = {}) {
|
|
|
45
49
|
});
|
|
46
50
|
|
|
47
51
|
return result.outputFiles[0].text;
|
|
48
|
-
}
|
|
52
|
+
};
|
|
49
53
|
}
|
|
50
54
|
});
|
|
51
55
|
|
|
52
56
|
// Filter to inline a bundled entry; supports callback style (Nunjucks/Liquid) and Promise return.
|
|
53
|
-
eleventyConfig.addAsyncFilter(
|
|
54
|
-
const done = typeof callback ===
|
|
57
|
+
eleventyConfig.addAsyncFilter('inlineESbuild', async function (jsFilePath, callback) {
|
|
58
|
+
const done = typeof callback === 'function' ? callback : null;
|
|
55
59
|
try {
|
|
56
60
|
const js = await inlineESbuild(jsFilePath);
|
|
57
61
|
const html = `<script>${js}</script>`;
|
|
58
62
|
if (done) return done(null, html);
|
|
59
63
|
return html;
|
|
60
|
-
} catch
|
|
64
|
+
} catch {
|
|
61
65
|
// Non-fatal fallback: return an error comment wrapped in script tags.
|
|
62
66
|
const html = `<script>/* Error processing JS */</script>`;
|
|
63
67
|
if (done) return done(null, html);
|
|
64
68
|
return html;
|
|
65
69
|
}
|
|
66
70
|
});
|
|
67
|
-
|
|
68
|
-
// Override the default collection behavior. Adding js as template format and extension collects 11tydata.js files.
|
|
69
|
-
eleventyConfig.addCollection("all", function (collectionApi) {
|
|
70
|
-
return collectionApi.getAll().filter(item => {
|
|
71
|
-
return !item.inputPath.endsWith("11tydata.js");
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
};
|
|
71
|
+
}
|
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import postcssImportExtGlob from
|
|
2
|
-
import postcssImport from
|
|
3
|
-
import postcssPresetEnv from
|
|
4
|
-
import cssnano from
|
|
1
|
+
import postcssImportExtGlob from 'postcss-import-ext-glob';
|
|
2
|
+
import postcssImport from 'postcss-import';
|
|
3
|
+
import postcssPresetEnv from 'postcss-preset-env';
|
|
4
|
+
import cssnano from 'cssnano'; // Import cssnano for minification
|
|
5
5
|
|
|
6
|
-
const isProd = process.env.ELEVENTY_ENV ===
|
|
6
|
+
const isProd = process.env.ELEVENTY_ENV === 'production';
|
|
7
7
|
const plugins = [
|
|
8
8
|
postcssImportExtGlob,
|
|
9
9
|
postcssImport,
|
|
10
10
|
postcssPresetEnv({
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
],
|
|
14
|
-
"preserve": true,
|
|
11
|
+
browsers: ['> 0.2% and not dead'],
|
|
12
|
+
preserve: true
|
|
15
13
|
})
|
|
16
|
-
]
|
|
14
|
+
];
|
|
17
15
|
|
|
18
16
|
if (isProd) {
|
|
19
17
|
plugins.push(cssnano);
|
|
@@ -24,4 +22,4 @@ const config = {
|
|
|
24
22
|
plugins
|
|
25
23
|
};
|
|
26
24
|
|
|
27
|
-
export default config
|
|
25
|
+
export default config;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import fs from
|
|
2
|
-
import postcss from
|
|
3
|
-
import loadPostCSSConfig from
|
|
4
|
-
import fallbackPostCSSConfig from
|
|
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
5
|
|
|
6
6
|
// Resolve user PostCSS config from the project root (cwd), not the Eleventy input dir.
|
|
7
7
|
const configRoot = process.cwd();
|
|
@@ -16,7 +16,7 @@ export default async function inlinePostCSS(cssFilePath) {
|
|
|
16
16
|
try {
|
|
17
17
|
// Prefer the consuming project's PostCSS config (postcss.config.* or package.json#postcss).
|
|
18
18
|
({ plugins, options } = await loadPostCSSConfig({}, configRoot));
|
|
19
|
-
} catch
|
|
19
|
+
} catch {
|
|
20
20
|
// If none is found, fall back to the bundled Baseline config to keep builds working.
|
|
21
21
|
const { plugins: fallbackPlugins, ...fallbackOptions } = fallbackPostCSSConfig;
|
|
22
22
|
plugins = fallbackPlugins;
|
|
@@ -33,6 +33,6 @@ export default async function inlinePostCSS(cssFilePath) {
|
|
|
33
33
|
} catch (error) {
|
|
34
34
|
console.error(error);
|
|
35
35
|
// Surface a safe CSS string so the caller can decide how to wrap it.
|
|
36
|
-
return
|
|
36
|
+
return '/* Error processing CSS */';
|
|
37
37
|
}
|
|
38
|
-
}
|
|
38
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import path from
|
|
2
|
-
import postcss from
|
|
3
|
-
import loadPostCSSConfig from
|
|
4
|
-
import fallbackPostCSSConfig from
|
|
5
|
-
import inlinePostCSS from
|
|
6
|
-
import { resolveAssetsDir } from
|
|
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
7
|
|
|
8
8
|
/**
|
|
9
9
|
* assets-postcss
|
|
@@ -15,22 +15,22 @@ import { resolveAssetsDir } from "../../../core/helpers.js";
|
|
|
15
15
|
/** @param {import("@11ty/eleventy").UserConfig} eleventyConfig */
|
|
16
16
|
export default function assetsPostCSS(eleventyConfig) {
|
|
17
17
|
const { assetsDir } = resolveAssetsDir(
|
|
18
|
-
eleventyConfig.dir?.input ||
|
|
19
|
-
eleventyConfig.dir?.output ||
|
|
20
|
-
eleventyConfig.dir?.assets ||
|
|
18
|
+
eleventyConfig.dir?.input || './',
|
|
19
|
+
eleventyConfig.dir?.output || './',
|
|
20
|
+
eleventyConfig.dir?.assets || 'assets'
|
|
21
21
|
);
|
|
22
22
|
const cssDir = `${assetsDir}css/`;
|
|
23
23
|
|
|
24
24
|
// Resolve user PostCSS config from the project root (cwd), not the Eleventy input dir.
|
|
25
25
|
const configRoot = process.cwd();
|
|
26
26
|
|
|
27
|
-
eleventyConfig.addTemplateFormats(
|
|
27
|
+
eleventyConfig.addTemplateFormats('css');
|
|
28
28
|
|
|
29
|
-
eleventyConfig.addExtension(
|
|
30
|
-
outputFileExtension:
|
|
29
|
+
eleventyConfig.addExtension('css', {
|
|
30
|
+
outputFileExtension: 'css',
|
|
31
31
|
useLayouts: false,
|
|
32
32
|
compile: async function (_inputContent, inputPath) {
|
|
33
|
-
if (!inputPath.startsWith(cssDir) || path.basename(inputPath) !==
|
|
33
|
+
if (!inputPath.startsWith(cssDir) || path.basename(inputPath) !== 'index.css') {
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
36
|
|
|
@@ -41,9 +41,9 @@ export default function assetsPostCSS(eleventyConfig) {
|
|
|
41
41
|
try {
|
|
42
42
|
// Prefer the consuming project's PostCSS config (postcss.config.* or package.json#postcss).
|
|
43
43
|
({ plugins, options } = await loadPostCSSConfig({}, configRoot));
|
|
44
|
-
} catch
|
|
44
|
+
} catch {
|
|
45
45
|
// If none is found, fall back to the bundled Baseline config to keep builds working.
|
|
46
|
-
({plugins, ...options } = fallbackPostCSSConfig);
|
|
46
|
+
({ plugins, ...options } = fallbackPostCSSConfig);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
const result = await postcss(plugins).process(_inputContent, {
|
|
@@ -58,18 +58,18 @@ export default function assetsPostCSS(eleventyConfig) {
|
|
|
58
58
|
});
|
|
59
59
|
|
|
60
60
|
// Filter to inline a bundled entry; supports callback style (Nunjucks/Liquid) and Promise return.
|
|
61
|
-
eleventyConfig.addAsyncFilter(
|
|
62
|
-
const done = typeof callback ===
|
|
61
|
+
eleventyConfig.addAsyncFilter('inlinePostCSS', async function (cssFilePath, callback) {
|
|
62
|
+
const done = typeof callback === 'function' ? callback : null;
|
|
63
63
|
try {
|
|
64
64
|
const css = await inlinePostCSS(cssFilePath);
|
|
65
65
|
const html = `<style>${css}</style>`;
|
|
66
66
|
if (done) return done(null, html);
|
|
67
67
|
return html;
|
|
68
|
-
} catch
|
|
68
|
+
} catch {
|
|
69
69
|
// Keep behavior non-fatal: return a styled error comment instead of throwing.
|
|
70
70
|
const html = `<style>/* Error processing CSS */</style>`;
|
|
71
71
|
if (done) return done(null, html);
|
|
72
72
|
return html;
|
|
73
73
|
}
|
|
74
74
|
});
|
|
75
|
-
}
|
|
75
|
+
}
|
|
@@ -6,143 +6,127 @@
|
|
|
6
6
|
// Original: https://github.com/posthtml/posthtml-head-elements
|
|
7
7
|
// Adapted for Baseline head-core.
|
|
8
8
|
|
|
9
|
-
import util from
|
|
10
|
-
import { createRequire } from
|
|
9
|
+
import util from 'node:util';
|
|
10
|
+
import { createRequire } from 'node:module';
|
|
11
11
|
|
|
12
12
|
const require = createRequire(import.meta.url);
|
|
13
13
|
|
|
14
14
|
function nonString(type, attrsArr) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
return attrsArr.map(function (attrs) {
|
|
16
|
+
return { tag: type, attrs: attrs };
|
|
17
|
+
});
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
function nonArray(type, content) {
|
|
21
|
-
|
|
21
|
+
return { tag: type, content: [content] };
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
function findElmType(type, objectData) {
|
|
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
|
-
'default': function() {
|
|
95
|
-
util.log('posthtml-head-elements: Please make sure the HTML head type is correct');
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
if (type.indexOf('_') !== -1) {
|
|
100
|
-
type = type.substr(0, type.indexOf('_'));
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return (elementType[type]() || elementType['default']());
|
|
25
|
+
var elementType = {
|
|
26
|
+
meta: function () {
|
|
27
|
+
if (Array.isArray(objectData)) {
|
|
28
|
+
return nonString(type, objectData);
|
|
29
|
+
} else {
|
|
30
|
+
util.log('posthtml-head-elements: Please use the correct syntax for a meta element');
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
title: function () {
|
|
34
|
+
if (typeof objectData === 'string') {
|
|
35
|
+
return nonArray('title', objectData);
|
|
36
|
+
} else {
|
|
37
|
+
util.log('posthtml-head-elements: Please use the correct syntax for a title element');
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
link: function () {
|
|
41
|
+
if (Array.isArray(objectData)) {
|
|
42
|
+
return nonString(type, objectData);
|
|
43
|
+
} else {
|
|
44
|
+
util.log('posthtml-head-elements: Please use the correct syntax for a link element');
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
linkCanonical: function () {
|
|
48
|
+
if (Array.isArray(objectData)) {
|
|
49
|
+
return nonString('link', objectData);
|
|
50
|
+
} else {
|
|
51
|
+
util.log('posthtml-head-elements: Please use the correct syntax for a linkCanonical element');
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
script: function () {
|
|
55
|
+
if (Array.isArray(objectData)) {
|
|
56
|
+
return objectData.map(function (entry) {
|
|
57
|
+
const { content, ...attrs } = entry || {};
|
|
58
|
+
return content !== undefined ? { tag: 'script', attrs, content: [content] } : { tag: 'script', attrs };
|
|
59
|
+
});
|
|
60
|
+
} else {
|
|
61
|
+
util.log('posthtml-head-elements: Please use the correct syntax for a script element');
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
style: function () {
|
|
65
|
+
if (Array.isArray(objectData)) {
|
|
66
|
+
return objectData.map(function (entry) {
|
|
67
|
+
const { content, ...attrs } = entry || {};
|
|
68
|
+
return content !== undefined ? { tag: 'style', attrs, content: [content] } : { tag: 'style', attrs };
|
|
69
|
+
});
|
|
70
|
+
} else {
|
|
71
|
+
util.log('posthtml-head-elements: Please use the correct syntax for a style element');
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
base: function () {
|
|
75
|
+
if (Array.isArray(objectData)) {
|
|
76
|
+
return nonString(type, objectData);
|
|
77
|
+
} else {
|
|
78
|
+
util.log('posthtml-head-elements: Please use the correct syntax for a base element');
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
default: function () {
|
|
82
|
+
util.log('posthtml-head-elements: Please make sure the HTML head type is correct');
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
if (type.indexOf('_') !== -1) {
|
|
87
|
+
type = type.substr(0, type.indexOf('_'));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return elementType[type]() || elementType['default']();
|
|
104
91
|
}
|
|
105
92
|
|
|
106
93
|
function buildNewTree(headElements, EOL) {
|
|
94
|
+
var newHeadElements = [];
|
|
107
95
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
newHeadElements.push(findElmType(value, headElements[value]));
|
|
96
|
+
Object.keys(headElements).forEach(function (value) {
|
|
97
|
+
newHeadElements.push(findElmType(value, headElements[value]));
|
|
98
|
+
});
|
|
113
99
|
|
|
114
|
-
|
|
100
|
+
function cnct(arr) {
|
|
101
|
+
return Array.prototype.concat.apply([], arr);
|
|
102
|
+
}
|
|
115
103
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
return [elem, EOL];
|
|
122
|
-
}));
|
|
104
|
+
return cnct(
|
|
105
|
+
cnct(newHeadElements).map(function (elem) {
|
|
106
|
+
return [elem, EOL];
|
|
107
|
+
})
|
|
108
|
+
);
|
|
123
109
|
}
|
|
124
110
|
|
|
125
|
-
export default function(options) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
};
|
|
148
|
-
|
|
111
|
+
export default function (options) {
|
|
112
|
+
options = options || {};
|
|
113
|
+
options.headElementsTag = options.headElementsTag || 'posthtml-head-elements';
|
|
114
|
+
|
|
115
|
+
if (!options.headElements) {
|
|
116
|
+
util.log(
|
|
117
|
+
"posthtml-head-elements: Don't forget to add a link to the JSON file containing the head elements to insert"
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
var jsonOne = typeof options.headElements !== 'string' ? options.headElements : require(options.headElements);
|
|
121
|
+
|
|
122
|
+
return function posthtmlHeadElements(tree) {
|
|
123
|
+
tree.match({ tag: options.headElementsTag }, function () {
|
|
124
|
+
return {
|
|
125
|
+
tag: false, // delete this node, safe content
|
|
126
|
+
content: buildNewTree(jsonOne, options.EOL || '\n')
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
return tree;
|
|
131
|
+
};
|
|
132
|
+
}
|
|
@@ -1,25 +1,24 @@
|
|
|
1
|
-
import headElements from
|
|
2
|
-
import { getVerbose, logIfVerbose } from
|
|
3
|
-
import { buildHead } from
|
|
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
4
|
|
|
5
5
|
/** @param {import("@11ty/eleventy").UserConfig} eleventyConfig */
|
|
6
6
|
export default function headCore(eleventyConfig, options = {}) {
|
|
7
7
|
const verbose = getVerbose(eleventyConfig) || options.verbose || false;
|
|
8
8
|
|
|
9
9
|
// Following options are not public.
|
|
10
|
-
const userKey = options.dirKey ||
|
|
11
|
-
const headElementsTag = options.headElementsTag ||
|
|
12
|
-
const eol = options.EOL ||
|
|
13
|
-
const pathPrefix = options.pathPrefix ?? eleventyConfig?.pathPrefix ??
|
|
10
|
+
const userKey = options.dirKey || 'head';
|
|
11
|
+
const headElementsTag = options.headElementsTag || 'baseline-head';
|
|
12
|
+
const eol = options.EOL || '\n';
|
|
13
|
+
const pathPrefix = options.pathPrefix ?? eleventyConfig?.pathPrefix ?? '';
|
|
14
14
|
const siteUrl = options.siteUrl;
|
|
15
|
-
const inputDir = eleventyConfig.dir?.input || ".";
|
|
16
15
|
|
|
17
16
|
let cachedContentMap = {};
|
|
18
|
-
eleventyConfig.on(
|
|
17
|
+
eleventyConfig.on('eleventy.contentMap', ({ inputPathToUrl, urlToInputPath }) => {
|
|
19
18
|
cachedContentMap = { inputPathToUrl, urlToInputPath };
|
|
20
19
|
});
|
|
21
20
|
|
|
22
|
-
eleventyConfig.addGlobalData(
|
|
21
|
+
eleventyConfig.addGlobalData('eleventyComputed.page.head', () => {
|
|
23
22
|
return (data) =>
|
|
24
23
|
buildHead(data, {
|
|
25
24
|
userKey,
|
|
@@ -27,15 +26,12 @@ export default function headCore(eleventyConfig, options = {}) {
|
|
|
27
26
|
pathPrefix,
|
|
28
27
|
contentMap: cachedContentMap,
|
|
29
28
|
pageUrlOverride: data?.page?.url,
|
|
29
|
+
verbose
|
|
30
30
|
});
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
-
eleventyConfig.htmlTransformer.addPosthtmlPlugin(
|
|
34
|
-
logIfVerbose(
|
|
35
|
-
verbose,
|
|
36
|
-
"head-core: injecting head elements for",
|
|
37
|
-
context?.page?.inputPath || context?.outputPath
|
|
38
|
-
);
|
|
33
|
+
eleventyConfig.htmlTransformer.addPosthtmlPlugin('html', function (context) {
|
|
34
|
+
logIfVerbose(verbose, 'head-core: injecting head elements for', context?.page?.inputPath || context?.outputPath);
|
|
39
35
|
|
|
40
36
|
const headElementsSpec =
|
|
41
37
|
context?.page?.head ||
|
|
@@ -45,12 +41,13 @@ export default function headCore(eleventyConfig, options = {}) {
|
|
|
45
41
|
pathPrefix,
|
|
46
42
|
contentMap: cachedContentMap,
|
|
47
43
|
pageUrlOverride: context?.page?.url,
|
|
44
|
+
verbose
|
|
48
45
|
});
|
|
49
46
|
|
|
50
47
|
const plugin = headElements({
|
|
51
48
|
headElements: headElementsSpec,
|
|
52
49
|
headElementsTag,
|
|
53
|
-
EOL: eol
|
|
50
|
+
EOL: eol
|
|
54
51
|
});
|
|
55
52
|
|
|
56
53
|
return async function asyncHead(tree) {
|