@hagicode/hagilight 0.20.1-dev.196.1.d67f4e4 → 0.20.1-dev.200.1.6beb099

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/Footer.astro CHANGED
@@ -8,8 +8,12 @@ interface Props extends ComponentProps<typeof CoreFooter> {}
8
8
  if (typeof manifest.version !== 'string' || manifest.version.trim().length === 0) {
9
9
  throw new Error('@hagicode/hagilight requires a nonempty string version in its package.json.');
10
10
  }
11
+
12
+ // Set per request by the hagilight integration on a regional build. Absent otherwise, so global output is unchanged.
13
+ const consentFromBuild = (Astro.locals as { hagilightConsent?: { regional: boolean; replayEntry: boolean } }).hagilightConsent;
14
+ const { regional = consentFromBuild?.regional, replayEntry = consentFromBuild?.replayEntry, ...props } = Astro.props;
11
15
  ---
12
16
 
13
- <CoreFooter {...Astro.props}>
17
+ <CoreFooter {...props} regional={regional} replayEntry={replayEntry}>
14
18
  <span slot="attribution">Powered By hagilight@{manifest.version}</span>
15
19
  </CoreFooter>
@@ -0,0 +1,2 @@
1
+ import type { MiddlewareHandler } from 'astro';
2
+ export declare const onRequest: MiddlewareHandler;
@@ -0,0 +1,5 @@
1
+ import consentFooter from 'virtual:hagilight/consent-footer';
2
+ export const onRequest = (context, next) => {
3
+ context.locals.hagilightConsent = consentFooter;
4
+ return next();
5
+ };
@@ -102,5 +102,10 @@ export type HagilightFaviconOptions = FaviconOptions;
102
102
  * precedence, and an enabled Starlight Hagilight integration owns RSS feeds.
103
103
  */
104
104
  export declare function hagilight({ enabled, rss, contentImages, llms, metadata, analytics }?: HagilightOptions): AstroIntegration;
105
+ /** The footer's regional state, read per request by `Footer.astro` through `Astro.locals`. */
106
+ export interface ConsentFooterState {
107
+ regional: boolean;
108
+ replayEntry: boolean;
109
+ }
105
110
  /** Inject the bundled HagiCode favicon unless the site head already declares an icon. */
106
111
  export declare function hagilightFavicon(options?: HagilightFaviconOptions): AstroIntegration;
@@ -7,7 +7,7 @@ import { checkContentImageRegistration, registerContentImages } from '@hagicode/
7
7
  import { resolveFaviconHeadEntry } from '@hagicode/hagilight-core/favicon';
8
8
  import { DEFAULT_POSTHOG_API_KEY, POSTHOG_API_KEY_PATTERN, posthogInitScript } from '@hagicode/hagilight-core/posthog';
9
9
  import { consentHeadScript } from '@hagicode/hagilight-core/consent-mount';
10
- import { validatePolicyVersion, validatePrivacyUrl } from '@hagicode/hagilight-core/consent-markup';
10
+ import { resolveRegionalOptions, validatePolicyVersion, validatePrivacyUrl, } from '@hagicode/hagilight-core/consent-markup';
11
11
  import { resolveRssLocales } from '@hagicode/hagilight-core/rss';
12
12
  import { resolvePlainAstroRssOwner } from '@hagicode/hagilight-core/rss-ownership';
13
13
  import { resolveSiteMetadataOption } from '@hagicode/hagilight-core/site-metadata';
@@ -18,6 +18,8 @@ const VIRTUAL_RSS_CONFIG = 'virtual:hagilight/rss-config';
18
18
  const VIRTUAL_RSS_CONFIG_RESOLVED = `\0${VIRTUAL_RSS_CONFIG}`;
19
19
  const VIRTUAL_BUILD_INFO = 'virtual:hagilight/build-info';
20
20
  const VIRTUAL_BUILD_INFO_RESOLVED = `\0${VIRTUAL_BUILD_INFO}`;
21
+ const VIRTUAL_CONSENT_FOOTER = 'virtual:hagilight/consent-footer';
22
+ const VIRTUAL_CONSENT_FOOTER_RESOLVED = `\0${VIRTUAL_CONSENT_FOOTER}`;
21
23
  const PAGE_SOURCE_EXTENSIONS = new Set(['.astro', '.html', '.js', '.jsx', '.md', '.mdx', '.ts', '.tsx']);
22
24
  const packageRoot = new URL('../', import.meta.url);
23
25
  const routeEntrypoint = (name) => fileURLToPath(new URL(name, packageRoot));
@@ -62,10 +64,12 @@ function resolveConsentOptions(analytics, posthogEnabled) {
62
64
  if (consent?.enabled !== undefined && typeof consent.enabled !== 'boolean') {
63
65
  throw new TypeError('Hagilight analytics consent enabled option must be a boolean.');
64
66
  }
67
+ // Regional options are validated by the core, so every integration throws the same named error.
65
68
  return {
66
69
  enabled: posthogEnabled && (consent?.enabled ?? true),
67
70
  privacyUrl: validatePrivacyUrl(consent?.privacyUrl),
68
71
  policyVersion: validatePolicyVersion(consent?.policyVersion),
72
+ regional: resolveRegionalOptions(consent, consent?.enabled !== false),
69
73
  };
70
74
  }
71
75
  function postHogSiteContext(site) {
@@ -164,10 +168,27 @@ export function hagilight({ enabled = true, rss, contentImages, llms, metadata,
164
168
  const loader = posthogInitScript(posthogApiKey, postHogSiteContext(config.site));
165
169
  injectScript('head-inline', consentHeadScript({
166
170
  posthog: { apiKey: posthogApiKey, loader },
167
- config: { providers: ['posthog'], privacyUrl: consent.privacyUrl, policyVersion: consent.policyVersion },
171
+ config: {
172
+ providers: ['posthog'],
173
+ privacyUrl: consent.privacyUrl,
174
+ policyVersion: consent.policyVersion,
175
+ regional: consent.regional,
176
+ },
168
177
  }));
169
178
  const mountModule = fileURLToPath(import.meta.resolve('@hagicode/hagilight-core/consent-mount'));
170
179
  injectScript('page', `import { mountConsent } from ${JSON.stringify(mountModule)};\nmountConsent();`);
180
+ if (consent.regional) {
181
+ // The footer reads these per request, so its hidden entries follow the descriptor it was built with.
182
+ updateConfig({
183
+ vite: {
184
+ plugins: [createConsentFooterPlugin({
185
+ regional: true,
186
+ replayEntry: consent.regional.sessionReplay === 'optIn',
187
+ })],
188
+ },
189
+ });
190
+ addMiddleware({ entrypoint: fileURLToPath(new URL('./consent-middleware.js', import.meta.url)), order: 'pre' });
191
+ }
171
192
  }
172
193
  else {
173
194
  injectScript('head-inline', posthogInitScript(posthogApiKey, postHogSiteContext(config.site)));
@@ -445,6 +466,19 @@ function createVirtualPlugin({ modulePath, site, baseUrl, locales, defaultFeedUr
445
466
  },
446
467
  };
447
468
  }
469
+ function createConsentFooterPlugin(state) {
470
+ return {
471
+ name: '@hagicode/hagilight:consent-footer',
472
+ resolveId(id) {
473
+ return id === VIRTUAL_CONSENT_FOOTER ? VIRTUAL_CONSENT_FOOTER_RESOLVED : null;
474
+ },
475
+ load(id) {
476
+ if (id !== VIRTUAL_CONSENT_FOOTER_RESOLVED)
477
+ return null;
478
+ return `export default ${JSON.stringify(state)};`;
479
+ },
480
+ };
481
+ }
448
482
  function createBuildInfoPlugin(buildInfo) {
449
483
  return {
450
484
  name: '@hagicode/hagilight:build-info',
@@ -7,7 +7,7 @@ import { existsSync, readFileSync, statSync } from 'node:fs';
7
7
  import { join } from 'node:path';
8
8
  import { fileURLToPath } from 'node:url';
9
9
  import { CONSENT_DESCRIPTOR_ID } from '@hagicode/hagilight-core/consent-markup';
10
- import { buildSiteMetadata, detectAnalyticsLoaders, SITE_METADATA_PATH, } from '@hagicode/hagilight-core/site-metadata';
10
+ import { buildSiteMetadata, detectAnalyticsLoaders, detectConsentMode, SITE_METADATA_PATH, } from '@hagicode/hagilight-core/site-metadata';
11
11
  import { findDiscoveryOutputs, writeSiteMetadata } from '@hagicode/hagilight-core/site-metadata-writer';
12
12
  import { parseHeadMeta } from './llms.js';
13
13
  const ASTRO_PACKAGE_VERSION = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
@@ -99,7 +99,7 @@ export function writeAstroSiteMetadata({ config, outDir, pages, build, options,
99
99
  discovery: findDiscoveryOutputs(outDir),
100
100
  analytics: detectAnalyticsLoaders(pageHtml),
101
101
  // The popup is mounted exactly when a built page carries its config descriptor.
102
- features: { consent: pageHtml.some((html) => html.includes(CONSENT_DESCRIPTOR_ID)) },
102
+ features: { consent: pageHtml.some((html) => html.includes(CONSENT_DESCRIPTOR_ID)), consentMode: detectConsentMode(pageHtml) },
103
103
  });
104
104
  writeSiteMetadata({
105
105
  outDir,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hagicode/hagilight",
3
- "version": "0.20.1-dev.196.1.d67f4e4",
3
+ "version": "0.20.1-dev.200.1.6beb099",
4
4
  "type": "module",
5
5
  "description": "Astro integrations and components for HagiCode sites",
6
6
  "repository": {
@@ -40,7 +40,7 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "@astrojs/sitemap": "^3.7.4",
43
- "@hagicode/hagilight-core": "0.20.1-dev.196.1.d67f4e4"
43
+ "@hagicode/hagilight-core": "0.20.1-dev.200.1.6beb099"
44
44
  },
45
45
  "keywords": [
46
46
  "hagicode",