@easy-web/seo 1.3.3 → 1.4.1
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 +9 -132
- package/dist/index.d.ts +6 -23
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -170
- package/dist/index.js.map +1 -1
- package/package.json +3 -5
- package/src/components/SeoHead.astro +8 -101
- package/dist/crawl-policy.d.ts +0 -18
- package/dist/crawl-policy.d.ts.map +0 -1
- package/dist/crawl-policy.js +0 -25
- package/dist/crawl-policy.js.map +0 -1
- package/dist/routes/robots-txt.d.ts +0 -3
- package/dist/routes/robots-txt.d.ts.map +0 -1
- package/dist/routes/robots-txt.js +0 -28
- package/dist/routes/robots-txt.js.map +0 -1
- package/src/routes/robots-txt.ts +0 -36
package/README.md
CHANGED
|
@@ -1,135 +1,12 @@
|
|
|
1
|
-
# @easy-web/seo
|
|
1
|
+
# @easy-web/seo (deprecated)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This package is a compatibility layer. The SEO integration, crawl policy, `robots.txt` route and `<SeoHead>` component now live in [`@easy-web/core`](../core/README.md). Every export keeps working and re-exports the core implementation unchanged, but new code should import from `@easy-web/core`.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
`astro`
|
|
5
|
+
| Old import | New import |
|
|
6
|
+
| :--- | :--- |
|
|
7
|
+
| `import easyWebSeo from '@easy-web/seo'` | `import easyWebSeo from '@easy-web/core/seo'` |
|
|
8
|
+
| `import { createCrawlPolicy, isDisallowedPath, type CrawlPolicy, type Options, type LocalizedPathGroup } from '@easy-web/seo'` | `import { ... } from '@easy-web/core/seo'` |
|
|
9
|
+
| `import SeoHead from '@easy-web/seo/components/SeoHead'` | `import SeoHead from '@easy-web/core/components/SeoHead'` |
|
|
10
|
+
| `import SeoHead from '@easy-web/seo/components/SeoHead.astro'` | `import SeoHead from '@easy-web/core/components/SeoHead.astro'` |
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
```ts
|
|
15
|
-
// astro.config.mjs
|
|
16
|
-
import easyWebSeo from '@easy-web/seo';
|
|
17
|
-
|
|
18
|
-
export default defineConfig({
|
|
19
|
-
site: 'https://yoursite.example',
|
|
20
|
-
integrations: [
|
|
21
|
-
easyWebSeo({
|
|
22
|
-
sitemapLocales: { de: 'de-DE', en: 'en-US' },
|
|
23
|
-
// noIndex: true // set on staging/dev sites
|
|
24
|
-
}),
|
|
25
|
-
],
|
|
26
|
-
});
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
## Routes whose slug differs per locale
|
|
30
|
-
|
|
31
|
-
`@astrojs/sitemap` pairs translations by comparing the path left after the
|
|
32
|
-
locale prefix is stripped. `/datenschutz/` and `/en/privacy/` therefore never
|
|
33
|
-
pair, and their hreflang alternates are dropped. Declare such routes explicitly:
|
|
34
|
-
|
|
35
|
-
```ts
|
|
36
|
-
easyWebSeo({
|
|
37
|
-
sitemapLocales: { de: 'de-DE', en: 'en-US' },
|
|
38
|
-
localizedPaths: [
|
|
39
|
-
{ de: '/datenschutz/', en: '/en/privacy/' },
|
|
40
|
-
{ de: '/kontakt/', en: '/en/contact/' },
|
|
41
|
-
],
|
|
42
|
-
});
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
Routes that use the same slug in every locale (`/impressum/` ↔ `/en/impressum/`)
|
|
46
|
-
pair automatically and must not be listed.
|
|
47
|
-
|
|
48
|
-
Pass the same groups to `createI18n` from `@easy-web/i18n` so the page `<head>`
|
|
49
|
-
and the sitemap agree. Declare them once in a shared module:
|
|
50
|
-
|
|
51
|
-
```ts
|
|
52
|
-
// src/lib/localized-paths.ts
|
|
53
|
-
export const localizedPaths = [
|
|
54
|
-
{ de: '/datenschutz/', en: '/en/privacy/' },
|
|
55
|
-
] as const;
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
A group that names an unknown locale, omits a configured one, claims a path
|
|
59
|
-
already owned by another group, or points at a route that was never built fails
|
|
60
|
-
the build.
|
|
61
|
-
|
|
62
|
-
## Crawl policy
|
|
63
|
-
|
|
64
|
-
robots.txt and the sitemap derive from one internal policy, so they cannot
|
|
65
|
-
disagree:
|
|
66
|
-
|
|
67
|
-
| Mode | robots.txt | Sitemap |
|
|
68
|
-
| :--- | :--- | :--- |
|
|
69
|
-
| default | `Disallow: /admin/`, `Allow: /`, `Sitemap:` line | emitted, `/admin/` excluded |
|
|
70
|
-
| `noIndex: true` | `Disallow: /` | not emitted |
|
|
71
|
-
|
|
72
|
-
A caller-supplied `filter` composes with this policy using AND semantics and
|
|
73
|
-
cannot re-admit a blocked path.
|
|
74
|
-
|
|
75
|
-
## URL form
|
|
76
|
-
|
|
77
|
-
`<SeoHead>` normalises the canonical and `og:url` to the form the site actually
|
|
78
|
-
serves, resolved from Astro's `build.format` and `trailingSlash`. With Astro's
|
|
79
|
-
defaults that is a trailing slash (`/about/`), matching the sitemap `<loc>` and
|
|
80
|
-
the self-referencing hreflang.
|
|
81
|
-
|
|
82
|
-
This matters because `/about` and `/about/` both return 200 on Azure Static Web
|
|
83
|
-
Apps. If the canonical and the sitemap disagree, Google sees competing
|
|
84
|
-
duplicates. Pages may therefore pass `pathname` in either spelling — the emitted
|
|
85
|
-
URL is the same either way.
|
|
86
|
-
|
|
87
|
-
The integration resolves the style itself: `'never'` when Astro's `trailingSlash`
|
|
88
|
-
is `'never'` or `build.format` is not `'directory'`, `'always'` otherwise. It then
|
|
89
|
-
publishes the resolved value so `<SeoHead>` reuses it, which is why the canonical,
|
|
90
|
-
the sitemap `<loc>` and the self-referencing hreflang cannot drift apart.
|
|
91
|
-
|
|
92
|
-
`createI18n` from `@easy-web/i18n` does not read `astro.config`, so pass it the
|
|
93
|
-
matching style explicitly with the `trailingSlash: 'always' | 'never'` option
|
|
94
|
-
(default `'always'`):
|
|
95
|
-
|
|
96
|
-
```ts
|
|
97
|
-
// src/lib/i18n.ts
|
|
98
|
-
import { createI18n } from '@easy-web/i18n';
|
|
99
|
-
import { localizedPaths } from './localized-paths';
|
|
100
|
-
|
|
101
|
-
export const i18n = createI18n({
|
|
102
|
-
locales: ['de', 'en'],
|
|
103
|
-
defaultLocale: 'de',
|
|
104
|
-
baseUrl: 'https://yoursite.example',
|
|
105
|
-
localizedPaths,
|
|
106
|
-
trailingSlash: 'always', // must match the site's Astro config
|
|
107
|
-
});
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
Setting it on one side only is the one way these surfaces can still disagree.
|
|
111
|
-
|
|
112
|
-
## hreflang locale tags
|
|
113
|
-
|
|
114
|
-
Provide `sitemapLocales` to control the emitted tags. Without it the integration
|
|
115
|
-
falls back to language-only tags (`de`, `en`) and warns. It deliberately does not
|
|
116
|
-
guess a region: uppercasing the language code is correct only when the two
|
|
117
|
-
coincide (`de-DE`, `fr-FR`) and produces invalid tags otherwise (`en-EN`,
|
|
118
|
-
`ja-JA`), which Google discards.
|
|
119
|
-
|
|
120
|
-
## SeoHead
|
|
121
|
-
|
|
122
|
-
```astro
|
|
123
|
-
// In your Base layout:
|
|
124
|
-
import SeoHead from '@easy-web/seo/components/SeoHead.astro';
|
|
125
|
-
|
|
126
|
-
<SeoHead
|
|
127
|
-
title={title}
|
|
128
|
-
description={description}
|
|
129
|
-
pathname={pathname}
|
|
130
|
-
locale={locale}
|
|
131
|
-
siteName="My Site"
|
|
132
|
-
/>
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
Full implementation: see package source.
|
|
12
|
+
The `robots.txt` route is injected from `@easy-web/core`, so this package no longer ships `src/routes`.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,24 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Routes whose slug differs per locale, e.g. `{ de: '/datenschutz/', en: '/en/privacy/' }`.
|
|
9
|
-
*
|
|
10
|
-
* `@astrojs/sitemap` pairs translations by comparing the path left after the
|
|
11
|
-
* locale prefix is stripped, so translated slugs never pair and their
|
|
12
|
-
* hreflang alternates are silently omitted. Declaring the group here restores
|
|
13
|
-
* them. Declare the same groups on `createI18n` so the page `<head>` and the
|
|
14
|
-
* sitemap agree.
|
|
15
|
-
*
|
|
16
|
-
* A stale or misspelled entry fails the build rather than degrading quietly.
|
|
17
|
-
*/
|
|
18
|
-
localizedPaths?: readonly LocalizedPathGroup[];
|
|
19
|
-
/** Composed with the built-in crawl policy using AND semantics; cannot re-admit blocked paths. */
|
|
20
|
-
filter?: (page: string) => boolean;
|
|
21
|
-
};
|
|
22
|
-
export default function easyWebSeo(options?: Options): AstroIntegration;
|
|
23
|
-
export { createCrawlPolicy, isDisallowedPath, type CrawlPolicy } from './crawl-policy.js';
|
|
1
|
+
/**
|
|
2
|
+
* @easy-web/seo is a compatibility package; everything it exports now lives in
|
|
3
|
+
* `@easy-web/core/seo`. Import from there instead.
|
|
4
|
+
*/
|
|
5
|
+
export { default } from '@easy-web/core/seo';
|
|
6
|
+
export * from '@easy-web/core/seo';
|
|
24
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,cAAc,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,171 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function resolveTrailingSlash(config, logger) {
|
|
8
|
-
// An explicit astro `trailingSlash` is a statement of intent about the served
|
|
9
|
-
// URL, so it outranks the output shape. Only when it is left at 'ignore' does
|
|
10
|
-
// `build.format` decide.
|
|
11
|
-
if (config.trailingSlash === 'always')
|
|
12
|
-
return 'always';
|
|
13
|
-
if (config.trailingSlash === 'never')
|
|
14
|
-
return 'never';
|
|
15
|
-
if (config.build.format === 'file')
|
|
16
|
-
return 'never';
|
|
17
|
-
if (config.build.format === 'directory')
|
|
18
|
-
return 'always';
|
|
19
|
-
// 'preserve' mirrors the source tree, so some routes emit as files and others
|
|
20
|
-
// as directories. No single form is correct for the whole site.
|
|
21
|
-
logger?.warn('@easy-web/seo: `build.format: "preserve"` emits a mix of file and directory routes, ' +
|
|
22
|
-
'so no single canonical URL form is correct. Assuming trailing slashes; ' +
|
|
23
|
-
'set `trailingSlash` in astro.config.mjs to state the intent explicitly.');
|
|
24
|
-
return 'always';
|
|
25
|
-
}
|
|
26
|
-
function toOutputUrl(path, config) {
|
|
27
|
-
const route = toServedPath(path, resolveTrailingSlash(config));
|
|
28
|
-
const base = new URL(config.base.endsWith('/') ? config.base : `${config.base}/`, config.site);
|
|
29
|
-
return new URL(route.replace(/^\/+/, ''), base).href;
|
|
30
|
-
}
|
|
31
|
-
function pathnameOf(page, config) {
|
|
32
|
-
const absolute = page.startsWith('http') ? page : new URL(page, config.site).href;
|
|
33
|
-
const basePath = normalizeLocalizedPath(config.base);
|
|
34
|
-
const pathname = normalizeLocalizedPath(new URL(absolute).pathname);
|
|
35
|
-
if (basePath !== '/' && (pathname === basePath || pathname.startsWith(`${basePath}/`))) {
|
|
36
|
-
const stripped = pathname.slice(basePath.length);
|
|
37
|
-
return stripped === '' ? '/' : stripped;
|
|
38
|
-
}
|
|
39
|
-
return pathname;
|
|
40
|
-
}
|
|
41
|
-
export default function easyWebSeo(options = {}) {
|
|
42
|
-
return {
|
|
43
|
-
name: '@easy-web/seo',
|
|
44
|
-
hooks: {
|
|
45
|
-
'astro:config:setup': ({ config, updateConfig, injectRoute, logger }) => {
|
|
46
|
-
if (!config.site) {
|
|
47
|
-
logger.error('@easy-web/seo: astro.config.mjs must set `site` (a full https:// URL). ' +
|
|
48
|
-
'Example: site: "https://yoursite.example"');
|
|
49
|
-
throw new Error('@easy-web/seo: `site` is required in astro.config.mjs');
|
|
50
|
-
}
|
|
51
|
-
const noIndex = options.noIndex ?? false;
|
|
52
|
-
const policy = createCrawlPolicy(noIndex);
|
|
53
|
-
let sitemapI18n;
|
|
54
|
-
if (config.i18n && config.i18n.locales.length > 0) {
|
|
55
|
-
const localeMap = options.sitemapLocales ?? {};
|
|
56
|
-
if (!options.sitemapLocales) {
|
|
57
|
-
// Language-only tags, never a guessed region. "uppercase the language"
|
|
58
|
-
// only coincidentally works (de-DE, fr-FR) and invents nonexistent
|
|
59
|
-
// regions otherwise (en-EN, ja-JA, sv-SV), which Google discards.
|
|
60
|
-
for (const locale of config.i18n.locales) {
|
|
61
|
-
const id = typeof locale === 'string' ? locale : locale.path;
|
|
62
|
-
localeMap[id] = id;
|
|
63
|
-
}
|
|
64
|
-
logger.warn('@easy-web/seo: no `sitemapLocales` provided, falling back to language-only hreflang tags (' +
|
|
65
|
-
Object.keys(localeMap).join(', ') +
|
|
66
|
-
'). Provide `sitemapLocales` for region-specific tags (e.g. { de: "de-DE", en: "en-US" }).');
|
|
67
|
-
}
|
|
68
|
-
sitemapI18n = {
|
|
69
|
-
defaultLocale: config.i18n.defaultLocale,
|
|
70
|
-
locales: localeMap,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
const declaredGroups = options.localizedPaths ?? [];
|
|
74
|
-
if (declaredGroups.length > 0 && !sitemapI18n) {
|
|
75
|
-
throw new Error('@easy-web/seo: `localizedPaths` requires `i18n` to be configured in astro.config.mjs.');
|
|
76
|
-
}
|
|
77
|
-
const localeIds = localeIdsOf(config);
|
|
78
|
-
const problems = validateLocalizedPaths(declaredGroups, localeIds);
|
|
79
|
-
if (problems.length > 0) {
|
|
80
|
-
throw new Error(`@easy-web/seo: invalid \`localizedPaths\`:\n- ${problems.join('\n- ')}`);
|
|
81
|
-
}
|
|
82
|
-
const linksByUrl = new Map();
|
|
83
|
-
const declaredUrls = new Set();
|
|
84
|
-
for (const group of declaredGroups) {
|
|
85
|
-
const links = localeIds
|
|
86
|
-
.filter((locale) => group[locale] !== undefined)
|
|
87
|
-
.map((locale) => ({
|
|
88
|
-
lang: sitemapI18n.locales[locale],
|
|
89
|
-
url: toOutputUrl(group[locale], config),
|
|
90
|
-
}));
|
|
91
|
-
for (const link of links) {
|
|
92
|
-
linksByUrl.set(link.url, links);
|
|
93
|
-
declaredUrls.add(link.url);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
const seenUrls = new Set();
|
|
97
|
-
const conflicts = [];
|
|
98
|
-
if (policy.sitemap) {
|
|
99
|
-
const sitemapIntegration = sitemap({
|
|
100
|
-
...(sitemapI18n ? { i18n: sitemapI18n } : {}),
|
|
101
|
-
namespaces: { xhtml: true },
|
|
102
|
-
filter: (page) => !isDisallowedPath(pathnameOf(page, config), policy) &&
|
|
103
|
-
(options.filter?.(page) ?? true),
|
|
104
|
-
serialize: (item) => {
|
|
105
|
-
// Re-render every <loc> through the same helper that produces the
|
|
106
|
-
// canonical, so the two agree byte-for-byte. @astrojs/sitemap
|
|
107
|
-
// renders the site root as a bare origin with no path, which the
|
|
108
|
-
// canonical never does.
|
|
109
|
-
const url = toOutputUrl(pathnameOf(item.url, config), config);
|
|
110
|
-
const declared = linksByUrl.get(url);
|
|
111
|
-
if (declared) {
|
|
112
|
-
seenUrls.add(url);
|
|
113
|
-
// Replace, never merge: every member of a group must carry the
|
|
114
|
-
// same complete, reciprocal set or Google rejects the cluster.
|
|
115
|
-
return { ...item, url, links: [...declared] };
|
|
116
|
-
}
|
|
117
|
-
for (const link of item.links ?? []) {
|
|
118
|
-
if (linksByUrl.has(link.url)) {
|
|
119
|
-
conflicts.push(`${url} was auto-paired with ${link.url}, which is already claimed by a localizedPaths group.`);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return {
|
|
123
|
-
...item,
|
|
124
|
-
url,
|
|
125
|
-
...(item.links
|
|
126
|
-
? {
|
|
127
|
-
links: item.links.map((link) => ({
|
|
128
|
-
...link,
|
|
129
|
-
url: toOutputUrl(pathnameOf(link.url, config), config),
|
|
130
|
-
})),
|
|
131
|
-
}
|
|
132
|
-
: {}),
|
|
133
|
-
};
|
|
134
|
-
},
|
|
135
|
-
});
|
|
136
|
-
const validatorIntegration = {
|
|
137
|
-
name: '@easy-web/seo:localized-paths-validation',
|
|
138
|
-
hooks: {
|
|
139
|
-
'astro:build:done': () => {
|
|
140
|
-
const missing = [...declaredUrls].filter((url) => !seenUrls.has(url));
|
|
141
|
-
const failures = [
|
|
142
|
-
...missing.map((url) => `${url} is declared in localizedPaths but no such page was built. Check for a typo or a removed route.`),
|
|
143
|
-
...conflicts,
|
|
144
|
-
];
|
|
145
|
-
if (failures.length > 0) {
|
|
146
|
-
throw new Error(`@easy-web/seo: invalid \`localizedPaths\`:\n- ${failures.join('\n- ')}`);
|
|
147
|
-
}
|
|
148
|
-
},
|
|
149
|
-
},
|
|
150
|
-
};
|
|
151
|
-
// Order matters: @astrojs/sitemap runs serialize inside its own
|
|
152
|
-
// astro:build:done, and it swallows errors thrown from serialize, so
|
|
153
|
-
// validation has to run in a later hook to fail the build.
|
|
154
|
-
updateConfig({ integrations: [sitemapIntegration, validatorIntegration] });
|
|
155
|
-
}
|
|
156
|
-
process.env.EASY_WEB_SEO_NO_INDEX = String(noIndex);
|
|
157
|
-
// <SeoHead> is a component and cannot read astro.config, so the style
|
|
158
|
-
// the sitemap uses is published here for it to reuse. Both surfaces
|
|
159
|
-
// therefore derive the canonical URL form from one resolver.
|
|
160
|
-
process.env.EASY_WEB_SEO_TRAILING_SLASH = resolveTrailingSlash(config, logger);
|
|
161
|
-
injectRoute({
|
|
162
|
-
pattern: '/robots.txt',
|
|
163
|
-
entrypoint: new URL('./routes/robots-txt.js', import.meta.url),
|
|
164
|
-
prerender: true,
|
|
165
|
-
});
|
|
166
|
-
},
|
|
167
|
-
},
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
export { createCrawlPolicy, isDisallowedPath } from './crawl-policy.js';
|
|
1
|
+
/**
|
|
2
|
+
* @easy-web/seo is a compatibility package; everything it exports now lives in
|
|
3
|
+
* `@easy-web/core/seo`. Import from there instead.
|
|
4
|
+
*/
|
|
5
|
+
export { default } from '@easy-web/core/seo';
|
|
6
|
+
export * from '@easy-web/core/seo';
|
|
171
7
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,cAAc,oBAAoB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easy-web/seo",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Shared SEO primitives for @easy-web/* consumer instances — Astro integration wrapping @astrojs/sitemap with i18n hreflang, dynamic robots.txt route with noIndex mode, and <SeoHead> component (canonical, OpenGraph, Twitter Cards, hreflang, theme-color, manifest).",
|
|
6
6
|
"keywords": [
|
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
"files": [
|
|
25
25
|
"dist",
|
|
26
26
|
"src/components",
|
|
27
|
-
"src/routes",
|
|
28
27
|
"README.md"
|
|
29
28
|
],
|
|
30
29
|
"sideEffects": false,
|
|
@@ -32,11 +31,10 @@
|
|
|
32
31
|
"astro": ">=6.0.0 <8.0.0"
|
|
33
32
|
},
|
|
34
33
|
"dependencies": {
|
|
35
|
-
"@
|
|
36
|
-
"@easy-web/i18n": "1.3.3"
|
|
34
|
+
"@easy-web/core": "1.4.1"
|
|
37
35
|
},
|
|
38
36
|
"devDependencies": {
|
|
39
|
-
"astro": "^
|
|
37
|
+
"astro": "^7.3.5",
|
|
40
38
|
"vitest": "^3.2.4",
|
|
41
39
|
"@vitest/coverage-v8": "^3.2.4",
|
|
42
40
|
"typescript": "^5.5.0"
|
|
@@ -1,105 +1,12 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated Import `@easy-web/core/components/SeoHead.astro` instead.
|
|
4
|
+
* Compatibility wrapper: renders the core component with the same props.
|
|
5
|
+
*/
|
|
6
|
+
import SeoHead from '@easy-web/core/components/SeoHead.astro';
|
|
3
7
|
|
|
4
|
-
export
|
|
5
|
-
hreflang: string;
|
|
6
|
-
href: string;
|
|
7
|
-
}
|
|
8
|
+
export type { AlternateLink, Props } from '@easy-web/core/components/SeoHead.astro';
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
title: string;
|
|
11
|
-
description?: string;
|
|
12
|
-
pathname: string;
|
|
13
|
-
locale: string;
|
|
14
|
-
siteName: string;
|
|
15
|
-
ogType?: 'website' | 'article';
|
|
16
|
-
ogImage?: string;
|
|
17
|
-
themeColor?: string;
|
|
18
|
-
manifest?: string;
|
|
19
|
-
noIndex?: boolean;
|
|
20
|
-
twitterCard?: 'summary' | 'summary_large_image';
|
|
21
|
-
twitterSite?: string;
|
|
22
|
-
alternates?: AlternateLink[];
|
|
23
|
-
trailingSlash?: TrailingSlash;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const {
|
|
27
|
-
title,
|
|
28
|
-
description,
|
|
29
|
-
pathname,
|
|
30
|
-
locale,
|
|
31
|
-
siteName,
|
|
32
|
-
ogType = 'website',
|
|
33
|
-
ogImage,
|
|
34
|
-
themeColor,
|
|
35
|
-
manifest,
|
|
36
|
-
noIndex,
|
|
37
|
-
twitterCard = 'summary',
|
|
38
|
-
twitterSite,
|
|
39
|
-
alternates = [],
|
|
40
|
-
trailingSlash,
|
|
41
|
-
} = Astro.props;
|
|
42
|
-
|
|
43
|
-
const site = Astro.site;
|
|
44
|
-
if (!site) {
|
|
45
|
-
throw new Error(
|
|
46
|
-
'@easy-web/seo: <SeoHead> requires astro.config.mjs to set `site` (a full https:// URL).'
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Callers hand-write `pathname` in mixed conventions, so the canonical is
|
|
51
|
-
// normalised to the form the site actually serves. It must match the sitemap
|
|
52
|
-
// <loc> and the self-referencing hreflang exactly, or Google treats /x and /x/
|
|
53
|
-
// as competing duplicates. The style is resolved from Astro's build config by
|
|
54
|
-
// the easyWebSeo() integration.
|
|
55
|
-
const servedStyle: TrailingSlash =
|
|
56
|
-
trailingSlash ?? (process.env.EASY_WEB_SEO_TRAILING_SLASH === 'never' ? 'never' : 'always');
|
|
57
|
-
const servedPath = toServedPath(pathname, servedStyle);
|
|
58
|
-
|
|
59
|
-
// The built 404 documents answer 200 when requested directly, so without this
|
|
60
|
-
// they are ordinary indexable pages whose content happens to say "not found".
|
|
61
|
-
// A self-referencing canonical is omitted for the same reason: it would assert
|
|
62
|
-
// the page is a canonical destination while the body says the opposite.
|
|
63
|
-
const isNotFoundRoute = servedPath.split('/').filter(Boolean).pop() === '404';
|
|
64
|
-
|
|
65
|
-
// The crawl policy is resolved once by easyWebSeo() and published to the
|
|
66
|
-
// environment, exactly like the trailing-slash style above. Defaulting the prop
|
|
67
|
-
// to `false` instead of reading that value meant `easyWebSeo({ noIndex: true })`
|
|
68
|
-
// suppressed the sitemap and wrote a disallow-all robots.txt while every page
|
|
69
|
-
// still shipped without a robots meta tag — the integration and the document
|
|
70
|
-
// disagreeing about the same policy. An explicit prop still wins, so a single
|
|
71
|
-
// page can opt out of a site-wide setting.
|
|
72
|
-
const policyNoIndex = process.env.EASY_WEB_SEO_NO_INDEX === 'true';
|
|
73
|
-
const shouldNoIndex = (noIndex ?? policyNoIndex) || isNotFoundRoute;
|
|
74
|
-
|
|
75
|
-
const canonical = new URL(servedPath, site).href;
|
|
76
|
-
const absoluteOgImage = ogImage ? new URL(ogImage, site).href : undefined;
|
|
77
|
-
// Map locale to OG locale format: 'de' → 'de_DE', 'en' → 'en_US'
|
|
78
|
-
const ogLocale = locale === 'en' ? 'en_US' : locale === 'de' ? 'de_DE' : locale.replace('-', '_');
|
|
79
|
-
const ogLocaleAlternate = locale === 'en' ? 'de_DE' : 'en_US';
|
|
10
|
+
const props = Astro.props;
|
|
80
11
|
---
|
|
81
|
-
<
|
|
82
|
-
{description && <meta name="description" content={description} />}
|
|
83
|
-
{!isNotFoundRoute && <link rel="canonical" href={canonical} />}
|
|
84
|
-
{shouldNoIndex && <meta name="robots" content="noindex, nofollow" />}
|
|
85
|
-
{themeColor && <meta name="theme-color" content={themeColor} />}
|
|
86
|
-
{manifest && <link rel="manifest" href={manifest} />}
|
|
87
|
-
<!-- Open Graph -->
|
|
88
|
-
<meta property="og:title" content={title} />
|
|
89
|
-
{description && <meta property="og:description" content={description} />}
|
|
90
|
-
<meta property="og:url" content={canonical} />
|
|
91
|
-
<meta property="og:type" content={ogType} />
|
|
92
|
-
<meta property="og:locale" content={ogLocale} />
|
|
93
|
-
<meta property="og:locale:alternate" content={ogLocaleAlternate} />
|
|
94
|
-
<meta property="og:site_name" content={siteName} />
|
|
95
|
-
{absoluteOgImage && <meta property="og:image" content={absoluteOgImage} />}
|
|
96
|
-
<!-- Twitter Cards -->
|
|
97
|
-
<meta name="twitter:card" content={twitterCard} />
|
|
98
|
-
<meta name="twitter:title" content={title} />
|
|
99
|
-
{description && <meta name="twitter:description" content={description} />}
|
|
100
|
-
{absoluteOgImage && <meta name="twitter:image" content={absoluteOgImage} />}
|
|
101
|
-
{twitterSite && <meta name="twitter:site" content={twitterSite} />}
|
|
102
|
-
<!-- hreflang alternates -->
|
|
103
|
-
{alternates.map((link) => (
|
|
104
|
-
<link rel="alternate" hreflang={link.hreflang} href={link.href} />
|
|
105
|
-
))}
|
|
12
|
+
<SeoHead {...props} />
|
package/dist/crawl-policy.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Single source of truth for what crawlers may see.
|
|
3
|
-
*
|
|
4
|
-
* robots.txt and the sitemap previously decided this independently: the route
|
|
5
|
-
* handler hardcoded `Disallow: /admin/` while the sitemap integration applied
|
|
6
|
-
* no exclusions at all, so every instance shipped a sitemap advertising the
|
|
7
|
-
* very path its robots.txt blocked. Both outputs now derive from this module,
|
|
8
|
-
* which makes that class of contradiction unrepresentable.
|
|
9
|
-
*/
|
|
10
|
-
export interface CrawlPolicy {
|
|
11
|
-
readonly disallow: readonly string[];
|
|
12
|
-
readonly allow: readonly string[];
|
|
13
|
-
/** Whether this site publishes a sitemap at all — read by both robots.txt and the integration. */
|
|
14
|
-
readonly sitemap: boolean;
|
|
15
|
-
}
|
|
16
|
-
export declare function createCrawlPolicy(noIndex: boolean): CrawlPolicy;
|
|
17
|
-
export declare function isDisallowedPath(pathname: string, policy: CrawlPolicy): boolean;
|
|
18
|
-
//# sourceMappingURL=crawl-policy.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"crawl-policy.d.ts","sourceRoot":"","sources":["../src/crawl-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAA;IACpC,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAA;IACjC,kGAAkG;IAClG,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;CAC1B;AAID,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,WAAW,CAI/D;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAU/E"}
|
package/dist/crawl-policy.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Single source of truth for what crawlers may see.
|
|
3
|
-
*
|
|
4
|
-
* robots.txt and the sitemap previously decided this independently: the route
|
|
5
|
-
* handler hardcoded `Disallow: /admin/` while the sitemap integration applied
|
|
6
|
-
* no exclusions at all, so every instance shipped a sitemap advertising the
|
|
7
|
-
* very path its robots.txt blocked. Both outputs now derive from this module,
|
|
8
|
-
* which makes that class of contradiction unrepresentable.
|
|
9
|
-
*/
|
|
10
|
-
const PUBLIC_DISALLOW = ['/admin/'];
|
|
11
|
-
export function createCrawlPolicy(noIndex) {
|
|
12
|
-
return noIndex
|
|
13
|
-
? { disallow: ['/'], allow: [], sitemap: false }
|
|
14
|
-
: { disallow: [...PUBLIC_DISALLOW], allow: ['/'], sitemap: true };
|
|
15
|
-
}
|
|
16
|
-
export function isDisallowedPath(pathname, policy) {
|
|
17
|
-
return policy.disallow.some((rule) => {
|
|
18
|
-
if (rule === '/') {
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
const prefix = rule.endsWith('/') ? rule : `${rule}/`;
|
|
22
|
-
return pathname === prefix.slice(0, -1) || pathname.startsWith(prefix);
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
//# sourceMappingURL=crawl-policy.js.map
|
package/dist/crawl-policy.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"crawl-policy.js","sourceRoot":"","sources":["../src/crawl-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AASH,MAAM,eAAe,GAAG,CAAC,SAAS,CAAU,CAAA;AAE5C,MAAM,UAAU,iBAAiB,CAAC,OAAgB;IAChD,OAAO,OAAO;QACZ,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE;QAChD,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,eAAe,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA;AACrE,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,QAAgB,EAAE,MAAmB;IACpE,OAAO,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;QACnC,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;YACjB,OAAO,IAAI,CAAA;QACb,CAAC;QAED,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,CAAA;QAErD,OAAO,QAAQ,KAAK,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;IACxE,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"robots-txt.d.ts","sourceRoot":"","sources":["../../src/routes/robots-txt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAsBrC,eAAO,MAAM,GAAG,EAAE,QAajB,CAAA"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { createCrawlPolicy } from '../crawl-policy.js';
|
|
2
|
-
function render(policy, site) {
|
|
3
|
-
const lines = ['User-agent: *'];
|
|
4
|
-
for (const path of policy.disallow) {
|
|
5
|
-
lines.push(`Disallow: ${path}`);
|
|
6
|
-
}
|
|
7
|
-
for (const path of policy.allow) {
|
|
8
|
-
lines.push(`Allow: ${path}`);
|
|
9
|
-
}
|
|
10
|
-
if (policy.sitemap && site) {
|
|
11
|
-
lines.push('');
|
|
12
|
-
lines.push(`Sitemap: ${new URL('sitemap-index.xml', site).href}`);
|
|
13
|
-
}
|
|
14
|
-
return `${lines.join('\n')}\n`;
|
|
15
|
-
}
|
|
16
|
-
export const GET = ({ site }) => {
|
|
17
|
-
if (!site) {
|
|
18
|
-
return new Response(render(createCrawlPolicy(true), undefined), {
|
|
19
|
-
status: 500,
|
|
20
|
-
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
const policy = createCrawlPolicy(process.env.EASY_WEB_SEO_NO_INDEX === 'true');
|
|
24
|
-
return new Response(render(policy, site), {
|
|
25
|
-
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
//# sourceMappingURL=robots-txt.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"robots-txt.js","sourceRoot":"","sources":["../../src/routes/robots-txt.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAoB,MAAM,oBAAoB,CAAA;AAExE,SAAS,MAAM,CAAC,MAAmB,EAAE,IAAqB;IACxD,MAAM,KAAK,GAAG,CAAC,eAAe,CAAC,CAAA;IAE/B,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;QACnC,KAAK,CAAC,IAAI,CAAC,aAAa,IAAI,EAAE,CAAC,CAAA;IACjC,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QAChC,KAAK,CAAC,IAAI,CAAC,UAAU,IAAI,EAAE,CAAC,CAAA;IAC9B,CAAC;IAED,IAAI,MAAM,CAAC,OAAO,IAAI,IAAI,EAAE,CAAC;QAC3B,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QACd,KAAK,CAAC,IAAI,CAAC,YAAY,IAAI,GAAG,CAAC,mBAAmB,EAAE,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;IACnE,CAAC;IAED,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAA;AAChC,CAAC;AAED,MAAM,CAAC,MAAM,GAAG,GAAa,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;IACxC,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,EAAE;YAC9D,MAAM,EAAE,GAAG;YACX,OAAO,EAAE,EAAE,cAAc,EAAE,2BAA2B,EAAE;SACzD,CAAC,CAAA;IACJ,CAAC;IAED,MAAM,MAAM,GAAG,iBAAiB,CAAC,OAAO,CAAC,GAAG,CAAC,qBAAqB,KAAK,MAAM,CAAC,CAAA;IAE9E,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE;QACxC,OAAO,EAAE,EAAE,cAAc,EAAE,2BAA2B,EAAE;KACzD,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
package/src/routes/robots-txt.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { APIRoute } from 'astro'
|
|
2
|
-
|
|
3
|
-
import { createCrawlPolicy, type CrawlPolicy } from '../crawl-policy.js'
|
|
4
|
-
|
|
5
|
-
function render(policy: CrawlPolicy, site: URL | undefined): string {
|
|
6
|
-
const lines = ['User-agent: *']
|
|
7
|
-
|
|
8
|
-
for (const path of policy.disallow) {
|
|
9
|
-
lines.push(`Disallow: ${path}`)
|
|
10
|
-
}
|
|
11
|
-
for (const path of policy.allow) {
|
|
12
|
-
lines.push(`Allow: ${path}`)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (policy.sitemap && site) {
|
|
16
|
-
lines.push('')
|
|
17
|
-
lines.push(`Sitemap: ${new URL('sitemap-index.xml', site).href}`)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return `${lines.join('\n')}\n`
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const GET: APIRoute = ({ site }) => {
|
|
24
|
-
if (!site) {
|
|
25
|
-
return new Response(render(createCrawlPolicy(true), undefined), {
|
|
26
|
-
status: 500,
|
|
27
|
-
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
|
|
28
|
-
})
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const policy = createCrawlPolicy(process.env.EASY_WEB_SEO_NO_INDEX === 'true')
|
|
32
|
-
|
|
33
|
-
return new Response(render(policy, site), {
|
|
34
|
-
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
|
|
35
|
-
})
|
|
36
|
-
}
|