@easy-web/core 1.9.1 → 1.11.0
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 +25 -6
- package/dist/contracts/capabilities.d.ts +3 -0
- package/dist/contracts/capabilities.d.ts.map +1 -1
- package/dist/contracts/content-composition.d.ts +16 -0
- package/dist/contracts/content-composition.d.ts.map +1 -1
- package/dist/contracts/content-composition.js +8 -0
- package/dist/contracts/content-composition.js.map +1 -1
- package/dist/contracts/index.d.ts +1 -0
- package/dist/contracts/index.d.ts.map +1 -1
- package/dist/contracts/index.js +1 -0
- package/dist/contracts/index.js.map +1 -1
- package/dist/contracts/ordering.d.ts +6 -0
- package/dist/contracts/ordering.d.ts.map +1 -0
- package/dist/contracts/ordering.js +22 -0
- package/dist/contracts/ordering.js.map +1 -0
- package/dist/contracts/traits.d.ts +4 -0
- package/dist/contracts/traits.d.ts.map +1 -1
- package/dist/contracts/traits.js +3 -1
- package/dist/contracts/traits.js.map +1 -1
- package/dist/recipes/content-site.d.ts +8 -0
- package/dist/recipes/content-site.d.ts.map +1 -1
- package/dist/recipes/content-site.js +226 -42
- package/dist/recipes/content-site.js.map +1 -1
- package/dist/recipes/shell-recipe.d.ts +4 -0
- package/dist/recipes/shell-recipe.d.ts.map +1 -1
- package/dist/recipes/shell-recipe.js +127 -6
- package/dist/recipes/shell-recipe.js.map +1 -1
- package/dist/seo/index.d.ts +5 -0
- package/dist/seo/index.d.ts.map +1 -1
- package/dist/seo/index.js +7 -3
- package/dist/seo/index.js.map +1 -1
- package/dist/seo/rendered-sitemap-alternates.d.ts +7 -0
- package/dist/seo/rendered-sitemap-alternates.d.ts.map +1 -0
- package/dist/seo/rendered-sitemap-alternates.js +232 -0
- package/dist/seo/rendered-sitemap-alternates.js.map +1 -0
- package/package.json +1 -1
- package/src/contracts/__tests__/content-composition.test.ts +17 -0
- package/src/contracts/__tests__/ordering.test.ts +34 -0
- package/src/contracts/capabilities.ts +4 -0
- package/src/contracts/content-composition.ts +8 -0
- package/src/contracts/index.ts +1 -0
- package/src/contracts/ordering.ts +33 -0
- package/src/contracts/traits.ts +4 -1
- package/src/recipes/__tests__/content-site.test.ts +98 -2
- package/src/recipes/__tests__/shell-recipe.test.ts +23 -0
- package/src/recipes/content-site.ts +227 -48
- package/src/recipes/shell-recipe.ts +132 -6
- package/src/seo/__tests__/integration.test.ts +28 -0
- package/src/seo/__tests__/rendered-sitemap-alternates.test.ts +127 -0
- package/src/seo/__tests__/sitemap-options.test.ts +7 -7
- package/src/seo/index.ts +17 -3
- package/src/seo/rendered-sitemap-alternates.ts +231 -0
- package/src/type-tests/contracts.ts +6 -0
|
@@ -7,6 +7,19 @@ const shellOptionsSchema = z.strictObject({
|
|
|
7
7
|
});
|
|
8
8
|
const PLACEHOLDER_SITE_URL = 'https://replace-with-your-domain.example';
|
|
9
9
|
function astroConfig(options, configuration) {
|
|
10
|
+
const locales = configuration.contentLocales;
|
|
11
|
+
const multilingual = !!locales && locales.length > 1;
|
|
12
|
+
const seoOptions = {
|
|
13
|
+
noIndex: options.noIndex,
|
|
14
|
+
...(multilingual ? {
|
|
15
|
+
sitemapLocales: Object.fromEntries(locales.map((locale) => [locale, locale])),
|
|
16
|
+
localizedPaths: configuration.localizedPaths,
|
|
17
|
+
synchronizeRenderedAlternates: true,
|
|
18
|
+
} : {}),
|
|
19
|
+
};
|
|
20
|
+
const seoConfig = multilingual
|
|
21
|
+
? `easyWebSeo(${JSON.stringify(seoOptions)})`
|
|
22
|
+
: `easyWebSeo({ noIndex: ${options.noIndex ? 'true' : 'false'} })`;
|
|
10
23
|
return `import { defineConfig } from 'astro/config';
|
|
11
24
|
import easyWebSeo from '@easy-web/core/seo';
|
|
12
25
|
${(configuration.imports ?? []).join('\n')}
|
|
@@ -14,8 +27,20 @@ ${(configuration.imports ?? []).join('\n')}
|
|
|
14
27
|
export default defineConfig({
|
|
15
28
|
site: ${JSON.stringify(PLACEHOLDER_SITE_URL)},
|
|
16
29
|
${configuration.markdownProcessor ? `markdown: { processor: ${configuration.markdownProcessor} },` : ''}
|
|
30
|
+
${multilingual ? `i18n: { defaultLocale: ${JSON.stringify(options.defaultLocale)}, locales: ${JSON.stringify(locales)} },` : ''}
|
|
17
31
|
integrations: [
|
|
18
|
-
|
|
32
|
+
${seoConfig},
|
|
33
|
+
${configuration.publicationGating ? `{
|
|
34
|
+
name: 'easy-web-publication-instant',
|
|
35
|
+
hooks: {
|
|
36
|
+
'astro:config:setup': ({ command, updateConfig }) => {
|
|
37
|
+
// A build-time literal is shared by all prerender bundles and workers.
|
|
38
|
+
updateConfig({
|
|
39
|
+
vite: { define: { 'import.meta.env.EASY_WEB_PUBLICATION_INSTANT': JSON.stringify(command === 'build' ? Date.now() : null) } },
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
},` : ''}
|
|
19
44
|
${(configuration.integrations ?? []).map((integration) => `${integration},`).join('\n ')}
|
|
20
45
|
],
|
|
21
46
|
});
|
|
@@ -31,7 +56,67 @@ const pnpmWorkspace = `allowBuilds:
|
|
|
31
56
|
esbuild: true
|
|
32
57
|
sharp: true
|
|
33
58
|
`;
|
|
34
|
-
function baseLayout(options, navigation) {
|
|
59
|
+
function baseLayout(options, navigation, configuration) {
|
|
60
|
+
const locales = configuration.contentLocales;
|
|
61
|
+
if (locales && locales.length > 1) {
|
|
62
|
+
return `---
|
|
63
|
+
import PageShell from '@easy-web/core/components/PageShell.astro';
|
|
64
|
+
import Header from '@easy-web/core/components/Header.astro';
|
|
65
|
+
import Footer from '@easy-web/core/components/Footer.astro';
|
|
66
|
+
import SeoHead from '@easy-web/core/components/SeoHead.astro';
|
|
67
|
+
import '@easy-web/core/styles/tokens.css';
|
|
68
|
+
|
|
69
|
+
interface Props {
|
|
70
|
+
title: string;
|
|
71
|
+
description?: string;
|
|
72
|
+
image?: string;
|
|
73
|
+
locale?: string;
|
|
74
|
+
basePath?: string;
|
|
75
|
+
alternates?: { hreflang: string; href: string }[];
|
|
76
|
+
alternateHref?: string;
|
|
77
|
+
}
|
|
78
|
+
const { title, description, image, locale = ${JSON.stringify(options.defaultLocale)}, basePath: configuredBasePath, alternates = [], alternateHref } = Astro.props;
|
|
79
|
+
const siteName = ${JSON.stringify(options.siteName)};
|
|
80
|
+
const currentLang = locale;
|
|
81
|
+
const locales = ${JSON.stringify(locales)};
|
|
82
|
+
const navigationByLocale: Record<string, { label: string; href: string }[]> = ${JSON.stringify(configuration.navigationByLocale ?? { [options.defaultLocale]: navigation })};
|
|
83
|
+
const basePath = configuredBasePath ?? import.meta.env.BASE_URL.replace(/\\/$/, '');
|
|
84
|
+
const navItems = (navigationByLocale[currentLang] ?? []).map((item) => ({ ...item, href: basePath + item.href }));
|
|
85
|
+
const languageHref = alternateHref
|
|
86
|
+
? new URL(alternateHref, Astro.site ?? new URL(${JSON.stringify(PLACEHOLDER_SITE_URL)})).pathname
|
|
87
|
+
: undefined;
|
|
88
|
+
---
|
|
89
|
+
<!doctype html>
|
|
90
|
+
<html lang={currentLang}>
|
|
91
|
+
<head>
|
|
92
|
+
<meta charset="utf-8" />
|
|
93
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
94
|
+
<SeoHead title={title} description={description} ogImage={image}
|
|
95
|
+
pathname={Astro.url.pathname} locale={currentLang} siteName={siteName} alternates={alternates} />
|
|
96
|
+
</head>
|
|
97
|
+
<body>
|
|
98
|
+
<PageShell lang={currentLang}>
|
|
99
|
+
<Header
|
|
100
|
+
slot="header"
|
|
101
|
+
lang={currentLang}
|
|
102
|
+
siteName={siteName}
|
|
103
|
+
navItems={navItems}
|
|
104
|
+
currentLang={currentLang}
|
|
105
|
+
pathname={Astro.url.pathname}
|
|
106
|
+
brandHref={basePath + (currentLang === ${JSON.stringify(options.defaultLocale)} ? '/' : '/' + currentLang + '/')}
|
|
107
|
+
alternateHref={languageHref}
|
|
108
|
+
locales={locales}
|
|
109
|
+
/>
|
|
110
|
+
<slot />
|
|
111
|
+
<Footer slot="footer" lang={currentLang} siteName={siteName} legalLinks={[
|
|
112
|
+
{ label: currentLang === 'de' ? 'Impressum (Beispiel)' : 'Imprint (sample)', href: basePath + '/imprint' },
|
|
113
|
+
{ label: currentLang === 'de' ? 'Datenschutz (Beispiel)' : 'Privacy (sample)', href: basePath + '/privacy' },
|
|
114
|
+
]} />
|
|
115
|
+
</PageShell>
|
|
116
|
+
</body>
|
|
117
|
+
</html>
|
|
118
|
+
`;
|
|
119
|
+
}
|
|
35
120
|
return `---
|
|
36
121
|
import PageShell from '@easy-web/core/components/PageShell.astro';
|
|
37
122
|
import Header from '@easy-web/core/components/Header.astro';
|
|
@@ -107,16 +192,52 @@ const gitignore = `node_modules
|
|
|
107
192
|
dist
|
|
108
193
|
.astro
|
|
109
194
|
`;
|
|
195
|
+
function localizedHomePage(options, locale, locales) {
|
|
196
|
+
return `---
|
|
197
|
+
import Base from '${locale === options.defaultLocale ? '../layouts/Base.astro' : '../../layouts/Base.astro'}';
|
|
198
|
+
import { getAlternateLinks, ambientTrailingSlash } from '@easy-web/core/i18n';
|
|
199
|
+
|
|
200
|
+
const localizedPaths = [Object.fromEntries(${JSON.stringify(locales)}.map((itemLocale) => [
|
|
201
|
+
itemLocale, itemLocale === ${JSON.stringify(options.defaultLocale)} ? '/' : '/' + itemLocale + '/',
|
|
202
|
+
]))];
|
|
203
|
+
const routePath = ${JSON.stringify(locale === options.defaultLocale ? '/' : `/${locale}/`)};
|
|
204
|
+
const pagePath = Astro.url.pathname.replace(/\\/+$/, '') || '/';
|
|
205
|
+
const routeWithoutSlash = routePath.replace(/\\/+$/, '') || '/';
|
|
206
|
+
const sitePrefix = routeWithoutSlash === '/' ? (pagePath === '/' ? '' : pagePath)
|
|
207
|
+
: pagePath.endsWith(routeWithoutSlash) ? pagePath.slice(0, -routeWithoutSlash.length) : '';
|
|
208
|
+
const alternates = getAlternateLinks({
|
|
209
|
+
path: routePath, locales: ${JSON.stringify(locales)},
|
|
210
|
+
defaultLocale: ${JSON.stringify(options.defaultLocale)},
|
|
211
|
+
baseUrl: new URL(sitePrefix ? sitePrefix + '/' : '/', Astro.site?.toString() ?? ${JSON.stringify(PLACEHOLDER_SITE_URL)}).toString(),
|
|
212
|
+
localizedPaths,
|
|
213
|
+
trailingSlash: ambientTrailingSlash(),
|
|
214
|
+
});
|
|
215
|
+
const alternateHref = alternates.find(({ hreflang }) => hreflang !== ${JSON.stringify(locale)} && hreflang !== 'x-default')?.href;
|
|
216
|
+
---
|
|
217
|
+
<Base title={${JSON.stringify(options.siteName)}} locale={${JSON.stringify(locale)}} basePath={sitePrefix} alternates={alternates} alternateHref={alternateHref}>
|
|
218
|
+
<h1>${locale === 'de' ? 'Willkommen' : 'Welcome'}</h1>
|
|
219
|
+
<p>${locale === 'de' ? 'Dies ist eine generierte Platzhalter-Startseite. Ersetze diesen Inhalt vor der Veröffentlichung.' : 'This is a generated placeholder home page. Replace this content before production.'}</p>
|
|
220
|
+
</Base>
|
|
221
|
+
`;
|
|
222
|
+
}
|
|
110
223
|
export function buildShellFiles(rawOptions, navigation = [], configuration = {}) {
|
|
111
224
|
const options = shellOptionsSchema.parse(rawOptions ?? {});
|
|
225
|
+
const locales = configuration.contentLocales;
|
|
226
|
+
const multilingual = !!locales && locales.length > 1;
|
|
112
227
|
return [
|
|
113
228
|
{ path: 'astro.config.mjs', content: astroConfig(options, configuration) },
|
|
114
229
|
{ path: 'package.json', content: packageJsonFragment },
|
|
115
230
|
{ path: 'pnpm-workspace.yaml', content: pnpmWorkspace },
|
|
116
|
-
{ path: 'src/layouts/Base.astro', content: baseLayout(options, navigation) },
|
|
117
|
-
{ path: 'src/pages/index.astro', content: homePage(options) },
|
|
231
|
+
{ path: 'src/layouts/Base.astro', content: baseLayout(options, navigation, configuration) },
|
|
232
|
+
{ path: 'src/pages/index.astro', content: multilingual ? localizedHomePage(options, options.defaultLocale, locales) : homePage(options) },
|
|
233
|
+
...(multilingual ? locales.slice(1).map((locale) => ({
|
|
234
|
+
path: `src/pages/${locale}/index.astro`,
|
|
235
|
+
content: localizedHomePage(options, locale, locales),
|
|
236
|
+
})) : []),
|
|
118
237
|
{ path: 'src/pages/404.astro', content: notFoundPage(options) },
|
|
119
|
-
{ path: 'src/lib/localized-paths.ts', content:
|
|
238
|
+
{ path: 'src/lib/localized-paths.ts', content: multilingual
|
|
239
|
+
? `import type { LocalizedPathGroup } from '@easy-web/core/i18n';\n\nexport const localizedPaths: readonly LocalizedPathGroup[] = ${JSON.stringify(configuration.localizedPaths ?? [], null, 2)};\n`
|
|
240
|
+
: localizedPaths },
|
|
120
241
|
{ path: 'tsconfig.json', content: `${JSON.stringify({ extends: 'astro/tsconfigs/strict', include: ['.astro/types.d.ts', '**/*'], exclude: ['dist'] }, null, 2)}\n` },
|
|
121
242
|
{ path: '.gitignore', content: gitignore },
|
|
122
243
|
];
|
|
@@ -125,7 +246,7 @@ export const shellRecipe = {
|
|
|
125
246
|
id: SHELL_RECIPE_ID,
|
|
126
247
|
version: '1.5.0',
|
|
127
248
|
protocolVersion: 1,
|
|
128
|
-
compatibleCliRange: '^0.1.0 || ^0.2.0',
|
|
249
|
+
compatibleCliRange: '^0.1.0 || ^0.2.0 || ^0.3.0',
|
|
129
250
|
compatibleRuntimeRange: '^1.5.0',
|
|
130
251
|
provides: [SHELL_RECIPE_ID],
|
|
131
252
|
requires: [],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shell-recipe.js","sourceRoot":"","sources":["../../src/recipes/shell-recipe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,WAAW,CAAC;AAI9B,MAAM,CAAC,MAAM,eAAe,GAAG,YAAY,CAAC;AAE5C,MAAM,kBAAkB,GAAG,CAAC,CAAC,YAAY,CAAC;IACtC,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC;IACnD,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE,C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,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,EAAE;QAChD,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE;QAClD,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,uBAAuB,EAAE,MAAM,EAAE,4BAA4B,EAAE;QACnF,EAAE,IAAI,EAAE,eAAe,EAAE,EAAE,EAAE,gBAAgB,EAAE,MAAM,EAAE,eAAe,EAAE;QACxE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,EAAE,YAAY,EAAE;KAChE;IACD,UAAU,EAAE,EAAE;IACd,QAAQ,EAAE,CAAC,OAA8B,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;CACjD,CAAC;AAE/C,eAAe,WAAW,CAAC"}
|
package/dist/seo/index.d.ts
CHANGED
|
@@ -20,6 +20,11 @@ export type Options = {
|
|
|
20
20
|
* A stale or misspelled entry fails the build rather than degrading quietly.
|
|
21
21
|
*/
|
|
22
22
|
localizedPaths?: readonly LocalizedPathGroup[];
|
|
23
|
+
/**
|
|
24
|
+
* Reconcile sitemap alternates with rendered canonical/hreflang links after
|
|
25
|
+
* build. Intended for generated content whose translated slugs are CMS-owned.
|
|
26
|
+
*/
|
|
27
|
+
synchronizeRenderedAlternates?: boolean;
|
|
23
28
|
/** Composed with the built-in crawl policy using AND semantics; cannot re-admit blocked paths. */
|
|
24
29
|
filter?: (page: string) => boolean;
|
|
25
30
|
};
|
package/dist/seo/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/seo/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,gBAAgB,EAAE,MAAM,OAAO,CAAA;AAE1D,OAAO,EAIL,KAAK,kBAAkB,EAExB,MAAM,kBAAkB,CAAA;AAIzB,OAAO,EAA8C,KAAK,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/seo/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,gBAAgB,EAAE,MAAM,OAAO,CAAA;AAE1D,OAAO,EAIL,KAAK,kBAAkB,EAExB,MAAM,kBAAkB,CAAA;AAIzB,OAAO,EAA8C,KAAK,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAG5G,YAAY,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAEvG,YAAY,EAAE,kBAAkB,EAAE,CAAA;AAElC,MAAM,MAAM,OAAO,GAAG;IACpB,wFAAwF;IACxF,QAAQ,CAAC,SAAS,CAAC,EAAE,gBAAgB,CAAA;IACrC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACvC;;;;;;;;;;OAUG;IACH,cAAc,CAAC,EAAE,SAAS,kBAAkB,EAAE,CAAA;IAC9C;;;OAGG;IACH,6BAA6B,CAAC,EAAE,OAAO,CAAA;IACvC,kGAAkG;IAClG,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAA;CACnC,CAAA;AA8DD,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,OAAO,GAAE,OAAY,GAAG,gBAAgB,CAyL1E;AAED,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAA"}
|
package/dist/seo/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import { normalizeLocalizedPath, toServedPath, validateLocalizedPaths, } from '.
|
|
|
3
3
|
import { createCrawlPolicy, isDisallowedPath } from './crawl-policy.js';
|
|
4
4
|
import { buildInfoManifest } from './build-info.js';
|
|
5
5
|
import { buildInfoOptionsSchema, serializeBuildInfo } from './build-info-manifest.js';
|
|
6
|
+
import { synchronizeRenderedSitemapAlternates } from './rendered-sitemap-alternates.js';
|
|
6
7
|
function localeIdsOf(config) {
|
|
7
8
|
return (config.i18n?.locales ?? []).map((locale) => typeof locale === 'string' ? locale : locale.path);
|
|
8
9
|
}
|
|
@@ -83,8 +84,8 @@ export default function easyWebSeo(options = {}) {
|
|
|
83
84
|
};
|
|
84
85
|
}
|
|
85
86
|
const declaredGroups = options.localizedPaths ?? [];
|
|
86
|
-
if (declaredGroups.length > 0 && !sitemapI18n) {
|
|
87
|
-
throw new Error('@easy-web/seo:
|
|
87
|
+
if ((declaredGroups.length > 0 || options.synchronizeRenderedAlternates) && !sitemapI18n) {
|
|
88
|
+
throw new Error('@easy-web/seo: localized alternates require `i18n` to be configured in astro.config.mjs.');
|
|
88
89
|
}
|
|
89
90
|
const localeIds = localeIdsOf(config);
|
|
90
91
|
const problems = validateLocalizedPaths(declaredGroups, localeIds);
|
|
@@ -152,7 +153,7 @@ export default function easyWebSeo(options = {}) {
|
|
|
152
153
|
const validatorIntegration = {
|
|
153
154
|
name: '@easy-web/seo:localized-paths-validation',
|
|
154
155
|
hooks: {
|
|
155
|
-
'astro:build:done': () => {
|
|
156
|
+
'astro:build:done': async ({ dir }) => {
|
|
156
157
|
const missing = [...declaredUrls].filter((url) => !seenUrls.has(url));
|
|
157
158
|
const failures = [
|
|
158
159
|
...missing.map((url) => `${url} is declared in localizedPaths but no such page was built. Check for a typo or a removed route.`),
|
|
@@ -161,6 +162,9 @@ export default function easyWebSeo(options = {}) {
|
|
|
161
162
|
if (failures.length > 0) {
|
|
162
163
|
throw new Error(`@easy-web/seo: invalid \`localizedPaths\`:\n- ${failures.join('\n- ')}`);
|
|
163
164
|
}
|
|
165
|
+
if (options.synchronizeRenderedAlternates) {
|
|
166
|
+
await synchronizeRenderedSitemapAlternates(dir, config, localeIds, config.i18n.defaultLocale);
|
|
167
|
+
}
|
|
164
168
|
},
|
|
165
169
|
},
|
|
166
170
|
};
|
package/dist/seo/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/seo/index.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,kBAAkB,CAAA;AACtC,OAAO,EACL,sBAAsB,EACtB,YAAY,EACZ,sBAAsB,GAGvB,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACvE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAyB,MAAM,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/seo/index.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,kBAAkB,CAAA;AACtC,OAAO,EACL,sBAAsB,EACtB,YAAY,EACZ,sBAAsB,GAGvB,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACvE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAyB,MAAM,0BAA0B,CAAA;AAC5G,OAAO,EAAE,oCAAoC,EAAE,MAAM,kCAAkC,CAAA;AAmCvF,SAAS,WAAW,CAAC,MAAmB;IACtC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CACjD,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAClD,CAAA;AACH,CAAC;AAED,SAAS,oBAAoB,CAC3B,MAAmB,EACnB,MAAwC;IAExC,8EAA8E;IAC9E,8EAA8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BAAiB,EAAE,gBAAgB,EAAoB,MAAM,mBAAmB,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AstroConfig } from 'astro';
|
|
2
|
+
/**
|
|
3
|
+
* Reconciles sitemap alternates with rendered pages only when explicitly enabled.
|
|
4
|
+
* Rendered head links are validated against built canonicals before changing XML.
|
|
5
|
+
*/
|
|
6
|
+
export declare function synchronizeRenderedSitemapAlternates(outputDirectory: URL, config: AstroConfig, locales: readonly string[], defaultLocale: string): Promise<void>;
|
|
7
|
+
//# sourceMappingURL=rendered-sitemap-alternates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rendered-sitemap-alternates.d.ts","sourceRoot":"","sources":["../../src/seo/rendered-sitemap-alternates.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAsHzC;;;GAGG;AACH,wBAAsB,oCAAoC,CACtD,eAAe,EAAE,GAAG,EACpB,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,aAAa,EAAE,MAAM,GACtB,OAAO,CAAC,IAAI,CAAC,CAoGf"}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { readdir, readFile, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { join, relative, sep } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { normalizeLocalizedPath, toServedPath } from '../i18n/index.js';
|
|
5
|
+
function decodeHtml(value) {
|
|
6
|
+
return value.replaceAll('&', '&').replaceAll('"', '"').replaceAll(''', "'").replaceAll('<', '<').replaceAll('>', '>');
|
|
7
|
+
}
|
|
8
|
+
function decodeXml(value) {
|
|
9
|
+
return decodeHtml(value);
|
|
10
|
+
}
|
|
11
|
+
function escapeXml(value) {
|
|
12
|
+
return value.replaceAll('&', '&').replaceAll('"', '"').replaceAll('<', '<').replaceAll('>', '>');
|
|
13
|
+
}
|
|
14
|
+
function attributes(tag) {
|
|
15
|
+
const values = new Map();
|
|
16
|
+
for (const match of tag.matchAll(/([^\s=]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g)) {
|
|
17
|
+
values.set(match[1].toLowerCase(), decodeHtml(match[2] ?? match[3] ?? ''));
|
|
18
|
+
}
|
|
19
|
+
return values;
|
|
20
|
+
}
|
|
21
|
+
function canonicalOf(html) {
|
|
22
|
+
let canonical;
|
|
23
|
+
for (const tag of html.matchAll(/<link\b[^>]*>/gi)) {
|
|
24
|
+
const attrs = attributes(tag[0]);
|
|
25
|
+
if (attrs.get('rel')?.toLowerCase() !== 'canonical')
|
|
26
|
+
continue;
|
|
27
|
+
const href = attrs.get('href');
|
|
28
|
+
if (!href)
|
|
29
|
+
throw new Error('Rendered canonical link is missing href');
|
|
30
|
+
if (canonical)
|
|
31
|
+
throw new Error('Rendered HTML page has multiple canonical links');
|
|
32
|
+
canonical = href;
|
|
33
|
+
}
|
|
34
|
+
return canonical;
|
|
35
|
+
}
|
|
36
|
+
function renderedAlternates(html) {
|
|
37
|
+
const alternates = new Map();
|
|
38
|
+
for (const tag of html.matchAll(/<link\b[^>]*>/gi)) {
|
|
39
|
+
const attrs = attributes(tag[0]);
|
|
40
|
+
if (attrs.get('rel')?.toLowerCase() !== 'alternate')
|
|
41
|
+
continue;
|
|
42
|
+
const language = attrs.get('hreflang');
|
|
43
|
+
const href = attrs.get('href');
|
|
44
|
+
if (!language || !href)
|
|
45
|
+
continue;
|
|
46
|
+
if (alternates.has(language))
|
|
47
|
+
throw new Error(`Duplicate rendered hreflang "${language}"`);
|
|
48
|
+
alternates.set(language, href);
|
|
49
|
+
}
|
|
50
|
+
return alternates;
|
|
51
|
+
}
|
|
52
|
+
async function htmlFiles(directory, parent = '') {
|
|
53
|
+
const files = [];
|
|
54
|
+
for (const entry of await readdir(join(directory, parent), { withFileTypes: true })) {
|
|
55
|
+
const path = parent ? `${parent}${sep}${entry.name}` : entry.name;
|
|
56
|
+
if (entry.isDirectory())
|
|
57
|
+
files.push(...await htmlFiles(directory, path));
|
|
58
|
+
else if (entry.isFile() && entry.name.endsWith('.html'))
|
|
59
|
+
files.push(path);
|
|
60
|
+
}
|
|
61
|
+
return files;
|
|
62
|
+
}
|
|
63
|
+
function absoluteUrl(value, config, label) {
|
|
64
|
+
const site = new URL(config.site);
|
|
65
|
+
const url = new URL(value, site);
|
|
66
|
+
if (url.origin !== site.origin)
|
|
67
|
+
throw new Error(`${label} must use the configured site origin: ${value}`);
|
|
68
|
+
if (url.username || url.password || url.search || url.hash) {
|
|
69
|
+
throw new Error(`${label} must not contain credentials, a query string or a fragment: ${value}`);
|
|
70
|
+
}
|
|
71
|
+
const base = normalizeLocalizedPath(config.base);
|
|
72
|
+
if (base !== '/' && url.pathname !== base && !url.pathname.startsWith(`${base}/`)) {
|
|
73
|
+
throw new Error(`${label} is outside the configured base path "${base}": ${value}`);
|
|
74
|
+
}
|
|
75
|
+
return url;
|
|
76
|
+
}
|
|
77
|
+
function servedUrlForHtml(file, config) {
|
|
78
|
+
const segments = file.split(sep);
|
|
79
|
+
const last = segments.at(-1);
|
|
80
|
+
if (last === 'index.html')
|
|
81
|
+
segments.pop();
|
|
82
|
+
else if (last.endsWith('.html'))
|
|
83
|
+
segments[segments.length - 1] = last.slice(0, -5);
|
|
84
|
+
const route = normalizeLocalizedPath(segments.join('/'));
|
|
85
|
+
const base = normalizeLocalizedPath(config.base);
|
|
86
|
+
const withoutPhysicalBase = base !== '/' && (route === base || route.startsWith(`${base}/`))
|
|
87
|
+
? route.slice(base.length) || '/'
|
|
88
|
+
: route;
|
|
89
|
+
const pathname = `${base === '/' ? '' : base}${withoutPhysicalBase}`;
|
|
90
|
+
const style = config.trailingSlash === 'never'
|
|
91
|
+
|| (config.trailingSlash === 'ignore' && config.build.format === 'file')
|
|
92
|
+
? 'never'
|
|
93
|
+
: 'always';
|
|
94
|
+
const site = new URL(config.site);
|
|
95
|
+
return new URL(toServedPath(pathname, style), site).href;
|
|
96
|
+
}
|
|
97
|
+
function localeFromHtml(html, file) {
|
|
98
|
+
const tag = /<html\b[^>]*>/i.exec(html)?.[0];
|
|
99
|
+
const locale = tag ? attributes(tag).get('lang') : undefined;
|
|
100
|
+
if (!locale)
|
|
101
|
+
throw new Error(`Rendered HTML page is missing <html lang>: ${file}`);
|
|
102
|
+
return locale;
|
|
103
|
+
}
|
|
104
|
+
function sitemapUrlBlocks(xml, file) {
|
|
105
|
+
const blocks = new Map();
|
|
106
|
+
for (const match of xml.matchAll(/<url\b[^>]*>[\s\S]*?<\/url>/g)) {
|
|
107
|
+
const location = /<loc>([\s\S]*?)<\/loc>/.exec(match[0])?.[1];
|
|
108
|
+
if (!location)
|
|
109
|
+
throw new Error(`Sitemap entry in ${file} is missing <loc>`);
|
|
110
|
+
const url = decodeXml(location.trim());
|
|
111
|
+
if (blocks.has(url))
|
|
112
|
+
throw new Error(`Duplicate sitemap URL: ${url}`);
|
|
113
|
+
blocks.set(url, match[0]);
|
|
114
|
+
}
|
|
115
|
+
return blocks;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Reconciles sitemap alternates with rendered pages only when explicitly enabled.
|
|
119
|
+
* Rendered head links are validated against built canonicals before changing XML.
|
|
120
|
+
*/
|
|
121
|
+
export async function synchronizeRenderedSitemapAlternates(outputDirectory, config, locales, defaultLocale) {
|
|
122
|
+
const root = fileURLToPath(outputDirectory);
|
|
123
|
+
const pages = new Map();
|
|
124
|
+
for (const file of await htmlFiles(root)) {
|
|
125
|
+
const html = await readFile(join(root, file), 'utf8');
|
|
126
|
+
const canonical = canonicalOf(html);
|
|
127
|
+
if (!canonical)
|
|
128
|
+
continue;
|
|
129
|
+
const url = absoluteUrl(canonical, config, `Canonical in ${file}`).href;
|
|
130
|
+
const expected = servedUrlForHtml(relative(root, join(root, file)), config);
|
|
131
|
+
if (url !== expected)
|
|
132
|
+
throw new Error(`Rendered canonical does not match built page ${file}: expected ${expected}, got ${url}`);
|
|
133
|
+
const page = { url, locale: localeFromHtml(html, file), alternates: renderedAlternates(html) };
|
|
134
|
+
if (pages.has(url))
|
|
135
|
+
throw new Error(`Multiple built HTML files share the canonical URL: ${url}`);
|
|
136
|
+
pages.set(url, page);
|
|
137
|
+
}
|
|
138
|
+
const groups = new Map();
|
|
139
|
+
for (const page of pages.values()) {
|
|
140
|
+
const declared = [...page.alternates].filter(([lang]) => lang !== 'x-default');
|
|
141
|
+
if (declared.length === 1) {
|
|
142
|
+
throw new Error(`Rendered alternates for ${page.url} must include at least two locales`);
|
|
143
|
+
}
|
|
144
|
+
if (declared.length < 2)
|
|
145
|
+
continue;
|
|
146
|
+
if (!locales.includes(page.locale))
|
|
147
|
+
throw new Error(`Rendered page ${page.url} has unconfigured lang="${page.locale}"`);
|
|
148
|
+
const links = declared.map(([lang, href]) => {
|
|
149
|
+
if (!locales.includes(lang))
|
|
150
|
+
throw new Error(`Rendered hreflang "${lang}" on ${page.url} is not a configured locale`);
|
|
151
|
+
const target = absoluteUrl(href, config, `Rendered hreflang "${lang}" on ${page.url}`).href;
|
|
152
|
+
const targetPage = pages.get(target);
|
|
153
|
+
if (!targetPage)
|
|
154
|
+
throw new Error(`Rendered hreflang "${lang}" points to no built canonical page: ${target}`);
|
|
155
|
+
if (targetPage.locale !== lang)
|
|
156
|
+
throw new Error(`Rendered hreflang "${lang}" points to a page with lang="${targetPage.locale}": ${target}`);
|
|
157
|
+
return { lang, href: target };
|
|
158
|
+
});
|
|
159
|
+
if (!links.some(({ lang }) => lang === page.locale)) {
|
|
160
|
+
throw new Error(`Rendered alternates for ${page.url} omit its own locale "${page.locale}"`);
|
|
161
|
+
}
|
|
162
|
+
if (links.find(({ lang }) => lang === page.locale)?.href !== page.url) {
|
|
163
|
+
throw new Error(`Rendered hreflang "${page.locale}" must point to its own canonical URL: ${page.url}`);
|
|
164
|
+
}
|
|
165
|
+
for (const link of links) {
|
|
166
|
+
const targetPage = pages.get(link.href);
|
|
167
|
+
if (targetPage.alternates.get(page.locale) !== page.url) {
|
|
168
|
+
throw new Error(`Rendered hreflang group is not reciprocal between ${page.url} and ${link.href}`);
|
|
169
|
+
}
|
|
170
|
+
const targetAlternates = [...targetPage.alternates].filter(([lang]) => lang !== 'x-default');
|
|
171
|
+
if (targetAlternates.length !== links.length
|
|
172
|
+
|| links.some(({ lang, href }) => targetPage.alternates.get(lang) !== href)) {
|
|
173
|
+
throw new Error(`Rendered hreflang group is inconsistent between ${page.url} and ${link.href}`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const defaultHref = page.alternates.get('x-default');
|
|
177
|
+
if (defaultHref) {
|
|
178
|
+
const target = absoluteUrl(defaultHref, config, 'Rendered x-default alternate').href;
|
|
179
|
+
const targetPage = pages.get(target);
|
|
180
|
+
if (!targetPage || targetPage.locale !== defaultLocale) {
|
|
181
|
+
throw new Error(`Rendered x-default must point to a built ${defaultLocale} page: ${target}`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
groups.set(page.url, links);
|
|
185
|
+
}
|
|
186
|
+
const files = (await readdir(root, { withFileTypes: true }))
|
|
187
|
+
.filter((entry) => entry.isFile() && /^sitemap-\d+\.xml$/.test(entry.name))
|
|
188
|
+
.map((entry) => entry.name);
|
|
189
|
+
if (files.length === 0) {
|
|
190
|
+
if (groups.size > 0)
|
|
191
|
+
throw new Error('Rendered hreflang groups exist but no numbered sitemap was built');
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
const sitemapLocations = new Set();
|
|
195
|
+
const sitemapBlocks = new Map();
|
|
196
|
+
for (const file of files) {
|
|
197
|
+
const xml = await readFile(join(root, file), 'utf8');
|
|
198
|
+
const blocks = sitemapUrlBlocks(xml, file);
|
|
199
|
+
for (const url of blocks.keys()) {
|
|
200
|
+
if (sitemapLocations.has(url))
|
|
201
|
+
throw new Error(`Sitemap URL appears more than once: ${url}`);
|
|
202
|
+
sitemapLocations.add(url);
|
|
203
|
+
}
|
|
204
|
+
sitemapBlocks.set(file, blocks);
|
|
205
|
+
}
|
|
206
|
+
for (const [url, links] of groups) {
|
|
207
|
+
if (!sitemapLocations.has(url))
|
|
208
|
+
throw new Error(`Rendered alternate page is excluded from the sitemap: ${url}`);
|
|
209
|
+
for (const link of links) {
|
|
210
|
+
if (!sitemapLocations.has(link.href))
|
|
211
|
+
throw new Error(`Rendered alternate target is excluded from the sitemap: ${link.href}`);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
for (const file of files) {
|
|
215
|
+
const path = join(root, file);
|
|
216
|
+
let xml = await readFile(path, 'utf8');
|
|
217
|
+
const blocks = sitemapBlocks.get(file);
|
|
218
|
+
for (const [url, existing] of blocks) {
|
|
219
|
+
if (!pages.has(url))
|
|
220
|
+
continue;
|
|
221
|
+
const replaced = existing.replace(/<xhtml:link\b[^>]*\/>/g, '');
|
|
222
|
+
const tags = (groups.get(url) ?? []).map(({ lang, href }) => `<xhtml:link rel="alternate" hreflang="${escapeXml(lang)}" href="${escapeXml(href)}"/>`).join('');
|
|
223
|
+
const updated = replaced.replace('</url>', `${tags}</url>`);
|
|
224
|
+
xml = xml.replace(existing, updated);
|
|
225
|
+
blocks.set(url, updated);
|
|
226
|
+
if (!xml.includes(escapeXml(url)))
|
|
227
|
+
throw new Error(`Updated sitemap no longer contains ${url}`);
|
|
228
|
+
}
|
|
229
|
+
await writeFile(path, xml);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
//# sourceMappingURL=rendered-sitemap-alternates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rendered-sitemap-alternates.js","sourceRoot":"","sources":["../../src/seo/rendered-sitemap-alternates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AA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C/B,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -4,6 +4,8 @@ import {
|
|
|
4
4
|
contentCompositionSchema,
|
|
5
5
|
contentTypeDefinitionSchema,
|
|
6
6
|
moneyTraitSchema,
|
|
7
|
+
optionalOrderTraitSchema,
|
|
8
|
+
orderTraitSchema,
|
|
7
9
|
presentationBindings,
|
|
8
10
|
} from '../index.js';
|
|
9
11
|
|
|
@@ -156,6 +158,21 @@ describe('content trait data schemas', () => {
|
|
|
156
158
|
expect(unselected.success).toBe(false);
|
|
157
159
|
});
|
|
158
160
|
|
|
161
|
+
it('keeps the published order trait required and exposes a finite optional entry shape', () => {
|
|
162
|
+
// Given / When
|
|
163
|
+
const valid = [-12, 0, 24].map((order) => optionalOrderTraitSchema.safeParse({ order }));
|
|
164
|
+
const invalidValues: readonly unknown[] = [NaN, Infinity, -Infinity, 1.5, '2'];
|
|
165
|
+
|
|
166
|
+
// Then
|
|
167
|
+
expect(orderTraitSchema.safeParse({}).success).toBe(false);
|
|
168
|
+
expect(orderTraitSchema.parse({ order: -12 })).toEqual({ order: -12 });
|
|
169
|
+
expect(optionalOrderTraitSchema.parse({})).toEqual({});
|
|
170
|
+
expect(valid.every((result) => result.success)).toBe(true);
|
|
171
|
+
expect(invalidValues.every((order) => !optionalOrderTraitSchema.safeParse({ order }).success)).toBe(true);
|
|
172
|
+
expect(invalidValues.every((order) => !orderTraitSchema.safeParse({ order }).success)).toBe(true);
|
|
173
|
+
expect(composeContentTraitSchema(['order']).safeParse({}).success).toBe(false);
|
|
174
|
+
});
|
|
175
|
+
|
|
159
176
|
it.each([
|
|
160
177
|
['EUR', true],
|
|
161
178
|
['usd', false],
|