@easy-web/core 1.5.0 → 1.7.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 +100 -2
- package/dist/contracts/capabilities.d.ts +38 -0
- package/dist/contracts/capabilities.d.ts.map +1 -1
- package/dist/contracts/content-composition.d.ts +144 -0
- package/dist/contracts/content-composition.d.ts.map +1 -0
- package/dist/contracts/content-composition.js +143 -0
- package/dist/contracts/content-composition.js.map +1 -0
- package/dist/contracts/index.d.ts +2 -0
- package/dist/contracts/index.d.ts.map +1 -1
- package/dist/contracts/index.js +2 -0
- package/dist/contracts/index.js.map +1 -1
- package/dist/contracts/traits.d.ts +98 -0
- package/dist/contracts/traits.d.ts.map +1 -0
- package/dist/contracts/traits.js +84 -0
- package/dist/contracts/traits.js.map +1 -0
- package/dist/demo/demo-content.d.ts +37 -0
- package/dist/demo/demo-content.d.ts.map +1 -0
- package/dist/demo/demo-content.js +171 -0
- package/dist/demo/demo-content.js.map +1 -0
- package/dist/demo/index.d.ts +3 -0
- package/dist/demo/index.d.ts.map +1 -0
- package/dist/demo/index.js +3 -0
- package/dist/demo/index.js.map +1 -0
- package/dist/demo/legal-shells.d.ts +18 -0
- package/dist/demo/legal-shells.d.ts.map +1 -0
- package/dist/demo/legal-shells.js +40 -0
- package/dist/demo/legal-shells.js.map +1 -0
- package/dist/i18n/cli-catalogs.d.ts +42 -0
- package/dist/i18n/cli-catalogs.d.ts.map +1 -0
- package/dist/i18n/cli-catalogs.js +29 -0
- package/dist/i18n/cli-catalogs.js.map +1 -0
- package/dist/i18n/create-localization.d.ts +37 -0
- package/dist/i18n/create-localization.d.ts.map +1 -0
- package/dist/i18n/create-localization.js +68 -0
- package/dist/i18n/create-localization.js.map +1 -0
- package/dist/i18n/explicit-formatters.d.ts +20 -0
- package/dist/i18n/explicit-formatters.d.ts.map +1 -0
- package/dist/i18n/explicit-formatters.js +18 -0
- package/dist/i18n/explicit-formatters.js.map +1 -0
- package/dist/i18n/index.d.ts +4 -0
- package/dist/i18n/index.d.ts.map +1 -1
- package/dist/i18n/index.js +4 -0
- package/dist/i18n/index.js.map +1 -1
- package/dist/i18n/locale-inputs.d.ts +18 -0
- package/dist/i18n/locale-inputs.d.ts.map +1 -0
- package/dist/i18n/locale-inputs.js +73 -0
- package/dist/i18n/locale-inputs.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/recipes/admission.d.ts +161 -0
- package/dist/recipes/admission.d.ts.map +1 -0
- package/dist/recipes/admission.js +85 -0
- package/dist/recipes/admission.js.map +1 -0
- package/dist/recipes/graph.d.ts +101 -0
- package/dist/recipes/graph.d.ts.map +1 -0
- package/dist/recipes/graph.js +166 -0
- package/dist/recipes/graph.js.map +1 -0
- package/dist/recipes/index.d.ts +9 -0
- package/dist/recipes/index.d.ts.map +1 -0
- package/dist/recipes/index.js +9 -0
- package/dist/recipes/index.js.map +1 -0
- package/dist/recipes/mermaid.d.ts +3 -0
- package/dist/recipes/mermaid.d.ts.map +1 -0
- package/dist/recipes/mermaid.js +79 -0
- package/dist/recipes/mermaid.js.map +1 -0
- package/dist/recipes/registry.d.ts +82 -0
- package/dist/recipes/registry.d.ts.map +1 -0
- package/dist/recipes/registry.js +40 -0
- package/dist/recipes/registry.js.map +1 -0
- package/dist/recipes/schema.d.ts +129 -0
- package/dist/recipes/schema.d.ts.map +1 -0
- package/dist/recipes/schema.js +41 -0
- package/dist/recipes/schema.js.map +1 -0
- package/dist/recipes/serialize.d.ts +20 -0
- package/dist/recipes/serialize.d.ts.map +1 -0
- package/dist/recipes/serialize.js +56 -0
- package/dist/recipes/serialize.js.map +1 -0
- package/dist/recipes/shell-recipe.d.ts +59 -0
- package/dist/recipes/shell-recipe.d.ts.map +1 -0
- package/dist/recipes/shell-recipe.js +145 -0
- package/dist/recipes/shell-recipe.js.map +1 -0
- package/dist/recipes/types.d.ts +72 -0
- package/dist/recipes/types.d.ts.map +1 -0
- package/dist/recipes/types.js +13 -0
- package/dist/recipes/types.js.map +1 -0
- package/dist/schemas/galleries.d.ts +2 -2
- package/dist/seo/build-info-manifest.d.ts +45 -0
- package/dist/seo/build-info-manifest.d.ts.map +1 -0
- package/dist/seo/build-info-manifest.js +39 -0
- package/dist/seo/build-info-manifest.js.map +1 -0
- package/dist/seo/build-info.d.ts +3 -0
- package/dist/seo/build-info.d.ts.map +1 -0
- package/dist/seo/build-info.js +45 -0
- package/dist/seo/build-info.js.map +1 -0
- package/dist/seo/index.d.ts +4 -0
- package/dist/seo/index.d.ts.map +1 -1
- package/dist/seo/index.js +25 -2
- package/dist/seo/index.js.map +1 -1
- package/dist/seo/routes/robots-txt.d.ts.map +1 -1
- package/dist/seo/routes/robots-txt.js +3 -1
- package/dist/seo/routes/robots-txt.js.map +1 -1
- package/dist/seo/routes/version-json.d.ts +4 -0
- package/dist/seo/routes/version-json.d.ts.map +1 -0
- package/dist/seo/routes/version-json.js +11 -0
- package/dist/seo/routes/version-json.js.map +1 -0
- package/package.json +17 -1
- package/src/components/DemoLegalShell.astro +36 -0
- package/src/contracts/__tests__/content-composition.test.ts +170 -0
- package/src/contracts/capabilities.ts +49 -0
- package/src/contracts/content-composition.ts +176 -0
- package/src/contracts/index.ts +2 -0
- package/src/contracts/traits.ts +107 -0
- package/src/demo/__tests__/demo-content.test.ts +107 -0
- package/src/demo/demo-content.ts +210 -0
- package/src/demo/index.ts +2 -0
- package/src/demo/legal-shells.ts +52 -0
- package/src/i18n/__tests__/create-localization.test.ts +138 -0
- package/src/i18n/__tests__/explicit-formatters.test.ts +82 -0
- package/src/i18n/cli-catalogs.ts +44 -0
- package/src/i18n/create-localization.ts +67 -0
- package/src/i18n/explicit-formatters.ts +36 -0
- package/src/i18n/index.ts +4 -0
- package/src/i18n/locale-inputs.ts +73 -0
- package/src/index.ts +1 -0
- package/src/recipes/__tests__/graph.test.ts +139 -0
- package/src/recipes/__tests__/protocol.test.ts +180 -0
- package/src/recipes/__tests__/serialize.test.ts +128 -0
- package/src/recipes/__tests__/shell-recipe.test.ts +75 -0
- package/src/recipes/admission.ts +77 -0
- package/src/recipes/graph.ts +244 -0
- package/src/recipes/index.ts +8 -0
- package/src/recipes/mermaid.ts +75 -0
- package/src/recipes/registry.ts +48 -0
- package/src/recipes/schema.ts +53 -0
- package/src/recipes/serialize.ts +77 -0
- package/src/recipes/shell-recipe.ts +162 -0
- package/src/recipes/types.ts +63 -0
- package/src/seo/__tests__/build-info-html.test.ts +19 -0
- package/src/seo/__tests__/build-info-integration.test.ts +107 -0
- package/src/seo/__tests__/build-info.test.ts +86 -0
- package/src/seo/__tests__/robots-txt.test.ts +8 -0
- package/src/seo/build-info-manifest.ts +49 -0
- package/src/seo/build-info.ts +44 -0
- package/src/seo/index.ts +28 -3
- package/src/seo/routes/robots-txt.ts +3 -1
- package/src/seo/routes/version-json.ts +13 -0
- package/src/seo/routes/version.astro +42 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { readFileSync, existsSync } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { z } from 'astro/zod';
|
|
5
|
+
import {
|
|
6
|
+
BuildInfoError, buildInfoOptionsSchema, exactVersionSchema,
|
|
7
|
+
type BuildInfoManifest, type BuildInfoPackageId,
|
|
8
|
+
} from './build-info-manifest.js';
|
|
9
|
+
|
|
10
|
+
const packageSchema = z.object({ name: z.string(), version: exactVersionSchema });
|
|
11
|
+
|
|
12
|
+
function installedPackage(id: BuildInfoPackageId, root: URL) {
|
|
13
|
+
const name = `@easy-web/${id}`;
|
|
14
|
+
let folder = fileURLToPath(root);
|
|
15
|
+
let manifestPath = join(folder, 'node_modules', name, 'package.json');
|
|
16
|
+
while (!existsSync(manifestPath)) {
|
|
17
|
+
const parent = dirname(folder);
|
|
18
|
+
if (parent === folder) throw new BuildInfoError(`${name} must be installed in the site before it can be enabled.`);
|
|
19
|
+
folder = parent;
|
|
20
|
+
manifestPath = join(folder, 'node_modules', name, 'package.json');
|
|
21
|
+
}
|
|
22
|
+
const result = packageSchema.safeParse(JSON.parse(readFileSync(manifestPath, 'utf8')));
|
|
23
|
+
if (!result.success || result.data.name !== name) throw new BuildInfoError(`${name} artifact must contain its package identity and an exact version.`);
|
|
24
|
+
return result.data;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function buildInfoManifest(input: unknown, root: URL): BuildInfoManifest {
|
|
28
|
+
const parsed = buildInfoOptionsSchema.safeParse(input);
|
|
29
|
+
if (!parsed.success) throw new BuildInfoError(`options are invalid: ${parsed.error.message}`);
|
|
30
|
+
const options = parsed.data;
|
|
31
|
+
const core = packageSchema.parse(JSON.parse(readFileSync(new URL('../../package.json', import.meta.url), 'utf8')));
|
|
32
|
+
if (core.name !== '@easy-web/core') throw new BuildInfoError('core artifact identity is invalid.');
|
|
33
|
+
const packages = Object.freeze([...new Set<BuildInfoPackageId>(['core', ...(options.packages ?? [])])].sort());
|
|
34
|
+
for (const id of packages) {
|
|
35
|
+
if (id === 'core') continue;
|
|
36
|
+
const installed = installedPackage(id, root);
|
|
37
|
+
if (installed.version !== core.version) throw new BuildInfoError(`${installed.name} version must match core version ${core.version}.`);
|
|
38
|
+
}
|
|
39
|
+
return Object.freeze({
|
|
40
|
+
schema: 'easy-web/build-info', schemaVersion: 1, site: options.site,
|
|
41
|
+
...(options.releaseId === undefined ? {} : { releaseId: options.releaseId }),
|
|
42
|
+
easyWeb: Object.freeze({ version: core.version, packages }),
|
|
43
|
+
});
|
|
44
|
+
}
|
package/src/seo/index.ts
CHANGED
|
@@ -9,10 +9,16 @@ import {
|
|
|
9
9
|
} from '../i18n/index.js'
|
|
10
10
|
|
|
11
11
|
import { createCrawlPolicy, isDisallowedPath } from './crawl-policy.js'
|
|
12
|
+
import { buildInfoManifest } from './build-info.js'
|
|
13
|
+
import { buildInfoOptionsSchema, serializeBuildInfo, type BuildInfoOptions } from './build-info-manifest.js'
|
|
14
|
+
|
|
15
|
+
export type { BuildInfoOptions, BuildInfoPackageId, BuildInfoManifest } from './build-info-manifest.js'
|
|
12
16
|
|
|
13
17
|
export type { LocalizedPathGroup }
|
|
14
18
|
|
|
15
19
|
export type Options = {
|
|
20
|
+
/** Public labels only; these routes are public, not protected by crawler directives. */
|
|
21
|
+
readonly buildInfo?: BuildInfoOptions
|
|
16
22
|
noIndex?: boolean
|
|
17
23
|
sitemapLocales?: Record<string, string>
|
|
18
24
|
/**
|
|
@@ -87,6 +93,10 @@ function pathnameOf(page: string, config: AstroConfig): string {
|
|
|
87
93
|
return pathname
|
|
88
94
|
}
|
|
89
95
|
|
|
96
|
+
function isBuildInfoPath(pathname: string): boolean {
|
|
97
|
+
return pathname === '/version' || pathname === '/version.json'
|
|
98
|
+
}
|
|
99
|
+
|
|
90
100
|
export default function easyWebSeo(options: Options = {}): AstroIntegration {
|
|
91
101
|
return {
|
|
92
102
|
name: '@easy-web/seo',
|
|
@@ -101,6 +111,11 @@ export default function easyWebSeo(options: Options = {}): AstroIntegration {
|
|
|
101
111
|
}
|
|
102
112
|
|
|
103
113
|
const noIndex = options.noIndex ?? false
|
|
114
|
+
const buildInfoOptions = options.buildInfo === undefined ? undefined : buildInfoOptionsSchema.parse(options.buildInfo)
|
|
115
|
+
const manifest = buildInfoOptions === undefined ? undefined : buildInfoManifest(buildInfoOptions, config.root)
|
|
116
|
+
if (manifest) process.env.EASY_WEB_SEO_BUILD_INFO = serializeBuildInfo(manifest)
|
|
117
|
+
else delete process.env.EASY_WEB_SEO_BUILD_INFO
|
|
118
|
+
process.env.EASY_WEB_SEO_BUILD_INFO_JSON = String(buildInfoOptions?.json === true)
|
|
104
119
|
const policy = createCrawlPolicy(noIndex)
|
|
105
120
|
|
|
106
121
|
let sitemapI18n: { defaultLocale: string; locales: Record<string, string> } | undefined
|
|
@@ -166,9 +181,12 @@ export default function easyWebSeo(options: Options = {}): AstroIntegration {
|
|
|
166
181
|
const sitemapIntegration = sitemap({
|
|
167
182
|
...(sitemapI18n ? { i18n: sitemapI18n } : {}),
|
|
168
183
|
namespaces: { xhtml: true },
|
|
169
|
-
filter: (page: string): boolean =>
|
|
170
|
-
|
|
171
|
-
(
|
|
184
|
+
filter: (page: string): boolean => {
|
|
185
|
+
const pathname = pathnameOf(page, config)
|
|
186
|
+
return !isDisallowedPath(pathname, policy) &&
|
|
187
|
+
!(manifest && isBuildInfoPath(pathname)) &&
|
|
188
|
+
(options.filter?.(page) ?? true)
|
|
189
|
+
},
|
|
172
190
|
serialize: (item: SitemapItem): SitemapItem => {
|
|
173
191
|
// Re-render every <loc> through the same helper that produces the
|
|
174
192
|
// canonical, so the two agree byte-for-byte. @astrojs/sitemap
|
|
@@ -236,6 +254,7 @@ export default function easyWebSeo(options: Options = {}): AstroIntegration {
|
|
|
236
254
|
}
|
|
237
255
|
|
|
238
256
|
process.env.EASY_WEB_SEO_NO_INDEX = String(noIndex)
|
|
257
|
+
process.env.EASY_WEB_SEO_BASE = config.base
|
|
239
258
|
// <SeoHead> is a component and cannot read astro.config, so the style
|
|
240
259
|
// the sitemap uses is published here for it to reuse. Both surfaces
|
|
241
260
|
// therefore derive the canonical URL form from one resolver.
|
|
@@ -246,6 +265,12 @@ export default function easyWebSeo(options: Options = {}): AstroIntegration {
|
|
|
246
265
|
entrypoint: new URL('./routes/robots-txt.js', import.meta.url),
|
|
247
266
|
prerender: true,
|
|
248
267
|
})
|
|
268
|
+
if (manifest) {
|
|
269
|
+
injectRoute({ pattern: '/version', entrypoint: new URL('../../src/seo/routes/version.astro', import.meta.url), prerender: true })
|
|
270
|
+
if (buildInfoOptions?.json === true) {
|
|
271
|
+
injectRoute({ pattern: '/version.json', entrypoint: new URL('./routes/version-json.js', import.meta.url), prerender: true })
|
|
272
|
+
}
|
|
273
|
+
}
|
|
249
274
|
},
|
|
250
275
|
},
|
|
251
276
|
}
|
|
@@ -13,8 +13,10 @@ function render(policy: CrawlPolicy, site: URL | undefined): string {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
if (policy.sitemap && site) {
|
|
16
|
+
const configuredBase = process.env.EASY_WEB_SEO_BASE ?? '/'
|
|
17
|
+
const base = `/${configuredBase.replace(/^\/+|\/+$/g, '')}`.replace(/^\/$/, '')
|
|
16
18
|
lines.push('')
|
|
17
|
-
lines.push(`Sitemap: ${new URL(
|
|
19
|
+
lines.push(`Sitemap: ${new URL(`${base}/sitemap-index.xml`, site).href}`)
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
return `${lines.join('\n')}\n`
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { APIRoute } from 'astro';
|
|
2
|
+
import { readBuildInfo, serializeBuildInfo } from '../build-info-manifest.js';
|
|
3
|
+
|
|
4
|
+
export const prerender = true;
|
|
5
|
+
|
|
6
|
+
export const GET: APIRoute = () => new Response(serializeBuildInfo(readBuildInfo()), {
|
|
7
|
+
headers: {
|
|
8
|
+
'Content-Type': 'application/json; charset=utf-8',
|
|
9
|
+
'Cache-Control': 'no-store',
|
|
10
|
+
'X-Content-Type-Options': 'nosniff',
|
|
11
|
+
'X-Robots-Tag': 'noindex, nofollow',
|
|
12
|
+
},
|
|
13
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
---
|
|
2
|
+
import Hero from '../../components/Hero.astro';
|
|
3
|
+
import Section from '../../components/Section.astro';
|
|
4
|
+
import '../../../styles/tokens.css';
|
|
5
|
+
import { readBuildInfo } from '../build-info-manifest.js';
|
|
6
|
+
|
|
7
|
+
export const prerender = true;
|
|
8
|
+
const manifest = readBuildInfo();
|
|
9
|
+
const hasJson = process.env.EASY_WEB_SEO_BUILD_INFO_JSON === 'true';
|
|
10
|
+
---
|
|
11
|
+
<!doctype html>
|
|
12
|
+
<html lang="en">
|
|
13
|
+
<head>
|
|
14
|
+
<meta charset="utf-8" />
|
|
15
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
16
|
+
<meta name="robots" content="noindex,nofollow" />
|
|
17
|
+
<title>Build information - {manifest.site}</title>
|
|
18
|
+
</head>
|
|
19
|
+
<body>
|
|
20
|
+
<main>
|
|
21
|
+
<Hero title="Build information" subtitle={manifest.site} />
|
|
22
|
+
<Section title="easy-web family">
|
|
23
|
+
<dl>
|
|
24
|
+
<dt>Version</dt><dd>{manifest.easyWeb.version}</dd>
|
|
25
|
+
{manifest.releaseId !== undefined && <><dt>Release</dt><dd>{manifest.releaseId}</dd></>}
|
|
26
|
+
</dl>
|
|
27
|
+
<p>All displayed packages share one easy-web family version. Individual UI components are not independently versioned.</p>
|
|
28
|
+
<ul>{manifest.easyWeb.packages.map((id) => <li><code>@easy-web/{id}</code></li>)}</ul>
|
|
29
|
+
{hasJson && <p><a href={`${import.meta.env.BASE_URL.replace(/\/$/, '')}/version.json`}>Machine-readable build information (JSON)</a></p>}
|
|
30
|
+
</Section>
|
|
31
|
+
</main>
|
|
32
|
+
</body>
|
|
33
|
+
</html>
|
|
34
|
+
|
|
35
|
+
<style>
|
|
36
|
+
body { margin: 0; background: var(--ew-surface); color: var(--ew-on-surface); font-family: var(--ew-font-sans); line-height: var(--ew-leading-normal); }
|
|
37
|
+
dt { font-weight: 700; }
|
|
38
|
+
dd { margin: 0 0 var(--ew-space-4); overflow-wrap: anywhere; }
|
|
39
|
+
code { font-family: var(--ew-font-mono); }
|
|
40
|
+
a { color: var(--ew-link); }
|
|
41
|
+
a:focus-visible { outline: 2px solid var(--ew-primary); outline-offset: var(--ew-space-1); }
|
|
42
|
+
</style>
|