@hagicode/hagilight 0.3.1 → 0.3.2-dev.55.1.1e29eba
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/integration.mjs +35 -0
- package/package.json +3 -2
- package/robots.txt.ts +8 -0
package/integration.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { existsSync, readdirSync, statSync } from 'node:fs';
|
|
2
2
|
import { fileURLToPath } from 'node:url';
|
|
3
3
|
import { dirname, extname, isAbsolute, resolve, win32 } from 'node:path';
|
|
4
|
+
import sitemap from '@astrojs/sitemap';
|
|
4
5
|
import { resolveRssLocales } from './rss-locales.mjs';
|
|
5
6
|
|
|
6
7
|
export const HAGILIGHT_RSS_OWNER = Symbol.for('@hagicode/hagilight/rss-owner');
|
|
@@ -11,6 +12,40 @@ const PAGE_SOURCE_EXTENSIONS = new Set(['.astro', '.html', '.js', '.jsx', '.md',
|
|
|
11
12
|
const registeredRssOwners = globalThis[RSS_OWNER_REGISTRY] ?? new Map();
|
|
12
13
|
globalThis[RSS_OWNER_REGISTRY] = registeredRssOwners;
|
|
13
14
|
|
|
15
|
+
export function hagilight({ enabled = true } = {}) {
|
|
16
|
+
if (typeof enabled !== 'boolean') {
|
|
17
|
+
throw new TypeError('Hagilight sitemap and robots enabled option must be a boolean.');
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
name: '@hagicode/hagilight:discovery',
|
|
21
|
+
hooks: {
|
|
22
|
+
'astro:config:setup'({ config, injectRoute, updateConfig }) {
|
|
23
|
+
if (!enabled) return;
|
|
24
|
+
if (!config.site) {
|
|
25
|
+
throw new Error('Hagilight sitemap and robots require an absolute Astro site URL. Set `site` in astro.config.mjs.');
|
|
26
|
+
}
|
|
27
|
+
const integrations = config.integrations ?? [];
|
|
28
|
+
if (!integrations.some(({ name }) => name === '@astrojs/sitemap' || name === '@astrojs/starlight')) {
|
|
29
|
+
updateConfig({ integrations: [sitemap()] });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const pageRoot = resolve(fileURLToPath(config.srcDir), 'pages');
|
|
33
|
+
const publicRoot = fileURLToPath(config.publicDir);
|
|
34
|
+
const hasRobotsPage = existsSync(pageRoot) && readdirSync(pageRoot).some((name) =>
|
|
35
|
+
/^robots\.txt\.(?:astro|html|js|jsx|md|mdx|ts|tsx)$/u.test(name)
|
|
36
|
+
|| name === 'robots.txt');
|
|
37
|
+
if (!hasRobotsPage && !existsSync(resolve(publicRoot, 'robots.txt'))) {
|
|
38
|
+
injectRoute({
|
|
39
|
+
pattern: '/robots.txt',
|
|
40
|
+
entrypoint: fileURLToPath(new URL('./robots.txt.ts', import.meta.url)),
|
|
41
|
+
prerender: true,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
14
49
|
export function registerStarlightRssOwner(enabled) {
|
|
15
50
|
const token = Symbol('starlight-rss-owner');
|
|
16
51
|
registeredRssOwners.set(token, { package: 'starlight', enabled });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hagicode/hagilight",
|
|
3
|
-
"version": "0.3.1",
|
|
3
|
+
"version": "0.3.2-dev.55.1.1e29eba",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Shared Astro components for HagiCode sites",
|
|
6
6
|
"repository": {
|
|
@@ -44,7 +44,8 @@
|
|
|
44
44
|
"astro": "^6.0.7 || ^7.3.5"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@astrojs/rss": "^4.0.19"
|
|
47
|
+
"@astrojs/rss": "^4.0.19",
|
|
48
|
+
"@astrojs/sitemap": "^3.7.4"
|
|
48
49
|
},
|
|
49
50
|
"keywords": [
|
|
50
51
|
"astro-component",
|
package/robots.txt.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const prerender = true;
|
|
2
|
+
|
|
3
|
+
export function GET({ site }: { site: URL }) {
|
|
4
|
+
const sitemap = new URL('sitemap-index.xml', new URL(import.meta.env.BASE_URL, site));
|
|
5
|
+
return new Response(`User-agent: *\nAllow: /\nSitemap: ${sitemap.href}\n`, {
|
|
6
|
+
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
|
|
7
|
+
});
|
|
8
|
+
}
|