@hagicode/hagilight-core 0.21.1-dev.204.1.c72b9e4 → 0.21.1-dev.206.1.e881788

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 CHANGED
@@ -37,6 +37,17 @@ import { resolveSiteLinks } from '@hagicode/hagilight-core/links';
37
37
  const links = resolveSiteLinks('en-US');
38
38
  ```
39
39
 
40
+ ## Agent skills
41
+
42
+ This package ships agent skills for building a site with hagilight, under `node_modules/@hagicode/hagilight-core/skills/`:
43
+
44
+ - `hagilight/SKILL.md` is the entry point and routes to the guides below.
45
+ - `hagilight-site-from-scratch/SKILL.md` covers the shared start for an empty project.
46
+ - `hagilight-docs-site/SKILL.md` covers documentation sites on Starlight or Docusaurus.
47
+ - `hagilight-official-website/SKILL.md` covers official websites on plain Astro.
48
+
49
+ Not every agent discovers skills under `node_modules`. Point your agent at the entry skill, for example by asking it to read `node_modules/@hagicode/hagilight-core/skills/hagilight/SKILL.md` before it sets up a site.
50
+
40
51
  ## Footer avatar
41
52
 
42
53
  The footer brand block shows one decorative HagiCode avatar beside the headline. `avatar` defaults to `true`; `avatar={false}` removes the element and its request. The default is `assets/footer/avatar.avif` (128 px, with `avatar.webp` as the fallback) in a 64 px box, hidden below a 360 px container. `randomAvatar` defaults to `true`: the box becomes a 112 × 76 px stage, and once the footer nears the viewport the browser picks 6 distinct entries of the `cat-head-gallery` pool listed in `assets/footer/manifest.json`, preloads them, and deals three as a fan (the default fades out under them). All six loaded: every 3.6 seconds the left card leaves, the others shift left and a waiting card enters on the right, paused while the footer is off screen or the tab is hidden. Fewer than six loaded (or `prefers-reduced-motion: reduce`, which fetches only three) gives a still fan of three; fewer than three keeps the default. The browser picker is `@hagicode/hagilight-core/random-image` (`mountRandomFans`; browser-safe), preloads with a plain `Image()`, not `fetch`, waits up to 3 seconds per image, and makes no request under a data-saver preference. The slot carries `data-random-fan` (the same validated pool list); the showcase illustration in the Starlight article footer uses the same fan; the single-image swap (`data-random-pool`, `mountRandomImages`) stays exported for other slots. `randomAvatar={false}` ships no pool list and no picker script.
@@ -220,7 +220,7 @@
220
220
  "id": "opencode-vs-hagicode-section-5-steps",
221
221
  "type": "bullet-list",
222
222
  "items": [
223
- "Install OpenCode (for example curl -fsSL https://opencode.ai/install | bash, or npm install -g opencode-ai) and run /connect to add a provider.",
223
+ "Install OpenCode (for example curl -fsSL https://opencode.ai/v2/install | bash, or npm install -g @opencode/cli) and run /connect to add a provider.",
224
224
  "Install HagiCode Desktop for Windows, macOS or Linux.",
225
225
  "In HagiCode, choose OpenCode as the Agent CLI and pick one of your configured models.",
226
226
  "Open a repository and start a session or a proposal.",
@@ -311,7 +311,7 @@
311
311
  },
312
312
  {
313
313
  "question": "How do I install OpenCode?",
314
- "answer": "Run curl -fsSL https://opencode.ai/install | bash, or npm install -g opencode-ai, or brew install anomalyco/tap/opencode. The docs note these methods install OpenCode 1, so check opencode.ai/docs for the current version."
314
+ "answer": "Run curl -fsSL https://opencode.ai/v2/install | bash, or npm install -g @opencode/cli, or brew install anomalyco/tap/opencode-v2. These install OpenCode 2; check opencode.ai/docs for the current version."
315
315
  },
316
316
  {
317
317
  "question": "Can I use OpenCode with HagiCode?",
@@ -220,7 +220,7 @@
220
220
  "id": "opencode-vs-hagicode-section-5-steps",
221
221
  "type": "bullet-list",
222
222
  "items": [
223
- "安装 OpenCode(例如 curl -fsSL https://opencode.ai/install | bash,或 npm install -g opencode-ai),然后运行 /connect 添加供应商。",
223
+ "安装 OpenCode(例如 curl -fsSL https://opencode.ai/v2/install | bash,或 npm install -g @opencode/cli),然后运行 /connect 添加供应商。",
224
224
  "安装适用于 Windows、macOS 或 Linux 的 HagiCode Desktop。",
225
225
  "在 HagiCode 里把 OpenCode 选为 Agent CLI,并从你已配置的模型中选一个。",
226
226
  "打开一个仓库,开始会话或提案。",
@@ -311,7 +311,7 @@
311
311
  },
312
312
  {
313
313
  "question": "怎么安装 OpenCode?",
314
- "answer": "运行 curl -fsSL https://opencode.ai/install | bash,或 npm install -g opencode-ai,或 brew install anomalyco/tap/opencode。文档提示这些方式安装的是 OpenCode 1,当前版本请查看 opencode.ai/docs。"
314
+ "answer": "运行 curl -fsSL https://opencode.ai/v2/install | bash,或 npm install -g @opencode/cli,或 brew install anomalyco/tap/opencode-v2。这些方式安装的是 OpenCode 2,当前版本请查看 opencode.ai/docs。"
315
315
  },
316
316
  {
317
317
  "question": "OpenCode 能和 HagiCode 一起用吗?",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hagicode/hagilight-core",
3
- "version": "0.21.1-dev.204.1.c72b9e4",
3
+ "version": "0.21.1-dev.206.1.e881788",
4
4
  "type": "module",
5
5
  "description": "Shared TypeScript utilities, components, and assets for HagiCode Astro and Starlight sites",
6
6
  "repository": {
@@ -184,6 +184,7 @@
184
184
  "dist/**/*.json",
185
185
  "data/**/*.json",
186
186
  "assets/**/*",
187
+ "skills",
187
188
  "*.astro",
188
189
  "logo.png",
189
190
  "favicon.ico"
@@ -0,0 +1,25 @@
1
+ ---
2
+ name: hagilight
3
+ description: "Use when starting, setting up or changing a website built with the hagilight packages: a new site from an empty project, a documentation site on Starlight or Docusaurus, or an official website on plain Astro. Routes to the guide for the site type."
4
+ ---
5
+
6
+ # Hagilight
7
+
8
+ Entry point for building a site with `@hagicode/hagilight`. This skill does no setup itself. It sends you to the guide that matches what exists, then the guide does the work.
9
+
10
+ ## Route by what exists
11
+
12
+ | Situation | Read next |
13
+ | --- | --- |
14
+ | No site yet, or an empty project | [`hagilight-site-from-scratch`](../hagilight-site-from-scratch/SKILL.md): the shared start. It asks the site type and hands off. |
15
+ | A documentation site (docs, wiki, or release notes), or a site that already uses Starlight or Docusaurus | [`hagilight-docs-site`](../hagilight-docs-site/SKILL.md): plugin-driven setup for Starlight or Docusaurus. |
16
+ | An official website on plain Astro, where the maintainer writes the layout | [`hagilight-official-website`](../hagilight-official-website/SKILL.md): `hagilight()` with the head and footer components placed by hand. |
17
+
18
+ If the site type is unclear, ask one question: does a plugin own the header, footer and locale chooser (documentation site), or does the maintainer write the layout (official website)? Then use the matching row.
19
+
20
+ ## Rules that apply to every site type
21
+
22
+ - A site is one type or the other. Do not install the Starlight or Docusaurus plugin into an official website, and do not write a custom layout around a documentation plugin.
23
+ - Install the feature package and `@hagicode/hagilight-core` at one exact version. The peer ranges and the pinning rule are in [`versions.md`](../hagilight-site-from-scratch/references/versions.md).
24
+ - Option tables live in each package's README in `node_modules`. Read them there rather than copying them into the site.
25
+ - Analytics load only in production builds. Development pages carry no analytics loader.
@@ -0,0 +1,7 @@
1
+ interface:
2
+ display_name: "Hagilight"
3
+ short_description: "Start or change a website built with the hagilight packages."
4
+ default_prompt: "Use $hagilight to set up a hagilight site, starting from the shared guide and then the guide for the site type."
5
+
6
+ policy:
7
+ allow_implicit_invocation: true
@@ -0,0 +1,36 @@
1
+ ---
2
+ name: hagilight-docs-site
3
+ description: "Use when building or changing a documentation site with hagilight on Starlight or Docusaurus, where the plugin owns the header, footer, locale chooser and 404 page. Covers the plugin-driven model, the override rules that make a setup fail, and the choice between the two frameworks."
4
+ ---
5
+
6
+ # Hagilight documentation site
7
+
8
+ A documentation site uses a hagilight plugin. The plugin owns the page chrome, so the site configures the plugin and does not replace the chrome. The shared start, including the exact-version install and the build check, is in [`hagilight-site-from-scratch`](../hagilight-site-from-scratch/SKILL.md). Follow it first.
9
+
10
+ ## Choose the framework
11
+
12
+ - Starlight: `@hagicode/hagilight-starlight`, read [`references/starlight.md`](references/starlight.md). Most existing documentation sites in this organization use Starlight.
13
+ - Docusaurus: `@hagicode/hagilight-docusaurus`, read [`references/docusaurus.md`](references/docusaurus.md). Pick it only when the site already runs Docusaurus. Moving a Docusaurus site to Starlight is a rewrite, not a setup step.
14
+
15
+ Do not use both plugins on one site.
16
+
17
+ ## What the plugin owns
18
+
19
+ Starlight plugin: the header, footer, locale chooser, content-width control, theme picker, 404 page, SEO head, RSS feeds, analytics and AI disclosures.
20
+
21
+ Docusaurus plugin: the footer, promotion banner, analytics, SEO head tags and JSON-LD, the sitemap, robots and RSS discovery files, and the locale catalog.
22
+
23
+ Configure these through the plugin's options. Do not rebuild them in the site.
24
+
25
+ ## Override rules
26
+
27
+ These rules decide whether a setup builds.
28
+
29
+ - Starlight rejects a site that already overrides `Footer`, `components.Header`, `PageTitle` or `MarkdownContent`. The plugin fails the build with an error that names the component. Remove the override rather than keeping both. If you need the header of your own, set `header: { enabled: false }` in the plugin options and compose `@hagicode/hagilight-starlight/Header` yourself.
30
+ - Docusaurus does not fail on a swizzled `Footer` or `SiteMetadata`. It warns during the build. A swizzled `src/theme/Footer` is a problem while `footer` is enabled, and a swizzled `src/theme/SiteMetadata` is a problem while `seo` is enabled. Remove the swizzle, or disable the matching Hagilight feature. Do not leave both in place.
31
+
32
+ ## Keep the shared steps
33
+
34
+ - Keep the site URL and locales in the framework config, as the from-scratch guide says. The locale list must match the plugin's catalog.
35
+ - Analytics and tagged links follow [`analytics-and-links.md`](../hagilight-site-from-scratch/references/analytics-and-links.md). Both plugins configure Google Analytics, 51LA and PostHog through their own `analytics` option.
36
+ - The build check follows [`build-checks.md`](../hagilight-site-from-scratch/references/build-checks.md) for the framework you chose.
@@ -0,0 +1,99 @@
1
+ # Docusaurus setup
2
+
3
+ Use this reference with the `hagilight-docs-site` skill when the documentation site runs on Docusaurus 3. Install the plugin and core at one exact version, as the from-scratch guide says. The plugin's peer ranges are `@docusaurus/core` and `@docusaurus/theme-classic` at `^3.9.2`, and React `^18 || ^19`; the table in [`versions.md`](../../hagilight-site-from-scratch/references/versions.md) is the source.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install --save-exact @hagicode/hagilight-core@<exact-version> @hagicode/hagilight-docusaurus@<exact-version>
9
+ npm install @docusaurus/core @docusaurus/theme-classic @docusaurus/preset-classic @docusaurus/types react react-dom
10
+ ```
11
+
12
+ Declare every package your config imports, including `@docusaurus/types` and `@docusaurus/preset-classic`. The package manager does not hoist them for you.
13
+
14
+ ## Register the plugin and the locales
15
+
16
+ The plugin is the named export `hagilightDocusaurus`. Its locale catalog is the `i18n` export from `@hagicode/hagilight-docusaurus/locales`, so take the locale settings from there.
17
+
18
+ ```ts
19
+ // docusaurus.config.ts
20
+ import type { Config } from '@docusaurus/types';
21
+ import { hagilightDocusaurus } from '@hagicode/hagilight-docusaurus';
22
+ import { i18n } from '@hagicode/hagilight-docusaurus/locales';
23
+
24
+ const config: Config = {
25
+ title: 'Example docs',
26
+ url: 'https://docs.example.com',
27
+ baseUrl: '/',
28
+ onBrokenLinks: 'throw',
29
+ onBrokenMarkdownLinks: 'throw',
30
+ i18n,
31
+ presets: [
32
+ [
33
+ 'classic',
34
+ {
35
+ docs: { sidebarPath: './sidebars.ts', routeBasePath: 'docs' },
36
+ blog: false,
37
+ theme: { customCss: './src/css/custom.css' },
38
+ // The plugin writes the sitemap fallback when the official sitemap plugin is not loaded.
39
+ sitemap: false,
40
+ },
41
+ ],
42
+ ],
43
+ plugins: [
44
+ hagilightDocusaurus({
45
+ seo: {
46
+ image: '/img/social-card.png',
47
+ organization: {
48
+ name: 'Example',
49
+ url: 'https://example.com',
50
+ logo: 'https://docs.example.com/img/logo.svg',
51
+ },
52
+ },
53
+ analytics: {
54
+ googleAnalytics: { measurementId: 'G-XXXXXXXXXX' },
55
+ fiftyOneLa: { enabled: false },
56
+ },
57
+ }),
58
+ ],
59
+ themeConfig: {
60
+ image: 'img/social-card.png',
61
+ navbar: {
62
+ items: [
63
+ { type: 'docSidebar', sidebarId: 'docs', position: 'left', label: 'Docs' },
64
+ { type: 'localeDropdown', position: 'right' },
65
+ ],
66
+ },
67
+ },
68
+ };
69
+
70
+ export default config;
71
+ ```
72
+
73
+ Notes on the snippet:
74
+
75
+ - A locale that is not in the Hagilight catalog gets a warning and no label or `lang` check. Use catalog locales, or turn `languageSelector` off.
76
+ - With more than one locale, the language switcher needs a `localeDropdown` item in `themeConfig.navbar.items`. Without it the plugin warns.
77
+ - The position of `hagilightDocusaurus()` in `plugins` does not change the result. The sitemap check looks at every loaded plugin.
78
+
79
+ ## Swizzles: the plugin warns, it does not stop the build
80
+
81
+ Docusaurus lets a site replace a theme component by swizzling it into `src/theme/`. The Hagilight plugin owns two of them. A swizzle left in place still builds, so the warning is the only signal. Treat each warning as a failed check.
82
+
83
+ - `src/theme/Footer` while `footer` is enabled: remove the swizzle, or set `footer: { enabled: false }` and keep the site's own footer.
84
+ - `src/theme/SiteMetadata` while `seo` is enabled: remove it, or set `seo: { enabled: false }`.
85
+
86
+ Two more warnings come from settings that conflict with the plugin:
87
+
88
+ - `themeConfig.footer` is set while the Hagilight footer is enabled. The footer links in `themeConfig` are ignored. Remove them.
89
+ - Google Analytics is configured twice, through `themeConfig.gtag` or the official gtag plugin, and through this plugin. Keep only the plugin's `analytics.googleAnalytics`.
90
+
91
+ ## Build and discovery
92
+
93
+ - Build every locale (run `docusaurus build` without `--locale`). `robots.txt` is written only by the default-locale build, and it lists one sitemap per locale. A single-locale build leaves the others out.
94
+ - The discovery files and their rules are in [`build-checks.md`](../../hagilight-site-from-scratch/references/build-checks.md).
95
+
96
+ ## Gotchas
97
+
98
+ - Keep `"type": "module"` out of the site's `package.json`. With it set, the production build fails with `require.resolveWeak is not a function`, because Docusaurus's generated registry needs webpack's CommonJS rewrite during SSR and an ESM-typed package skips it. If the config must be ESM, name it `docusaurus.config.mjs`, as the package README shows.
99
+ - On GitHub Pages, publish a `.nojekyll` file at the root. Without it, the `.well-known` directory is dropped.
@@ -0,0 +1,78 @@
1
+ # Starlight setup
2
+
3
+ Use this reference with the `hagilight-docs-site` skill when the documentation site runs on Starlight. Install the feature package and core at one exact version, as the from-scratch guide says, and use the peer ranges in [`versions.md`](../../hagilight-site-from-scratch/references/versions.md).
4
+
5
+ ## Register the plugin and the locales
6
+
7
+ The plugin is the default export of `@hagicode/hagilight-starlight`. It goes in `starlight({ plugins: [...] })`. The locale list comes from the plugin's own catalog, so pass `locales` from `@hagicode/hagilight-starlight/locales` and do not write the locale map by hand.
8
+
9
+ ```js
10
+ // astro.config.mjs
11
+ import { defineConfig } from 'astro/config';
12
+ import starlight from '@astrojs/starlight';
13
+ import hagilight from '@hagicode/hagilight-starlight';
14
+ import { locales } from '@hagicode/hagilight-starlight/locales';
15
+
16
+ export default defineConfig({
17
+ site: 'https://docs.example.com',
18
+ integrations: [
19
+ starlight({
20
+ title: 'Docs',
21
+ locales,
22
+ plugins: [hagilight({
23
+ links: { siteId: 'docs-example', siteUrl: 'https://docs.example.com/' },
24
+ seo: {
25
+ organization: { name: 'Example', url: 'https://example.com/' },
26
+ },
27
+ analytics: {
28
+ googleAnalytics: { measurementId: 'G-XXXXXXXXXX' },
29
+ fiftyOneLa: { enabled: false },
30
+ },
31
+ })],
32
+ }),
33
+ ],
34
+ });
35
+ ```
36
+
37
+ `hagilight()` with no options also works: it enables the shared defaults. Pass only the options you need. The full option list, including `aiDisclosures`, `rss` and `contentImages`, is in the `@hagicode/hagilight-starlight` README under `node_modules`.
38
+
39
+ ## Extend the content schema
40
+
41
+ The plugin reads extra frontmatter fields: `hagicodePromotion`, `rss`, `isAITranslation`, `isAIAuthor` and the shared `seo` object. Extend the Starlight docs schema with `hagilightSchema`, so these fields validate on every page.
42
+
43
+ ```ts
44
+ // src/content.config.ts
45
+ import { defineCollection } from 'astro:content';
46
+ import { docsLoader } from '@astrojs/starlight/loaders';
47
+ import { docsSchema } from '@astrojs/starlight/schema';
48
+ import { hagilightSchema } from '@hagicode/hagilight-starlight/schema';
49
+
50
+ export const collections = {
51
+ docs: defineCollection({
52
+ loader: docsLoader(),
53
+ schema: docsSchema({ extend: hagilightSchema }),
54
+ }),
55
+ };
56
+ ```
57
+
58
+ ## Optional: plain-Astro discovery
59
+
60
+ `@hagicode/hagilight/integration` exports the plain-Astro `hagilight()` integration. Add it when the site also needs `robots.txt` and `llms.txt`. The Starlight plugin already writes the sitemap and the RSS feeds, and the plain integration does not write a second sitemap when Starlight owns one.
61
+
62
+ ```js
63
+ // astro.config.mjs (integrations)
64
+ import { hagilight as hagilightDiscovery } from '@hagicode/hagilight/integration';
65
+
66
+ integrations: [
67
+ starlight({ /* ...as above... */ }),
68
+ hagilightDiscovery(),
69
+ ],
70
+ ```
71
+
72
+ Register the discovery integration after the Starlight plugin, as above. Registering it before the plugin also works: the Starlight plugin writes `.well-known/hagilight.metadata.json` in either order, and that file lists `llms.txt` whichever order is used.
73
+
74
+ ## Starlight rules that fail the build
75
+
76
+ - Do not override `Footer`, `components.Header`, `PageTitle` or `MarkdownContent`. The plugin rejects the override and names the component. Remove the override.
77
+ - To replace the header, set `header: { enabled: false }` in the plugin options, then compose `@hagicode/hagilight-starlight/Header` in your own component. For `PageTitle`, set `contentComponents: { pageTitle: false }` and compose `@hagicode/hagilight-starlight/ContentLayoutToggle` into your own `PageTitle`. For `MarkdownContent`, set `contentComponents: { markdownContent: false }` and compose `@hagicode/hagilight-starlight/MarkdownContent` into your own override.
78
+ - A site-owned `components.Head` conflicts with enabled SEO, Google Analytics or PostHog. Disable those features first, as the package README describes, before keeping a custom head.
@@ -0,0 +1,37 @@
1
+ ---
2
+ name: hagilight-official-website
3
+ description: "Use when building or changing an official website on plain Astro with hagilight, where the maintainer owns the layout. Covers the hagilight() integration, the SEOHead and Footer components placed in the layout, locale routing, the analytics composed by hand, and the discovery files. No documentation plugin is involved."
4
+ ---
5
+
6
+ # Hagilight official website
7
+
8
+ An official website is plain Astro. The maintainer writes the layout, the pages and the styles. Hagilight supplies the parts that every HagiCode site shares: the integration, the SEO head, the footer, and the discovery files. A documentation plugin is not part of this setup.
9
+
10
+ Run the shared start first: [`hagilight-site-from-scratch`](../hagilight-site-from-scratch/SKILL.md). It covers the exact-version install, the site URL and the build check. Then continue here.
11
+
12
+ ## Model
13
+
14
+ Register `hagilight()` in the Astro config. Then place `SEOHead` and `Footer` in your own layout, and compose the analytics you use by hand. The rest of the site is yours.
15
+
16
+ ## What the maintainer owns
17
+
18
+ - The layout file, the pages, the styles and the navigation.
19
+ - Where `SEOHead` and `Footer` sit in the layout.
20
+ - The locale routes and the page content.
21
+ - Google Analytics and 51LA, which the layout composes.
22
+
23
+ ## What hagilight supplies
24
+
25
+ - `hagilight()` from `@hagicode/hagilight/integration`: `sitemap-index.xml` and `robots.txt` when the site has none of its own, localized RSS feeds, `llms.txt`, the site metadata file, and PostHog injected into production pages.
26
+ - `hagilightFavicon()` from the same module: the bundled icon, unless the site declares one.
27
+ - `SEOHead` from `@hagicode/hagilight/SEOHead`: the canonical link, title, description, Open Graph and Twitter tags, and a default `WebSite` and `Organization` JSON-LD block.
28
+ - `Footer` from `@hagicode/hagilight/Footer`: the localized footer, with the build line and the package attribution.
29
+
30
+ The integration injects PostHog only. Google Analytics and 51LA are composed in the layout. The details are in [`references/plain-astro.md`](references/plain-astro.md), and the layout placement is in [`references/layout.md`](references/layout.md).
31
+
32
+ ## Rules
33
+
34
+ - Do not install or configure a documentation plugin on an official website. The layout is yours, and a documentation plugin would take over the page chrome.
35
+ - `hagilight()` needs an absolute `site` URL in the Astro config. Set it before anything else.
36
+ - Place `SEOHead` once in `<head>`, and pass the page's `locale`. Place `Footer` once per page, with the same `locale`.
37
+ - Pass `consent` to each analytics component and render one `CookieConsent` when the site uses consent.
@@ -0,0 +1,65 @@
1
+ # Layout: SEOHead, Footer and site metadata
2
+
3
+ Use this reference with the `hagilight-official-website` skill. The layout is yours. Hagilight supplies the head and footer components, and the layout decides where they sit. The snippet below is trimmed from the plain-Astro demo layout.
4
+
5
+ ```astro
6
+ ---
7
+ // src/layouts/SiteLayout.astro
8
+ import Footer from '@hagicode/hagilight/Footer';
9
+ import SEOHead from '@hagicode/hagilight/SEOHead';
10
+ import GoogleAnalytics from '@hagicode/hagilight-core/GoogleAnalytics';
11
+ import Analytics51LA from '@hagicode/hagilight-core/Analytics51LA';
12
+ import CookieConsent from '@hagicode/hagilight-core/CookieConsent';
13
+ import favicon from '@hagicode/hagilight-core/favicon.ico';
14
+
15
+ interface Props {
16
+ locale: string;
17
+ title: string;
18
+ description: string;
19
+ }
20
+
21
+ const { locale, title, description } = Astro.props;
22
+ const site = Astro.site?.href;
23
+ if (!site) throw new Error('This layout needs an absolute Astro site URL.');
24
+ const pageUrl = new URL(Astro.url.pathname, site).href;
25
+ ---
26
+
27
+ <!doctype html>
28
+ <html lang={locale}>
29
+ <head>
30
+ <meta charset="UTF-8" />
31
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
32
+ <meta name="description" content={description} />
33
+ <title>{title}</title>
34
+ <link rel="icon" href={favicon} type="image/x-icon" />
35
+ <SEOHead
36
+ site={site}
37
+ siteSeo={{ title: 'Example' }}
38
+ page={{ url: pageUrl, title, description }}
39
+ locale={locale}
40
+ />
41
+ <GoogleAnalytics measurementId="G-XXXXXXXXXX" consent={true} />
42
+ <Analytics51LA siteId="XXXXXXXXXXXXXXXX" consent={true} />
43
+ </head>
44
+ <body>
45
+ <slot />
46
+ <Footer locale={locale} consent={true} />
47
+ <CookieConsent providers={['googleAnalytics', 'fiftyOneLa']} locale={locale} />
48
+ </body>
49
+ </html>
50
+ ```
51
+
52
+ ## What each piece does
53
+
54
+ - `SEOHead` writes the canonical link, the title and description tags, the Open Graph and Twitter tags, and the default JSON-LD. Pass `site` as an absolute URL, `page` with the page's own URL, title and description, and `locale`.
55
+ - `Footer` is the localized footer with the build line. Set `consent={true}` only when this layout also renders `CookieConsent`, because the "Cookie settings" entry needs the popup to open.
56
+ - `CookieConsent` mounts the consent popup once. List only the providers this layout enables.
57
+ - The `measurementId` and `siteId` values are placeholders. Use the site's own IDs, and keep the `G-` format for `measurementId`.
58
+
59
+ ## Site metadata
60
+
61
+ `hagilight()` writes `/.well-known/hagilight.metadata.json` once per build. It is written last, after the sitemap and `llms.txt`, so it lists what exists. It holds booleans for analytics, never IDs or keys. A site-owned copy in `public/` is never overwritten. `metadata: false` opts out.
62
+
63
+ ## Build line
64
+
65
+ The footer's build line reads `HAGILIGHT_BUILD_BRANCH` and `HAGILIGHT_BUILD_COMMIT` from the environment, then Git, then `unknown`. The layout does not set these. The CI build step does.
@@ -0,0 +1,78 @@
1
+ # Plain Astro setup
2
+
3
+ Use this reference with the `hagilight-official-website` skill. Install the feature package `@hagicode/hagilight` and `@hagicode/hagilight-core` at one exact version, as the from-scratch guide says. The package needs Astro `>=7`; the range is in [`versions.md`](../../hagilight-site-from-scratch/references/versions.md).
4
+
5
+ ## Register the integration
6
+
7
+ The integration and the favicon helper come from `@hagicode/hagilight/integration`. The snippet below is trimmed from the plain-Astro demo.
8
+
9
+ ```js
10
+ // astro.config.mjs
11
+ import { defineConfig } from 'astro/config';
12
+ import { hagilight, hagilightFavicon } from '@hagicode/hagilight/integration';
13
+
14
+ export default defineConfig({
15
+ site: 'https://example.com',
16
+ integrations: [
17
+ hagilight({ rss: { getFeed: './src/rss-feed.ts' } }),
18
+ hagilightFavicon(),
19
+ ],
20
+ i18n: {
21
+ defaultLocale: 'en-US',
22
+ locales: ['en-US', 'zh-CN'],
23
+ },
24
+ });
25
+ ```
26
+
27
+ - `site` must be an absolute HTTP(S) URL. The sitemap, robots and feeds all need it.
28
+ - `hagilight()` with no options is enough for a plain site: it writes the sitemap, `robots.txt`, RSS, `llms.txt` and the metadata file.
29
+ - `rss` takes `false` to turn feeds off, or an options object. `getFeed` points to a module at the project root whose default export is a feed callback. Type it with `RssFeedCallback` from `@hagicode/hagilight/integration`. Omit `getFeed` to serve a built-in empty feed.
30
+
31
+ ## Options
32
+
33
+ | Option | Default | Effect |
34
+ | --- | --- | --- |
35
+ | `enabled` | `true` | Turns the sitemap and `robots.txt` on or off. It does not affect PostHog or the feeds. |
36
+ | `rss` | on | `false` turns the feeds off. An options object sets `locales` and `getFeed`. |
37
+ | `llms` | on | `false` turns `llms.txt` off. An options object sets `enabled`, `title`, `summary`, `lang` and `maxLinksPerSection` (default 12). |
38
+ | `metadata` | on | `false` opts out of `.well-known/hagilight.metadata.json`. |
39
+ | `analytics.posthog` | on | `{ enabled: false }` turns the injected PostHog off. `{ apiKey }` replaces the shared key. |
40
+ | `analytics.consent` | on | Strict prior consent for the injected PostHog. `{ enabled: false }` loads it at once. |
41
+ | `contentImages` | see the package README | Body image handling. |
42
+
43
+ The option types are in `@hagicode/hagilight/integration`. The README under `node_modules/@hagicode/hagilight` has the full descriptions.
44
+
45
+ ## Locale routing
46
+
47
+ - Declare `i18n` in the Astro config with a `defaultLocale` and `locales`. RSS locales are derived from this when `rss` does not set them.
48
+ - Put each locale's pages in its own folder, as the demo does with `en-US/` and `zh-CN/` routes. The header's language links point to those folders.
49
+ - Pass the same locale string to `SEOHead` and `Footer` on every page. `SEOHead` turns it into the `og:locale` tag in `ll_CC` form, so `zh-CN` gives `zh_CN`. A bare `en` gives `en_US`, and a tag with no clear region is left out.
50
+
51
+ ## Sitemap, robots and RSS
52
+
53
+ - `sitemap-index.xml` is written when the site has no sitemap of its own. An existing `@astrojs/sitemap` integration owns the sitemap, and `hagilight()` leaves it alone.
54
+ - `robots.txt` is written when the site has none. A robots page or a file in `public/` takes precedence.
55
+ - Feeds are `/rss.xml` and `/rss.<language>.xml`, one per locale.
56
+
57
+ Run the checks in [`build-checks.md`](../../hagilight-site-from-scratch/references/build-checks.md) on the output.
58
+
59
+ ## `llms.txt`
60
+
61
+ `llms.txt` is generated from the built pages after the build. A site that ships its own `llms.txt`, as a public file or a page, keeps it. If no page is indexable, the build warns and writes none.
62
+
63
+ ## Analytics: Google Analytics and 51LA are composed by hand
64
+
65
+ The integration does not inject Google Analytics or 51LA, so the layout composes them. The components come from `@hagicode/hagilight-core`:
66
+
67
+ - `GoogleAnalytics` takes `measurementId`, in the form `G-` followed by capital letters or digits.
68
+ - `Analytics51LA` takes `siteId`.
69
+ - Both render only in production builds.
70
+ - With consent on, each takes `consent={true}`, and the layout renders one `CookieConsent` with the providers it enables.
71
+
72
+ PostHog is injected by `hagilight()` by default. To compose `<PostHog />` yourself, turn the injection off with `analytics: { posthog: { enabled: false } }` and place `<PostHog />` from `@hagicode/hagilight-core/PostHog` in the layout head. Choose one owner. Do not leave both on.
73
+
74
+ The layout snippet is in [`layout.md`](layout.md).
75
+
76
+ ## Build line
77
+
78
+ The footer shows `Branch:`, `Commit:` and `Built:` lines when `hagilight()` is registered. The branch and commit come from `HAGILIGHT_BUILD_BRANCH` and `HAGILIGHT_BUILD_COMMIT`, then Git, then `unknown`. Set `HAGILIGHT_BUILD_BRANCH` in CI, because a detached checkout reports `Branch: unknown`.
@@ -0,0 +1,65 @@
1
+ ---
2
+ name: hagilight-site-from-scratch
3
+ description: "Use when a project has no hagilight site yet and needs the shared start for any site type: choosing the site type, installing hagilight at one exact version, the site URL and locales, production-only analytics, and the build check. Hands off to the documentation-site or official-website guide."
4
+ ---
5
+
6
+ # Hagilight from scratch
7
+
8
+ The shared start for an empty project. It sets the steps every hagilight site needs, asks the one question that decides the rest, and then hands off to the guide for that site type.
9
+
10
+ ## Step 1: Choose the site type
11
+
12
+ Ask this question before you install anything or write any config:
13
+
14
+ > Is this a documentation site, where a plugin owns the header, footer and locale chooser? Or an official website, where you write the layout yourself?
15
+
16
+ - Documentation site: read [`hagilight-docs-site`](../hagilight-docs-site/SKILL.md). It then asks whether to use Starlight or Docusaurus.
17
+ - Official website: read [`hagilight-official-website`](../hagilight-official-website/SKILL.md).
18
+
19
+ Steps 2 to 5 apply to both site types. The guide you were handed gives the framework-specific commands and files for each of them.
20
+
21
+ ## Step 2: Install at one exact version
22
+
23
+ Install the feature package and `@hagicode/hagilight-core` at the same exact version. Use the version you chose, never a range such as `^` or `~`.
24
+
25
+ | Site type | Feature package | Peers the guide installs |
26
+ | --- | --- | --- |
27
+ | Documentation, Starlight | `@hagicode/hagilight-starlight` | `@astrojs/starlight`, `astro` |
28
+ | Documentation, Docusaurus | `@hagicode/hagilight-docusaurus` | `@docusaurus/core`, `@docusaurus/theme-classic`, `@docusaurus/preset-classic`, `@docusaurus/types`, `react`, `react-dom` |
29
+ | Official website | `@hagicode/hagilight` | `astro` |
30
+
31
+ ```sh
32
+ npm install --save-exact @hagicode/hagilight-core@<exact-version> <feature-package>@<exact-version>
33
+ ```
34
+
35
+ Then confirm one version is in use:
36
+
37
+ ```sh
38
+ npm ls @hagicode/hagilight-core
39
+ ```
40
+
41
+ Every `@hagicode/hagilight*` package in the tree must show the same version. The peer ranges that each package accepts are in [`references/versions.md`](references/versions.md).
42
+
43
+ ## Step 3: Set the site URL and locales
44
+
45
+ - Set `site` in the Astro config to the absolute `https://` URL of the deployed site. Sitemap, feeds and site metadata all depend on it, and RSS fails the build without it.
46
+ - Declare the locales once. Plain Astro uses `i18n`. Starlight takes `locales` from `@hagicode/hagilight-starlight/locales`. Docusaurus takes `i18n` from `@hagicode/hagilight-docusaurus/locales`. Use the catalog locale codes so that labels and `lang` values are checked against the catalog.
47
+ - The first locale is the default. Its build writes the files that cover every locale, such as Docusaurus `robots.txt`.
48
+
49
+ ## Step 4: Enable production-only analytics
50
+
51
+ - Analytics load only in production builds. Development pages carry no analytics loader, so a dev server cannot show whether analytics work.
52
+ - The packages ship shared Google Analytics, 51LA and PostHog defaults. Keep them, replace them with your own IDs, or turn one off with `enabled: false`.
53
+ - Analytics stay off until a visitor grants consent. Keep consent on unless the site has decided otherwise.
54
+
55
+ Which provider each site type configures, the consent pointer, and how tagged links are written are in [`references/analytics-and-links.md`](references/analytics-and-links.md).
56
+
57
+ ## Step 5: Build and check
58
+
59
+ Run the production build, then check the build output: the sitemap, the `robots.txt` and the feed files (`rss.xml` and `rss.<language>.xml`) where the site type generates them. [`references/build-checks.md`](references/build-checks.md) lists which files each site type writes and the checks to run on them. A missing sitemap, robots file or feed is a failed check, not a warning to ignore.
60
+
61
+ ## Done when
62
+
63
+ - `npm ls @hagicode/hagilight-core` shows one version for every `@hagicode/hagilight*` package.
64
+ - The production build finishes with the site URL and locales set.
65
+ - The output contains the sitemap, robots and feed files listed for the site type.
@@ -0,0 +1,45 @@
1
+ # Analytics and tagged links
2
+
3
+ Hagilight sites can load Google Analytics, 51LA and PostHog. This reference says what each site type configures and where the rules live. Option tables stay in the package READMEs.
4
+
5
+ ## Production builds only
6
+
7
+ Every provider renders only in a production build. Development pages carry no loader, so a dev server cannot show that analytics work. Check analytics on a production build, or on the deployed site.
8
+
9
+ ## Which provider each site type configures
10
+
11
+ | Site type | Google Analytics | 51LA | PostHog |
12
+ | --- | --- | --- | --- |
13
+ | Documentation, Starlight | `analytics.googleAnalytics` in the `hagilight()` plugin options | `analytics.fiftyOneLa` in the same options | `analytics.posthog` in the same options, on by default |
14
+ | Documentation, Docusaurus | `analytics.googleAnalytics` in `hagilightDocusaurus()` options | `analytics.fiftyOneLa` in the same options | `analytics.posthog` in the same options, on by default |
15
+ | Official website, plain Astro | Compose `<GoogleAnalytics measurementId="G-…" />` from `@hagicode/hagilight-core/GoogleAnalytics` in the layout head | Compose `<Analytics51LA siteId="…" />` from `@hagicode/hagilight-core/Analytics51LA` in the layout | Injected by `hagilight()` by default, through `analytics.posthog` |
16
+
17
+ Each provider takes `enabled` and its ID. Omitting `enabled` enables a provider when its ID is set. `enabled: false` turns it off without affecting the others.
18
+
19
+ For plain Astro, the layout composes Google Analytics and 51LA by hand, because `hagilight()` injects only PostHog. Pick one owner for PostHog. Either keep the default injection, or set `analytics: { posthog: { enabled: false } }` and compose `<PostHog />` from `@hagicode/hagilight-core/PostHog` in the layout head yourself. Do not do both.
20
+
21
+ ## Consent
22
+
23
+ Analytics stay off until a visitor grants consent. Consent is on by default whenever a provider is enabled, so the popup and the gate come with the provider. Turning consent off (`consent: { enabled: false }` where the option exists) loads the providers at once.
24
+
25
+ Regional consent (`analytics.consent.regions` and its related options) changes who sees the prompt. Set it only if the site serves visitors who need it. The option, its default country set and its resolution rules are in `@hagicode/hagilight-core`'s README under "Analytics consent" and "Regional analytics consent".
26
+
27
+ ## Tagged links
28
+
29
+ A link that should report a click event carries its tag as attributes. Never write `data-ga-*` attributes by hand.
30
+
31
+ - For a link in the catalog of tracked site links, use `siteLinkGaAttributes(link, location)` from `@hagicode/hagilight-core/analytics-events`. It returns `{}` for any link that is not in the catalog, so it is safe to call for every link. The catalog ids are listed in the core README under "Google Analytics click events".
32
+ - For your own link, use `gaEventAttributes({ category, label, location })` from the same module. The `category` must be one of `download`, `store`, `navigation`, `community` or `promotion`. `label` and `location` must be non-empty.
33
+
34
+ ```astro
35
+ ---
36
+ import { gaEventAttributes } from '@hagicode/hagilight-core/analytics-events';
37
+ ---
38
+
39
+ <a
40
+ href="https://example.com/download"
41
+ {...gaEventAttributes({ category: 'download', label: 'desktop-download', location: 'hero' })}
42
+ >Download</a>
43
+ ```
44
+
45
+ Related sites, RSS links, sitemap links, about and contact links, filing links, and extra links that the consumer adds stay untagged. Tag a link only when it is one of those tracked kinds.
@@ -0,0 +1,40 @@
1
+ # Build checks
2
+
3
+ Run the production build, then check the files the site type generates. The file list depends on the site type, so use the list for your type. A file the list names but the build does not write is a failed check.
4
+
5
+ Run these checks on the built output, not on the source:
6
+
7
+ - Sitemap URLs use the site's own `https://` origin. For example, `grep -c '<loc>http://' dist/sitemap-*.xml` should print nothing.
8
+ - `robots.txt`, when present, names the sitemap with an absolute URL.
9
+ - Feeds exist for the locales that have items.
10
+
11
+ ## Plain Astro (`hagilight()`)
12
+
13
+ The integration writes these into the output directory when the site URL is set:
14
+
15
+ - `sitemap-index.xml` and its sitemap pages. Skipped when the site already provides a sitemap.
16
+ - `robots.txt`. Skipped when the site already provides one.
17
+ - `rss.xml` and `rss.<language>.xml`, one per locale. On by default; `rss: false` turns them off.
18
+ - `llms.txt`, written from the built pages. Skipped with a warning when no page is indexable, and left alone when the site ships its own.
19
+ - `.well-known/hagilight.metadata.json`, written last, after the sitemap and `llms.txt`.
20
+
21
+ ## Documentation, Starlight
22
+
23
+ The plugin writes these into the output directory:
24
+
25
+ - `sitemap-index.xml`, generated by Starlight's own sitemap.
26
+ - `rss.xml` and `rss.<language>.xml`, one per locale. On by default; `rss: { enabled: false }` turns them off.
27
+ - `.well-known/hagilight.metadata.json`, written once per build, after the sitemap, so it lists the sitemap and any feed that exists.
28
+
29
+ The Starlight plugin writes no `robots.txt` and no `llms.txt`. If the site needs a `robots.txt`, add it to `public/` and check it yourself.
30
+
31
+ ## Documentation, Docusaurus
32
+
33
+ The plugin writes these, and only in the builds listed:
34
+
35
+ - `sitemap.xml`, into each locale's output, in production builds. Written only when the official `docusaurus-plugin-sitemap` is not loaded, and not when `noIndex` is set.
36
+ - `robots.txt`, written by the default-locale build only. It names one sitemap per locale, so build every locale (run `docusaurus build` without `--locale`) for the full list.
37
+ - `rss.xml`, per locale, when that locale has feed items.
38
+ - `.well-known/hagilight.metadata.json`, written by the default-locale build.
39
+
40
+ On GitHub Pages, publish a `.nojekyll` file at the root. Without it, the `.well-known` directory is dropped.
@@ -0,0 +1,16 @@
1
+ # Versions and peer ranges
2
+
3
+ Pin every `@hagicode/hagilight*` package to the same exact version. Feature packages depend on the matching `@hagicode/hagilight-core` version, so install the feature package and core at one exact version, for example `0.1.0`, and never a range such as `^0.1.0`.
4
+
5
+ ## Peer ranges
6
+
7
+ These are the peer ranges each package declares. Install a peer that satisfies its range; the table is checked against the package manifests by `test/website-skills.test.mjs`.
8
+
9
+ | Package | Peer | Range |
10
+ | --- | --- | --- |
11
+ | `@hagicode/hagilight` | `astro` | `>=7` |
12
+ | `@hagicode/hagilight-core` | `astro` | `>=7` |
13
+ | `@hagicode/hagilight-starlight` | `astro` | `^7.3.5` |
14
+ | `@hagicode/hagilight-starlight` | `@astrojs/starlight` | `^0.42.4` |
15
+ | `@hagicode/hagilight-docusaurus` | `@docusaurus/core` | `^3.9.2` |
16
+ | `@hagicode/hagilight-docusaurus` | `@docusaurus/theme-classic` | `^3.9.2` |