@hagicode/hagilight-starlight 0.11.0 → 0.11.1-dev.129.1.ea757b8

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
@@ -29,6 +29,43 @@ export default defineConfig({
29
29
 
30
30
  The plugin also exposes `@hagicode/hagilight-starlight/schema` for optional SEO frontmatter and individual Astro components such as `/Header` and `/MarkdownContent` for custom Starlight overrides. Configure features through the typed `HagilightStarlightOptions` passed to `hagilight()`.
31
31
 
32
+ ### Analytics
33
+
34
+ `hagilight()` enables PostHog without analytics configuration, an enabled flag, or a consumer project key. It uses `phc_qiVVihsL925ovhPYNdLJWz4k7aoKVMwYCevgZPE6PER5`, API host `https://us.i.posthog.com`, and SDK defaults `2026-05-30`. Google Analytics and PostHog render together in the generated global Head; 51LA stays in the Footer. PostHog covers all production pages, including localized and 404 pages, independently of Google's existing 404 exclusion. Development pages emit no PostHog loader.
35
+
36
+ PostHog options follow the Google Analytics provider convention:
37
+
38
+ | PostHog input | Behavior |
39
+ | --- | --- |
40
+ | Plugin options omitted, `analytics: {}`, or `posthog` omitted | Enabled with the supplied default key |
41
+ | `posthog: {}` | Disabled, like an empty Google Analytics provider |
42
+ | `posthog: { apiKey: 'phc_Custom123' }` | Enabled with the custom key |
43
+ | `posthog: { enabled: true, apiKey: 'phc_Custom123' }` | Enabled with the custom key |
44
+ | `posthog: { enabled: true }` | Configuration error: `apiKey` required |
45
+ | `posthog: { enabled: false }` | Disabled independently of Google Analytics and 51LA |
46
+
47
+ Keys must match `^phc_[A-Za-z0-9]+$`; enabled providers reject missing or malformed keys. Provider options must be objects and `enabled` must be boolean.
48
+
49
+ ```js
50
+ hagilight(); // shared analytics defaults
51
+ hagilight({ analytics: { posthog: { apiKey: 'phc_Custom123' } } });
52
+ hagilight({ analytics: { posthog: { enabled: false } } });
53
+ ```
54
+
55
+ A site-owned `components.Head` conflicts with enabled SEO, Google Analytics, or PostHog. To retain it, disable all three head features and explicitly compose the desired metadata and `@hagicode/hagilight-core/GoogleAnalytics` / `@hagicode/hagilight-core/PostHog` components in that Head:
56
+
57
+ ```js
58
+ hagilight({
59
+ seo: { enabled: false },
60
+ analytics: {
61
+ googleAnalytics: { enabled: false },
62
+ posthog: { enabled: false },
63
+ },
64
+ });
65
+ ```
66
+
67
+ The shared component initializes once per document; SDK defaults own PostHog navigation behavior. Choose one initialization owner and disable this provider when the site already initializes PostHog. Google Analytics and 51LA keep their configured behavior when PostHog is disabled.
68
+
32
69
  ### Theme picker
33
70
 
34
71
  By default the plugin replaces Starlight's light/dark toggle with a theme picker offering nine choices: the default theme plus the Ocean, Sakura, and Forest themes in light and dark, and a "Default" choice that follows the visitor's system color scheme and renders the Forest theme. First-time visitors, and visitors with an invalid saved choice, therefore see Forest; the other themes appear only after an explicit selection, which is remembered in `localStorage`.
package/dist/index.d.ts CHANGED
@@ -20,6 +20,12 @@ export interface HagilightFiftyOneLaOptions {
20
20
  export interface HagilightAnalyticsOptions {
21
21
  googleAnalytics?: HagilightGoogleAnalyticsOptions;
22
22
  fiftyOneLa?: HagilightFiftyOneLaOptions;
23
+ posthog?: HagilightPostHogOptions;
24
+ }
25
+ export interface HagilightPostHogOptions {
26
+ /** Defaults to true when the provider options are omitted, otherwise to whether apiKey is set. */
27
+ enabled?: boolean;
28
+ apiKey?: string;
23
29
  }
24
30
  export interface HagilightSeoOptions {
25
31
  /** Replace Starlight's Head with Hagilight SEO metadata. Defaults to `true`; requires Astro `site`. */
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ import { fileURLToPath } from 'node:url';
3
3
  import { resolveFaviconHeadEntry } from '@hagicode/hagilight-core/favicon';
4
4
  import { resolveBuildInfo } from '@hagicode/hagilight-core/build-info-resolver';
5
5
  import { checkContentImageRegistration, registerContentImages } from '@hagicode/hagilight-core/content-images';
6
+ import { DEFAULT_POSTHOG_API_KEY, POSTHOG_API_KEY_PATTERN } from '@hagicode/hagilight-core/posthog';
6
7
  import { resolveRssLocales } from '@hagicode/hagilight-core/rss';
7
8
  import { RSS_OWNER, registerStarlightRssOwner, } from '@hagicode/hagilight-core/rss-ownership';
8
9
  import { isValidSeoImageReference, resolveSeoImageUrl } from '@hagicode/hagilight-core/seo';
@@ -267,11 +268,13 @@ import options from '${optionsId}';
267
268
  import DefaultHead from '@astrojs/starlight/components/Head.astro';
268
269
  import SEOHead from ${JSON.stringify(seoHeadPath)};
269
270
  import GoogleAnalytics from ${JSON.stringify(coreExport('GoogleAnalytics'))};
271
+ ${serializedOptions.posthogApiKey ? `import PostHog from ${JSON.stringify(coreExport('PostHog'))};` : ''}
270
272
  import options from '${optionsId}';
271
273
  const isNotFound = /(?:^|\\/)404(?:\\.html)?\\/?$/u.test(Astro.url.pathname);
272
274
  ---
273
275
 
274
276
  {options.seoEnabled ? <SEOHead options={options} /> : <DefaultHead />}
277
+ ${serializedOptions.posthogApiKey ? '<PostHog apiKey={options.posthogApiKey} />' : ''}
275
278
  {!isNotFound && options.googleAnalyticsMeasurementId && (
276
279
  <GoogleAnalytics measurementId={options.googleAnalyticsMeasurementId} />
277
280
  )}
@@ -371,6 +374,14 @@ export default function hagilight(options = {}) {
371
374
  pattern: FIFTY_ONE_LA_ID_PATTERN,
372
375
  defaultId: DEFAULT_51LA_ID,
373
376
  });
377
+ const posthog = optionalRecord(analytics.posthog, 'PostHog analytics');
378
+ optionalBoolean(posthog, 'enabled', 'PostHog analytics enabled');
379
+ const posthogApiKey = resolveProvider(analytics.posthog, {
380
+ name: 'PostHog',
381
+ idKey: 'apiKey',
382
+ pattern: POSTHOG_API_KEY_PATTERN,
383
+ defaultId: DEFAULT_POSTHOG_API_KEY,
384
+ });
374
385
  const promoto = optionalRecord(input.promoto, 'promoto');
375
386
  const promotoEnabled = optionalBoolean(promoto, 'enabled', 'promoto enabled') !== false;
376
387
  const contentImages = optionalRecord(input.contentImages, 'contentImages');
@@ -388,7 +399,7 @@ export default function hagilight(options = {}) {
388
399
  markdownContent: markdownContentEnabled
389
400
  ? `virtual:hagilight-starlight/${instanceId}/MarkdownContent.astro`
390
401
  : undefined,
391
- head: seo.enabled || googleAnalyticsMeasurementId
402
+ head: seo.enabled || googleAnalyticsMeasurementId || posthogApiKey
392
403
  ? `virtual:hagilight-starlight/${instanceId}/Head.astro`
393
404
  : undefined,
394
405
  themeSelect: themesEnabled ? packageFile('ThemeSelect.astro') : undefined,
@@ -399,6 +410,7 @@ export default function hagilight(options = {}) {
399
410
  links: options.links ?? {},
400
411
  googleAnalyticsMeasurementId,
401
412
  fiftyOneLaId,
413
+ posthogApiKey,
402
414
  aiDisclosures,
403
415
  seoEnabled: seo.enabled,
404
416
  seo,
@@ -428,9 +440,9 @@ export default function hagilight(options = {}) {
428
440
  }
429
441
  if (componentIds.head && config.components?.Head) {
430
442
  if (seo.enabled) {
431
- throw new Error('Hagilight SEO cannot replace an existing Starlight Head override. Set seo: { enabled: false } and disable Google Analytics to keep your Head, or compose your site metadata explicitly.');
443
+ throw new Error('Hagilight SEO cannot replace an existing Starlight Head override. Set seo: { enabled: false }, analytics.googleAnalytics: { enabled: false }, and analytics.posthog: { enabled: false } to keep your Head, or compose SEO, @hagicode/hagilight-core/GoogleAnalytics and @hagicode/hagilight-core/PostHog explicitly.');
432
444
  }
433
- throw new Error('Hagilight Google Analytics cannot replace an existing Starlight Head override. Disable Google Analytics or compose @hagicode/hagilight-core/GoogleAnalytics in your Head instead.');
445
+ throw new Error('Hagilight Google Analytics or PostHog cannot replace an existing Starlight Head override. Set analytics.googleAnalytics: { enabled: false } and analytics.posthog: { enabled: false } to keep it, or compose @hagicode/hagilight-core/GoogleAnalytics and @hagicode/hagilight-core/PostHog in your Head.');
434
446
  }
435
447
  let seoSite;
436
448
  let seoLocales = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hagicode/hagilight-starlight",
3
- "version": "0.11.0",
3
+ "version": "0.11.1-dev.129.1.ea757b8",
4
4
  "type": "module",
5
5
  "description": "Starlight plugin and components for HagiCode documentation",
6
6
  "repository": {
@@ -53,7 +53,7 @@
53
53
  "assets/showcase/*"
54
54
  ],
55
55
  "dependencies": {
56
- "@hagicode/hagilight-core": "0.11.0"
56
+ "@hagicode/hagilight-core": "0.11.1-dev.129.1.ea757b8"
57
57
  },
58
58
  "peerDependencies": {
59
59
  "@astrojs/starlight": "^0.42.4",