@easy-web/seo 1.0.0 → 1.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Achim Ismaili
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,35 +1,103 @@
1
- # @easy-web/seo
2
-
3
- Shared SEO primitives for the `@easy-web/*` ecosystem.
4
-
5
- ## Usage
6
-
7
- ```ts
8
- // astro.config.mjs
9
- import easyWebSeo from '@easy-web/seo';
10
-
11
- export default defineConfig({
12
- site: 'https://yoursite.example',
13
- integrations: [
14
- easyWebSeo({
15
- sitemapLocales: { de: 'de-DE', en: 'en-US' },
16
- // noIndex: true // set on staging/dev sites
17
- }),
18
- ],
19
- });
20
- ```
21
-
22
- ```astro
23
- // In your Base layout:
24
- import SeoHead from '@easy-web/seo/components/SeoHead.astro';
25
-
26
- <SeoHead
27
- title={title}
28
- description={description}
29
- pathname={pathname}
30
- locale={locale}
31
- siteName="My Site"
32
- />
33
- ```
34
-
35
- Full implementation: see package source.
1
+ # @easy-web/seo
2
+
3
+ Shared SEO primitives for the `@easy-web/*` ecosystem.
4
+
5
+ ## Usage
6
+
7
+ ```ts
8
+ // astro.config.mjs
9
+ import easyWebSeo from '@easy-web/seo';
10
+
11
+ export default defineConfig({
12
+ site: 'https://yoursite.example',
13
+ integrations: [
14
+ easyWebSeo({
15
+ sitemapLocales: { de: 'de-DE', en: 'en-US' },
16
+ // noIndex: true // set on staging/dev sites
17
+ }),
18
+ ],
19
+ });
20
+ ```
21
+
22
+ ## Routes whose slug differs per locale
23
+
24
+ `@astrojs/sitemap` pairs translations by comparing the path left after the
25
+ locale prefix is stripped. `/datenschutz/` and `/en/privacy/` therefore never
26
+ pair, and their hreflang alternates are dropped. Declare such routes explicitly:
27
+
28
+ ```ts
29
+ easyWebSeo({
30
+ sitemapLocales: { de: 'de-DE', en: 'en-US' },
31
+ localizedPaths: [
32
+ { de: '/datenschutz/', en: '/en/privacy/' },
33
+ { de: '/kontakt/', en: '/en/contact/' },
34
+ ],
35
+ });
36
+ ```
37
+
38
+ Routes that use the same slug in every locale (`/impressum/` ↔ `/en/impressum/`)
39
+ pair automatically and must not be listed.
40
+
41
+ Pass the same groups to `createI18n` from `@easy-web/i18n` so the page `<head>`
42
+ and the sitemap agree. Declare them once in a shared module:
43
+
44
+ ```ts
45
+ // src/lib/localized-paths.ts
46
+ export const localizedPaths = [
47
+ { de: '/datenschutz/', en: '/en/privacy/' },
48
+ ] as const;
49
+ ```
50
+
51
+ A group that names an unknown locale, omits a configured one, claims a path
52
+ already owned by another group, or points at a route that was never built fails
53
+ the build.
54
+
55
+ ## Crawl policy
56
+
57
+ robots.txt and the sitemap derive from one internal policy, so they cannot
58
+ disagree:
59
+
60
+ | Mode | robots.txt | Sitemap |
61
+ | :--- | :--- | :--- |
62
+ | default | `Disallow: /admin/`, `Allow: /`, `Sitemap:` line | emitted, `/admin/` excluded |
63
+ | `noIndex: true` | `Disallow: /` | not emitted |
64
+
65
+ A caller-supplied `filter` composes with this policy using AND semantics and
66
+ cannot re-admit a blocked path.
67
+
68
+ ## URL form
69
+
70
+ `<SeoHead>` normalises the canonical and `og:url` to the form the site actually
71
+ serves, resolved from Astro's `build.format` and `trailingSlash`. With Astro's
72
+ defaults that is a trailing slash (`/about/`), matching the sitemap `<loc>` and
73
+ the self-referencing hreflang.
74
+
75
+ This matters because `/about` and `/about/` both return 200 on Azure Static Web
76
+ Apps. If the canonical and the sitemap disagree, Google sees competing
77
+ duplicates. Pages may therefore pass `pathname` in either spelling — the emitted
78
+ URL is the same either way.
79
+
80
+ ## hreflang locale tags
81
+
82
+ Provide `sitemapLocales` to control the emitted tags. Without it the integration
83
+ falls back to language-only tags (`de`, `en`) and warns. It deliberately does not
84
+ guess a region: uppercasing the language code is correct only when the two
85
+ coincide (`de-DE`, `fr-FR`) and produces invalid tags otherwise (`en-EN`,
86
+ `ja-JA`), which Google discards.
87
+
88
+ ## SeoHead
89
+
90
+ ```astro
91
+ // In your Base layout:
92
+ import SeoHead from '@easy-web/seo/components/SeoHead.astro';
93
+
94
+ <SeoHead
95
+ title={title}
96
+ description={description}
97
+ pathname={pathname}
98
+ locale={locale}
99
+ siteName="My Site"
100
+ />
101
+ ```
102
+
103
+ Full implementation: see package source.
@@ -0,0 +1,18 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,25 @@
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
@@ -0,0 +1 @@
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"}
package/dist/index.d.ts CHANGED
@@ -1,8 +1,24 @@
1
1
  import type { AstroIntegration } from 'astro';
2
+ import { type LocalizedPathGroup } from '@easy-web/i18n';
3
+ export type { LocalizedPathGroup };
2
4
  export type Options = {
3
5
  noIndex?: boolean;
4
6
  sitemapLocales?: Record<string, string>;
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. */
5
20
  filter?: (page: string) => boolean;
6
21
  };
7
22
  export default function easyWebSeo(options?: Options): AstroIntegration;
23
+ export { createCrawlPolicy, isDisallowedPath, type CrawlPolicy } from './crawl-policy.js';
8
24
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAG9C,MAAM,MAAM,OAAO,GAAG;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;CACpC,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,OAAO,GAAE,OAAY,GAAG,gBAAgB,CA0D1E"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,gBAAgB,EAAE,MAAM,OAAO,CAAA;AAE1D,OAAO,EAIL,KAAK,kBAAkB,EAExB,MAAM,gBAAgB,CAAA;AAIvB,YAAY,EAAE,kBAAkB,EAAE,CAAA;AAElC,MAAM,MAAM,OAAO,GAAG;IACpB,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,kGAAkG;IAClG,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAA;CACnC,CAAA;AA0CD,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,OAAO,GAAE,OAAY,GAAG,gBAAgB,CAkJ1E;AAED,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAA"}
package/dist/index.js CHANGED
@@ -1,46 +1,132 @@
1
1
  import sitemap from '@astrojs/sitemap';
2
+ import { normalizeLocalizedPath, toServedPath, validateLocalizedPaths, } from '@easy-web/i18n';
3
+ import { createCrawlPolicy, isDisallowedPath } from './crawl-policy.js';
4
+ function localeIdsOf(config) {
5
+ return (config.i18n?.locales ?? []).map((locale) => typeof locale === 'string' ? locale : locale.path);
6
+ }
7
+ function resolveTrailingSlash(config) {
8
+ const usesDirectoryFormat = config.trailingSlash !== 'never' && config.build.format === 'directory';
9
+ return usesDirectoryFormat ? 'always' : 'never';
10
+ }
11
+ function toOutputUrl(path, config) {
12
+ const route = toServedPath(path, resolveTrailingSlash(config));
13
+ const base = new URL(config.base.endsWith('/') ? config.base : `${config.base}/`, config.site);
14
+ return new URL(route.replace(/^\/+/, ''), base).href;
15
+ }
16
+ function pathnameOf(page, config) {
17
+ const absolute = page.startsWith('http') ? page : new URL(page, config.site).href;
18
+ const basePath = normalizeLocalizedPath(config.base);
19
+ const pathname = normalizeLocalizedPath(new URL(absolute).pathname);
20
+ if (basePath !== '/' && (pathname === basePath || pathname.startsWith(`${basePath}/`))) {
21
+ const stripped = pathname.slice(basePath.length);
22
+ return stripped === '' ? '/' : stripped;
23
+ }
24
+ return pathname;
25
+ }
2
26
  export default function easyWebSeo(options = {}) {
3
27
  return {
4
28
  name: '@easy-web/seo',
5
29
  hooks: {
6
30
  'astro:config:setup': ({ config, updateConfig, injectRoute, logger }) => {
7
- // 1. Validate site URL
8
31
  if (!config.site) {
9
32
  logger.error('@easy-web/seo: astro.config.mjs must set `site` (a full https:// URL). ' +
10
33
  'Example: site: "https://yoursite.example"');
11
34
  throw new Error('@easy-web/seo: `site` is required in astro.config.mjs');
12
35
  }
13
- // 2. Build BCP-47 locale map for sitemap
36
+ const noIndex = options.noIndex ?? false;
37
+ const policy = createCrawlPolicy(noIndex);
14
38
  let sitemapI18n;
15
39
  if (config.i18n && config.i18n.locales.length > 0) {
16
40
  const localeMap = options.sitemapLocales ?? {};
17
41
  if (!options.sitemapLocales) {
18
- // Auto-generate BCP-47 tags: 'de' → 'de-DE', 'en' → 'en-US'
42
+ // Language-only tags, never a guessed region. "uppercase the language"
43
+ // only coincidentally works (de-DE, fr-FR) and invents nonexistent
44
+ // regions otherwise (en-EN, ja-JA, sv-SV), which Google discards.
19
45
  for (const locale of config.i18n.locales) {
20
46
  const id = typeof locale === 'string' ? locale : locale.path;
21
- localeMap[id] = `${id}-${id.toUpperCase()}`;
47
+ localeMap[id] = id;
22
48
  }
23
- logger.warn('@easy-web/seo: auto-generated BCP-47 locale tags (' +
24
- Object.entries(localeMap).map(([k, v]) => `${k}→${v}`).join(', ') +
25
- '). Provide the `sitemapLocales` option for region-specific tags (e.g. { de: "de-DE", en: "en-US" }).');
49
+ logger.warn('@easy-web/seo: no `sitemapLocales` provided, falling back to language-only hreflang tags (' +
50
+ Object.keys(localeMap).join(', ') +
51
+ '). Provide `sitemapLocales` for region-specific tags (e.g. { de: "de-DE", en: "en-US" }).');
26
52
  }
27
53
  sitemapI18n = {
28
54
  defaultLocale: config.i18n.defaultLocale,
29
55
  locales: localeMap,
30
56
  };
31
57
  }
32
- // 3. Compose @astrojs/sitemap via updateConfig
33
- updateConfig({
34
- integrations: [
35
- sitemap({
36
- ...(sitemapI18n ? { i18n: sitemapI18n } : {}),
37
- ...(options.filter ? { filter: options.filter } : {}),
38
- }),
39
- ],
40
- });
41
- // 4. Pass noIndex flag to the robots.txt route handler via env
42
- process.env.EASY_WEB_SEO_NO_INDEX = String(options.noIndex ?? false);
43
- // 5. Inject dynamic robots.txt route
58
+ const declaredGroups = options.localizedPaths ?? [];
59
+ if (declaredGroups.length > 0 && !sitemapI18n) {
60
+ throw new Error('@easy-web/seo: `localizedPaths` requires `i18n` to be configured in astro.config.mjs.');
61
+ }
62
+ const localeIds = localeIdsOf(config);
63
+ const problems = validateLocalizedPaths(declaredGroups, localeIds);
64
+ if (problems.length > 0) {
65
+ throw new Error(`@easy-web/seo: invalid \`localizedPaths\`:\n- ${problems.join('\n- ')}`);
66
+ }
67
+ const linksByUrl = new Map();
68
+ const declaredUrls = new Set();
69
+ for (const group of declaredGroups) {
70
+ const links = localeIds
71
+ .filter((locale) => group[locale] !== undefined)
72
+ .map((locale) => ({
73
+ lang: sitemapI18n.locales[locale],
74
+ url: toOutputUrl(group[locale], config),
75
+ }));
76
+ for (const link of links) {
77
+ linksByUrl.set(link.url, links);
78
+ declaredUrls.add(link.url);
79
+ }
80
+ }
81
+ const seenUrls = new Set();
82
+ const conflicts = [];
83
+ if (policy.sitemap) {
84
+ const sitemapIntegration = sitemap({
85
+ ...(sitemapI18n ? { i18n: sitemapI18n } : {}),
86
+ namespaces: { xhtml: true },
87
+ filter: (page) => !isDisallowedPath(pathnameOf(page, config), policy) &&
88
+ (options.filter?.(page) ?? true),
89
+ serialize: (item) => {
90
+ const declared = linksByUrl.get(item.url);
91
+ if (declared) {
92
+ seenUrls.add(item.url);
93
+ // Replace, never merge: every member of a group must carry the
94
+ // same complete, reciprocal set or Google rejects the cluster.
95
+ return { ...item, links: [...declared] };
96
+ }
97
+ for (const link of item.links ?? []) {
98
+ if (linksByUrl.has(link.url)) {
99
+ conflicts.push(`${item.url} was auto-paired with ${link.url}, which is already claimed by a localizedPaths group.`);
100
+ }
101
+ }
102
+ return item;
103
+ },
104
+ });
105
+ const validatorIntegration = {
106
+ name: '@easy-web/seo:localized-paths-validation',
107
+ hooks: {
108
+ 'astro:build:done': () => {
109
+ const missing = [...declaredUrls].filter((url) => !seenUrls.has(url));
110
+ const failures = [
111
+ ...missing.map((url) => `${url} is declared in localizedPaths but no such page was built. Check for a typo or a removed route.`),
112
+ ...conflicts,
113
+ ];
114
+ if (failures.length > 0) {
115
+ throw new Error(`@easy-web/seo: invalid \`localizedPaths\`:\n- ${failures.join('\n- ')}`);
116
+ }
117
+ },
118
+ },
119
+ };
120
+ // Order matters: @astrojs/sitemap runs serialize inside its own
121
+ // astro:build:done, and it swallows errors thrown from serialize, so
122
+ // validation has to run in a later hook to fail the build.
123
+ updateConfig({ integrations: [sitemapIntegration, validatorIntegration] });
124
+ }
125
+ process.env.EASY_WEB_SEO_NO_INDEX = String(noIndex);
126
+ // <SeoHead> is a component and cannot read astro.config, so the style
127
+ // the sitemap uses is published here for it to reuse. Both surfaces
128
+ // therefore derive the canonical URL form from one resolver.
129
+ process.env.EASY_WEB_SEO_TRAILING_SLASH = resolveTrailingSlash(config);
44
130
  injectRoute({
45
131
  pattern: '/robots.txt',
46
132
  entrypoint: new URL('./routes/robots-txt.js', import.meta.url),
@@ -50,4 +136,5 @@ export default function easyWebSeo(options = {}) {
50
136
  },
51
137
  };
52
138
  }
139
+ export { createCrawlPolicy, isDisallowedPath } from './crawl-policy.js';
53
140
  //# 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":"AACA,OAAO,OAAO,MAAM,kBAAkB,CAAC;AAQvC,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,UAAmB,EAAE;IACtD,OAAO;QACL,IAAI,EAAE,eAAe;QACrB,KAAK,EAAE;YACL,oBAAoB,EAAE,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,EAAE;gBACtE,uBAAuB;gBACvB,IAAI,CAAC,MAAM,CAAC,IAAI,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AiB,EAAE,gBAAgB,EAAoB,MAAM,mBAAmB,CAAA"}
@@ -1,15 +1,3 @@
1
1
  import type { APIRoute } from 'astro';
2
- /**
3
- * Dynamic robots.txt endpoint injected by @easy-web/seo integration.
4
- *
5
- * Behavior:
6
- * - noIndex mode (process.env.EASY_WEB_SEO_NO_INDEX === 'true'):
7
- * Emits Disallow: / (blocks all crawlers — for auth-gated/staging sites)
8
- * - Public mode (default):
9
- * Emits Disallow: /admin/, Allow: /, Sitemap: <site>/sitemap-index.xml
10
- *
11
- * The noIndex flag is set by the integration factory in astro:config:setup
12
- * via process.env.EASY_WEB_SEO_NO_INDEX before this route is injected.
13
- */
14
2
  export declare const GET: APIRoute;
15
3
  //# sourceMappingURL=robots-txt.d.ts.map
@@ -1 +1 @@
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,CAAC;AAEtC;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,GAAG,EAAE,QA2BjB,CAAC"}
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,37 +1,27 @@
1
- /**
2
- * Dynamic robots.txt endpoint injected by @easy-web/seo integration.
3
- *
4
- * Behavior:
5
- * - noIndex mode (process.env.EASY_WEB_SEO_NO_INDEX === 'true'):
6
- * Emits Disallow: / (blocks all crawlers — for auth-gated/staging sites)
7
- * - Public mode (default):
8
- * Emits Disallow: /admin/, Allow: /, Sitemap: <site>/sitemap-index.xml
9
- *
10
- * The noIndex flag is set by the integration factory in astro:config:setup
11
- * via process.env.EASY_WEB_SEO_NO_INDEX before this route is injected.
12
- */
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
+ }
13
16
  export const GET = ({ site }) => {
14
- const noIndex = process.env.EASY_WEB_SEO_NO_INDEX === 'true';
15
17
  if (!site) {
16
- // Fail safe: if site is not configured, block all crawlers
17
- return new Response('User-agent: *\nDisallow: /\n', {
18
+ return new Response(render(createCrawlPolicy(true), undefined), {
18
19
  status: 500,
19
20
  headers: { 'Content-Type': 'text/plain; charset=utf-8' },
20
21
  });
21
22
  }
22
- const lines = ['User-agent: *'];
23
- if (noIndex) {
24
- // Auth-gated / staging / dev site — block all crawlers
25
- lines.push('Disallow: /');
26
- }
27
- else {
28
- // Public site — allow all, block CMS admin, link sitemap
29
- lines.push('Disallow: /admin/');
30
- lines.push('Allow: /');
31
- lines.push('');
32
- lines.push(`Sitemap: ${new URL('sitemap-index.xml', site).href}`);
33
- }
34
- return new Response(lines.join('\n') + '\n', {
23
+ const policy = createCrawlPolicy(process.env.EASY_WEB_SEO_NO_INDEX === 'true');
24
+ return new Response(render(policy, site), {
35
25
  headers: { 'Content-Type': 'text/plain; charset=utf-8' },
36
26
  });
37
27
  };
@@ -1 +1 @@
1
- {"version":3,"file":"robots-txt.js","sourceRoot":"","sources":["../../src/routes/robots-txt.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,GAAG,GAAa,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;IACxC,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,qBAAqB,KAAK,MAAM,CAAC;IAE7D,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,2DAA2D;Q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,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/package.json CHANGED
@@ -1,60 +1,59 @@
1
- {
2
- "name": "@easy-web/seo",
3
- "version": "1.0.0",
4
- "type": "module",
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
- "keywords": [
7
- "astro-integration",
8
- "astro-component",
9
- "seo",
10
- "sitemap",
11
- "robots.txt",
12
- "opengraph",
13
- "hreflang",
14
- "canonical"
15
- ],
16
- "exports": {
17
- ".": {
18
- "types": "./dist/index.d.ts",
19
- "import": "./dist/index.js"
20
- },
21
- "./components/*": "./src/components/*.astro"
22
- },
23
- "files": [
24
- "dist",
25
- "src/components",
26
- "src/routes",
27
- "README.md"
28
- ],
29
- "sideEffects": false,
30
- "scripts": {
31
- "build": "tsc -p tsconfig.build.json",
32
- "test": "vitest run",
33
- "lint": "eslint src",
34
- "typecheck": "tsc --noEmit"
35
- },
36
- "peerDependencies": {
37
- "astro": ">=6.0.0 <8.0.0",
38
- "@easy-web/i18n": ">=1.0.0"
39
- },
40
- "dependencies": {
41
- "@astrojs/sitemap": "^3.7.3"
42
- },
43
- "devDependencies": {
44
- "astro": "^6.4.0",
45
- "@easy-web/i18n": "workspace:*",
46
- "vitest": "^3.2.4",
47
- "@vitest/coverage-v8": "^3.2.4",
48
- "typescript": "^5.5.0"
49
- },
50
- "publishConfig": {
51
- "access": "public",
52
- "provenance": true
53
- },
54
- "repository": {
55
- "type": "git",
56
- "url": "https://github.com/achimismaili/easy-web.git",
57
- "directory": "packages/seo"
58
- },
59
- "license": "MIT"
60
- }
1
+ {
2
+ "name": "@easy-web/seo",
3
+ "version": "1.1.0",
4
+ "type": "module",
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
+ "keywords": [
7
+ "astro-integration",
8
+ "astro-component",
9
+ "seo",
10
+ "sitemap",
11
+ "robots.txt",
12
+ "opengraph",
13
+ "hreflang",
14
+ "canonical"
15
+ ],
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "import": "./dist/index.js"
20
+ },
21
+ "./components/*": "./src/components/*.astro"
22
+ },
23
+ "files": [
24
+ "dist",
25
+ "src/components",
26
+ "src/routes",
27
+ "README.md"
28
+ ],
29
+ "sideEffects": false,
30
+ "peerDependencies": {
31
+ "astro": ">=6.0.0 <8.0.0"
32
+ },
33
+ "dependencies": {
34
+ "@astrojs/sitemap": "^3.7.3",
35
+ "@easy-web/i18n": "1.1.0"
36
+ },
37
+ "devDependencies": {
38
+ "astro": "^6.4.0",
39
+ "vitest": "^3.2.4",
40
+ "@vitest/coverage-v8": "^3.2.4",
41
+ "typescript": "^5.5.0"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public",
45
+ "provenance": true
46
+ },
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "https://github.com/achimismaili/easy-web.git",
50
+ "directory": "packages/seo"
51
+ },
52
+ "license": "MIT",
53
+ "scripts": {
54
+ "build": "tsc -p tsconfig.build.json",
55
+ "test": "vitest run",
56
+ "lint": "eslint src",
57
+ "typecheck": "tsc --noEmit"
58
+ }
59
+ }
@@ -1,76 +1,87 @@
1
- ---
2
- export interface AlternateLink {
3
- hreflang: string;
4
- href: string;
5
- }
6
-
7
- export interface Props {
8
- title: string;
9
- description?: string;
10
- pathname: string;
11
- locale: string;
12
- siteName: string;
13
- ogType?: 'website' | 'article';
14
- ogImage?: string;
15
- themeColor?: string;
16
- manifest?: string;
17
- noIndex?: boolean;
18
- twitterCard?: 'summary' | 'summary_large_image';
19
- twitterSite?: string;
20
- alternates?: AlternateLink[];
21
- }
22
-
23
- const {
24
- title,
25
- description,
26
- pathname,
27
- locale,
28
- siteName,
29
- ogType = 'website',
30
- ogImage,
31
- themeColor,
32
- manifest,
33
- noIndex = false,
34
- twitterCard = 'summary',
35
- twitterSite,
36
- alternates = [],
37
- } = Astro.props;
38
-
39
- const site = Astro.site;
40
- if (!site) {
41
- throw new Error(
42
- '@easy-web/seo: <SeoHead> requires astro.config.mjs to set `site` (a full https:// URL).'
43
- );
44
- }
45
-
46
- const canonical = new URL(pathname, site).href;
47
- const absoluteOgImage = ogImage ? new URL(ogImage, site).href : undefined;
48
- // Map locale to OG locale format: 'de' → 'de_DE', 'en' → 'en_US'
49
- const ogLocale = locale === 'en' ? 'en_US' : locale === 'de' ? 'de_DE' : locale.replace('-', '_');
50
- const ogLocaleAlternate = locale === 'en' ? 'de_DE' : 'en_US';
51
- ---
52
- <title>{title}</title>
53
- {description && <meta name="description" content={description} />}
54
- <link rel="canonical" href={canonical} />
55
- {noIndex && <meta name="robots" content="noindex, nofollow" />}
56
- {themeColor && <meta name="theme-color" content={themeColor} />}
57
- {manifest && <link rel="manifest" href={manifest} />}
58
- <!-- Open Graph -->
59
- <meta property="og:title" content={title} />
60
- {description && <meta property="og:description" content={description} />}
61
- <meta property="og:url" content={canonical} />
62
- <meta property="og:type" content={ogType} />
63
- <meta property="og:locale" content={ogLocale} />
64
- <meta property="og:locale:alternate" content={ogLocaleAlternate} />
65
- <meta property="og:site_name" content={siteName} />
66
- {absoluteOgImage && <meta property="og:image" content={absoluteOgImage} />}
67
- <!-- Twitter Cards -->
68
- <meta name="twitter:card" content={twitterCard} />
69
- <meta name="twitter:title" content={title} />
70
- {description && <meta name="twitter:description" content={description} />}
71
- {absoluteOgImage && <meta name="twitter:image" content={absoluteOgImage} />}
72
- {twitterSite && <meta name="twitter:site" content={twitterSite} />}
73
- <!-- hreflang alternates -->
74
- {alternates.map((link) => (
75
- <link rel="alternate" hreflang={link.hreflang} href={link.href} />
76
- ))}
1
+ ---
2
+ import { toServedPath, type TrailingSlash } from '@easy-web/i18n';
3
+
4
+ export interface AlternateLink {
5
+ hreflang: string;
6
+ href: string;
7
+ }
8
+
9
+ export interface Props {
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 = false,
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 canonical = new URL(toServedPath(pathname, servedStyle), site).href;
58
+ const absoluteOgImage = ogImage ? new URL(ogImage, site).href : undefined;
59
+ // Map locale to OG locale format: 'de' → 'de_DE', 'en' → 'en_US'
60
+ const ogLocale = locale === 'en' ? 'en_US' : locale === 'de' ? 'de_DE' : locale.replace('-', '_');
61
+ const ogLocaleAlternate = locale === 'en' ? 'de_DE' : 'en_US';
62
+ ---
63
+ <title>{title}</title>
64
+ {description && <meta name="description" content={description} />}
65
+ <link rel="canonical" href={canonical} />
66
+ {noIndex && <meta name="robots" content="noindex, nofollow" />}
67
+ {themeColor && <meta name="theme-color" content={themeColor} />}
68
+ {manifest && <link rel="manifest" href={manifest} />}
69
+ <!-- Open Graph -->
70
+ <meta property="og:title" content={title} />
71
+ {description && <meta property="og:description" content={description} />}
72
+ <meta property="og:url" content={canonical} />
73
+ <meta property="og:type" content={ogType} />
74
+ <meta property="og:locale" content={ogLocale} />
75
+ <meta property="og:locale:alternate" content={ogLocaleAlternate} />
76
+ <meta property="og:site_name" content={siteName} />
77
+ {absoluteOgImage && <meta property="og:image" content={absoluteOgImage} />}
78
+ <!-- Twitter Cards -->
79
+ <meta name="twitter:card" content={twitterCard} />
80
+ <meta name="twitter:title" content={title} />
81
+ {description && <meta name="twitter:description" content={description} />}
82
+ {absoluteOgImage && <meta name="twitter:image" content={absoluteOgImage} />}
83
+ {twitterSite && <meta name="twitter:site" content={twitterSite} />}
84
+ <!-- hreflang alternates -->
85
+ {alternates.map((link) => (
86
+ <link rel="alternate" hreflang={link.hreflang} href={link.href} />
87
+ ))}
@@ -1,42 +1,36 @@
1
- import type { APIRoute } from 'astro';
2
-
3
- /**
4
- * Dynamic robots.txt endpoint injected by @easy-web/seo integration.
5
- *
6
- * Behavior:
7
- * - noIndex mode (process.env.EASY_WEB_SEO_NO_INDEX === 'true'):
8
- * Emits Disallow: / (blocks all crawlers — for auth-gated/staging sites)
9
- * - Public mode (default):
10
- * Emits Disallow: /admin/, Allow: /, Sitemap: <site>/sitemap-index.xml
11
- *
12
- * The noIndex flag is set by the integration factory in astro:config:setup
13
- * via process.env.EASY_WEB_SEO_NO_INDEX before this route is injected.
14
- */
15
- export const GET: APIRoute = ({ site }) => {
16
- const noIndex = process.env.EASY_WEB_SEO_NO_INDEX === 'true';
17
-
18
- if (!site) {
19
- // Fail safe: if site is not configured, block all crawlers
20
- return new Response('User-agent: *\nDisallow: /\n', {
21
- status: 500,
22
- headers: { 'Content-Type': 'text/plain; charset=utf-8' },
23
- });
24
- }
25
-
26
- const lines: string[] = ['User-agent: *'];
27
-
28
- if (noIndex) {
29
- // Auth-gated / staging / dev site — block all crawlers
30
- lines.push('Disallow: /');
31
- } else {
32
- // Public site — allow all, block CMS admin, link sitemap
33
- lines.push('Disallow: /admin/');
34
- lines.push('Allow: /');
35
- lines.push('');
36
- lines.push(`Sitemap: ${new URL('sitemap-index.xml', site).href}`);
37
- }
38
-
39
- return new Response(lines.join('\n') + '\n', {
40
- headers: { 'Content-Type': 'text/plain; charset=utf-8' },
41
- });
42
- };
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
+ }