@writedocs/generator 0.10.14 → 0.10.15

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.
@@ -1,77 +1,45 @@
1
- ---
2
- // writedocs.json's `integrations` (integrationsSchema in lib/config.ts) - the
3
- // six analytics providers. Each provider's inline-JS half (the ones that
4
- // need one; Fathom/Plausible/Umami are pure <script src> tags with data-*
5
- // attributes, rendered directly in the template below with no inline half
6
- // to build here) is assembled as a plain string, interpolating the site's
7
- // own config values via JSON.stringify (not raw string interpolation) so
8
- // a value containing a quote or backslash can never break out of the
9
- // generated script.
10
- //
11
- // Rendered by BaseLayout.astro in <head>, right after the meta tags and
12
- // before even the theme-detection script - the usual placement every one
13
- // of these providers' own install instructions ask for, so pageview
14
- // timing is captured as close to actual page load as it can be. Every
15
- // snippet below was sourced from that provider's own current official
16
- // docs (fetched directly, not recalled from training data) while building
17
- // this feature - see docs/dev/docs/integrations.mdx for links and dates.
18
- // Every provider field is optional and independent - a site can turn on
19
- // any subset (including all of them at once, for a migration period) or
20
- // none.
21
- //
22
- // AskAiWidget.astro is the seventh integration (DocsBot) - kept as its
23
- // own separate component rather than folded in here, since it renders at
24
- // the *end* of <body>, not in <head> (it's a UI widget, not a pageview
25
- // beacon - see that component's own comment).
26
- //
27
- // Split out of BaseLayout.astro, which had grown to ~2200 lines covering
28
- // several unrelated concerns in one file - see that component's own
29
- // comment for the fuller rationale.
30
- import type { DocsConfig } from '../../lib/config';
31
-
32
- interface Props {
33
- config: DocsConfig;
34
- }
35
- const { config } = Astro.props as Props;
36
-
37
- // Google Tag Manager's snippet is copied verbatim from Google's own
38
- // long-stable install snippet (unchanged in substance for years) - the
39
- // self-invoking function that pushes the initial 'gtm.js' event and
40
- // injects the real gtm.js loader script.
41
- const gtmScript = config.integrations.googleTagManager
42
- ? `(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer',${JSON.stringify(config.integrations.googleTagManager.containerId)});`
43
- : null;
44
- // GA4's own gtag.js config call - paired with the separate `<script
45
- // async src="...gtag/js?id=...">` loader tag rendered directly below,
46
- // both gated on the same config.integrations.ga4 check.
47
- const ga4ConfigScript = config.integrations.ga4
48
- ? `window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments);}gtag('js',new Date());gtag('config',${JSON.stringify(config.integrations.ga4.measurementId)});`
49
- : null;
50
- // PostHog's own "array.js" bootstrap loader - copied verbatim from
51
- // posthog.com/docs/libraries/js (fetched directly while building this
52
- // feature, not recalled from training data - PostHog revises this
53
- // snippet's minified body occasionally, so re-fetch and diff before
54
- // assuming it's still current if this ever needs touching again). The
55
- // `defaults` date is PostHog's own versioned configuration-snapshot pin
56
- // (their docs describe it as "a date... for a configuration snapshot used
57
- // as defaults") - current as of the fetch above; bump it if PostHog's own
58
- // docs have moved on to a newer one.
59
- const posthogScript = config.integrations.posthog
60
- ? `!function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.crossOrigin="anonymous",p.async=!0,p.src=s.api_host.replace(".i.posthog.com","-assets.i.posthog.com")+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="init capture register register_once register_for_session unregister unregister_for_session getFeatureFlag getFeatureFlagResult isFeatureEnabled reloadFeatureFlags updateEarlyAccessFeatureEnrollment getEarlyAccessFeatures on onFeatureFlags onSessionId getSurveys getActiveMatchingSurveys renderSurvey canRenderSurvey getNextSurveyStep identify setPersonProperties group resetGroups setPersonPropertiesForFlags resetPersonPropertiesForFlags setGroupPropertiesForFlags resetGroupPropertiesForFlags reset get_distinct_id getGroups get_session_id get_session_replay_url alias set_config startSessionRecording stopSessionRecording sessionRecordingStarted captureException loadToolbar get_property getSessionProperty createPersonProfile opt_in_capturing opt_out_capturing has_opted_in_capturing has_opted_out_capturing clear_opt_in_out_capturing debug".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]);posthog.init(${JSON.stringify(config.integrations.posthog.apiKey)},{api_host:${JSON.stringify(config.integrations.posthog.apiHost)},defaults:'2026-05-30'});`
61
- : null;
62
- ---
63
- {config.integrations.ga4 && (
64
- <script is:inline async src={`https://www.googletagmanager.com/gtag/js?id=${config.integrations.ga4.measurementId}`}></script>
65
- )}
66
- {ga4ConfigScript && <script is:inline set:html={ga4ConfigScript} />}
67
- {gtmScript && <script is:inline set:html={gtmScript} />}
68
- {config.integrations.plausible && (
69
- <script is:inline defer data-domain={config.integrations.plausible.domain} src={config.integrations.plausible.src}></script>
70
- )}
71
- {config.integrations.fathom && (
72
- <script is:inline src="https://cdn.usefathom.com/script.js" data-site={config.integrations.fathom.siteId} defer></script>
73
- )}
74
- {posthogScript && <script is:inline set:html={posthogScript} />}
75
- {config.integrations.umami && (
76
- <script is:inline defer src={config.integrations.umami.src} data-website-id={config.integrations.umami.websiteId}></script>
77
- )}
1
+ ---
2
+ // writedocs.json's `integrations` - the six analytics providers. The tags
3
+ // themselves are built by analyticsTags() in lib/consent.js (each one the
4
+ // provider's own install snippet - see docs/dev/docs/integrations.mdx for
5
+ // links and dates); this component decides how they reach the page:
6
+ //
7
+ // - no `integrations.consent`: one <script> tag each, loaded with the page.
8
+ // - with it: no tag at all, only consentLoaderScript() - which adds them
9
+ // once the reader has accepted, now or on an earlier visit. `scripts`
10
+ // entries marked `consent: true` (gatedScripts) wait the same way.
11
+ //
12
+ // Rendered by BaseLayout.astro in <head>, right after the meta tags and
13
+ // before even the theme-detection script - the usual placement every one
14
+ // of these providers' own install instructions ask for, so pageview timing
15
+ // is captured as close to actual page load as it can be. Every provider
16
+ // field is optional and independent - a site can turn on any subset
17
+ // (including all of them at once, for a migration period) or none.
18
+ //
19
+ // AskAiWidget.astro is the seventh integration (DocsBot) - its own
20
+ // component, since it renders at the *end* of <body>, not in <head> (it's a
21
+ // UI widget, not a pageview beacon - see that component's own comment), and
22
+ // it doesn't wait for consent.
23
+ import type { DocsConfig } from '../../lib/config';
24
+ import { analyticsTags, scriptTags, consentLoaderScript } from '../../lib/consent.js';
25
+
26
+ interface Props {
27
+ config: DocsConfig;
28
+ // consentOptions() of `integrations.consent` - null when the banner is off.
29
+ consent?: object | null;
30
+ // `scripts` entries with `consent: true`. Empty when the banner is off:
31
+ // BaseLayout renders them as ordinary scripts then.
32
+ gatedScripts?: { src?: string; content?: string }[];
33
+ }
34
+ const { config, consent = null, gatedScripts = [] } = Astro.props as Props;
35
+
36
+ const tags = analyticsTags(config.integrations);
37
+ const loader = consent ? consentLoaderScript([...tags, ...scriptTags(gatedScripts)]) : null;
38
+ ---
39
+ {loader ? (
40
+ <script is:inline set:html={loader} />
41
+ ) : (
42
+ tags.map((tag) =>
43
+ tag.src ? <script is:inline src={tag.src} {...tag.attrs}></script> : <script is:inline set:html={tag.content} />,
44
+ )
45
+ )}
@@ -0,0 +1,118 @@
1
+ ---
2
+ // writedocs.json's `integrations.consent` - the banner that asks before the
3
+ // analytics integrations load. It's in the page hidden; src/scripts/
4
+ // consent.ts shows it when the reader hasn't answered yet (window.wdConsent,
5
+ // defined in <head> by consentLoaderScript() in lib/consent.js), and again
6
+ // when they follow a link to #cookie-settings.
7
+ //
8
+ // A strip along the bottom of the window rather than a dialog: the page
9
+ // stays readable and usable while it's there, so focus isn't trapped and
10
+ // nothing is covered that can't be scrolled into view (consent.ts pads the
11
+ // page's end by the banner's height).
12
+ interface Props {
13
+ consent: {
14
+ message: string;
15
+ acceptLabel: string;
16
+ declineLabel: string;
17
+ policyUrl: string | null;
18
+ policyLabel: string;
19
+ };
20
+ }
21
+ const { consent } = Astro.props as Props;
22
+ ---
23
+ <section class="wd-consent" id="wd-consent" aria-label="Cookie consent" data-pagefind-ignore hidden>
24
+ <div class="wd-consent-inner">
25
+ <p class="wd-consent-text">
26
+ {consent.message}{" "}
27
+ {consent.policyUrl && <a href={consent.policyUrl}>{consent.policyLabel}</a>}
28
+ </p>
29
+ <div class="wd-consent-actions">
30
+ <button type="button" class="wd-consent-button" data-consent="denied">{consent.declineLabel}</button>
31
+ <button type="button" class="wd-consent-button wd-consent-accept" data-consent="granted">{consent.acceptLabel}</button>
32
+ </div>
33
+ </div>
34
+ </section>
35
+
36
+ <script>
37
+ import { initConsent } from "../../scripts/consent";
38
+
39
+ initConsent(document);
40
+ document.addEventListener("astro:page-load", () => initConsent(document));
41
+ </script>
42
+
43
+ <style is:global>
44
+ .wd-consent {
45
+ position: fixed;
46
+ left: 0;
47
+ right: 0;
48
+ bottom: 0;
49
+ /* Above the topbar (10) and the page; below the search and image
50
+ overlays (100), which the reader opened on purpose. */
51
+ z-index: 50;
52
+ background: var(--wd-surface);
53
+ border-top: 1px solid var(--wd-border);
54
+ color: var(--wd-text);
55
+ box-shadow: 0 -4px 16px rgb(0 0 0 / 0.08);
56
+ }
57
+ .wd-consent[hidden] {
58
+ display: none;
59
+ }
60
+ .wd-consent-inner {
61
+ max-width: 1440px;
62
+ margin: 0 auto;
63
+ padding: 0.85rem 1.5rem;
64
+ display: flex;
65
+ align-items: center;
66
+ justify-content: space-between;
67
+ gap: 1rem 1.5rem;
68
+ }
69
+ .wd-consent-text {
70
+ margin: 0;
71
+ font-size: 0.88rem;
72
+ line-height: 1.5;
73
+ }
74
+ .wd-consent-text a {
75
+ color: var(--wd-primary);
76
+ text-decoration: underline;
77
+ }
78
+ .wd-consent-actions {
79
+ display: flex;
80
+ gap: 0.5rem;
81
+ flex-shrink: 0;
82
+ }
83
+ /* Both buttons the same size and weight but for the fill - declining is as
84
+ easy as accepting. */
85
+ .wd-consent-button {
86
+ font: inherit;
87
+ font-size: 0.85rem;
88
+ font-weight: 600;
89
+ padding: 0.45rem 1rem;
90
+ border-radius: 0.5rem;
91
+ border: 1px solid var(--wd-border);
92
+ background: var(--wd-background);
93
+ color: var(--wd-heading);
94
+ cursor: pointer;
95
+ }
96
+ .wd-consent-button:hover {
97
+ border-color: var(--wd-primary);
98
+ }
99
+ .wd-consent-accept {
100
+ background: var(--wd-primary);
101
+ border-color: var(--wd-primary);
102
+ color: var(--wd-on-primary);
103
+ }
104
+ .wd-consent-button:focus-visible {
105
+ outline: 2px solid var(--wd-primary);
106
+ outline-offset: 2px;
107
+ }
108
+ @media (max-width: 640px) {
109
+ .wd-consent-inner {
110
+ flex-direction: column;
111
+ align-items: stretch;
112
+ padding: 0.85rem 1rem;
113
+ }
114
+ .wd-consent-actions > .wd-consent-button {
115
+ flex: 1;
116
+ }
117
+ }
118
+ </style>
@@ -245,6 +245,14 @@ pre {
245
245
  span, so it sizes like a glyph icon would. Lives here rather than in
246
246
  AppIcon.astro so it's part of the shared stylesheet, not an inline
247
247
  <style> added to every page. */
248
+ /* An image the build gave its file's width and height
249
+ (lib/rehype-image-loading.js): those attributes reserve its place while
250
+ it loads, and this keeps its height following its width when it's shown
251
+ narrower than the file - without it, the height attribute would stretch
252
+ it. :where() adds no specificity, so any rule that sets a height wins. */
253
+ :where(img[data-wd-sized]) {
254
+ height: auto;
255
+ }
248
256
  img.wd-icon-img {
249
257
  display: block;
250
258
  width: 1em;
@@ -306,16 +306,68 @@ const seoFieldsSchema = z.object({
306
306
  // sitemap.xml entirely - both driven off this one flag, since listing
307
307
  // a page in the sitemap while also telling crawlers not to index it
308
308
  // would be self-contradictory.
309
- noindex: z.boolean().optional()
309
+ noindex: z.boolean().optional(),
310
+ // The whole <meta name="robots"> value, for anything `noindex` (always
311
+ // "noindex, nofollow") doesn't say - "noindex, follow", "max-snippet:50".
312
+ // Wins over `noindex`; a value with "noindex" keeps the page out of
313
+ // sitemap.xml and llms.txt the same way (isNoindex(), lib/seo-tags.js).
314
+ robots: z.string().optional(),
315
+ // Any other <meta> tag, name -> content: "google-site-verification",
316
+ // "twitter:site", "og:locale"... One with the name of a tag writedocs
317
+ // writes itself ("og:image", "twitter:image", "description") replaces
318
+ // it. Open Graph names become <meta property>, the rest <meta name> -
319
+ // see seoHead() in lib/seo-tags.js. A page's own are merged over the
320
+ // site's, name by name.
321
+ metatags: z.record(z.string(), z.string()).optional()
322
+ }).strict();
323
+ const pageSeoFieldsSchema = seoFieldsSchema.extend({
324
+ // The <title> and og:title/twitter:title, exactly as written - no site
325
+ // name is added. The page's <h1> and sidebar entry keep `title`.
326
+ title: z.string().optional(),
327
+ // The <meta name="description"> and og/twitter descriptions, when they
328
+ // should differ from the `description` shown under the page's title.
329
+ description: z.string().optional(),
330
+ // The page's canonical URL, when it isn't its own address: a full URL,
331
+ // or a path on the site's domain. A page whose canonical is another
332
+ // address is left out of sitemap.xml.
333
+ canonical: z.string().optional(),
334
+ // The page's own structured data (schema.org JSON-LD): one block, or a
335
+ // list of them, written into the page after the ones writedocs
336
+ // generates (lib/json-ld.js). Any shape - it is the author's to get right.
337
+ jsonLd: z.union([z.record(z.string(), z.unknown()), z.array(z.record(z.string(), z.unknown()))]).optional()
310
338
  }).strict();
311
- function mergeSeo(site, page) {
312
- if (!page) return site;
339
+ const siteSeoFieldsSchema = seoFieldsSchema.extend({
340
+ // Who publishes the site - an Organization block in the home page's
341
+ // structured data, and the `publisher` of every page (lib/json-ld.js).
342
+ // Not derived from `name`: a site is called "Acme Docs", the
343
+ // organization "Acme".
344
+ organization: z.object({
345
+ name: z.string(),
346
+ // The organization's own site. Default: this site's address.
347
+ url: z.string().optional(),
348
+ // A path in the project or a full URL. Default: the site's logo.
349
+ logo: z.string().optional(),
350
+ // Its profiles elsewhere. Default: the URLs in `socials`.
351
+ sameAs: z.array(z.string()).optional()
352
+ }).strict().optional()
353
+ }).strict();
354
+ function mergeSeo(site, page = {}) {
355
+ const pageDecides = page.robots !== void 0 || page.noindex !== void 0;
356
+ const robots = pageDecides ? page.robots : site.robots;
357
+ const noindex = robots !== void 0 ? /\bnoindex\b|\bnone\b/i.test(robots) : pageDecides ? page.noindex : site.noindex;
358
+ const metatags = site.metatags || page.metatags ? { ...site.metatags, ...page.metatags } : void 0;
313
359
  return {
314
360
  ogImage: page.ogImage ?? site.ogImage,
315
361
  ogType: page.ogType ?? site.ogType,
316
362
  twitterCard: page.twitterCard ?? site.twitterCard,
317
363
  keywords: page.keywords ?? site.keywords,
318
- noindex: page.noindex ?? site.noindex
364
+ noindex,
365
+ robots,
366
+ metatags,
367
+ title: page.title,
368
+ description: page.description,
369
+ canonical: page.canonical,
370
+ jsonLd: page.jsonLd
319
371
  };
320
372
  }
321
373
  const MINTLIFY_MODE_ALIASES = { center: "frame", assistant: "default" };
@@ -386,12 +438,16 @@ const pageFrontmatterSchema = z.object({
386
438
  // it wants to override; mergeSeo() falls back to the site-wide default
387
439
  // for anything left unset. See BaseLayout.astro for where this and the
388
440
  // site-wide seo actually get merged and rendered.
389
- seo: seoFieldsSchema.optional(),
441
+ seo: pageSeoFieldsSchema.optional(),
390
442
  // Mintlify's spelling of `seo.noindex` - a top-level `noindex: true`.
391
443
  // Folded into `seo` by the transform below, so everything downstream
392
444
  // (the robots meta tag, sitemap.xml, llms.txt) keeps reading
393
445
  // `seo.noindex` only.
394
446
  noindex: z.boolean().optional(),
447
+ // Mintlify's spellings of `seo.robots` and `seo.canonical`, folded into
448
+ // `seo` the same way.
449
+ robots: z.string().optional(),
450
+ canonical: z.string().optional(),
395
451
  // Mintlify's short navigation label - used for the sidebar and the
396
452
  // topbar dropdown menus in place of `title` ([...slug].astro's
397
453
  // navTitleForSlug). The page's own <h1> and prev/next links keep `title`.
@@ -425,15 +481,28 @@ const pageFrontmatterSchema = z.object({
425
481
  hideFooterPagination: z.boolean().optional(),
426
482
  hideApiMarker: z.boolean().optional()
427
483
  }).transform(
428
- ({ noindex, keywords, "og:image": ogImage, "og:type": ogType, "twitter:card": twitterCard, ...data }) => {
429
- const fromMintlify = { noindex: noindex ?? (data.hidden ? true : void 0), keywords, ogImage, ogType, twitterCard };
484
+ ({ noindex, robots, canonical, keywords, "og:image": ogImage, "og:type": ogType, "twitter:card": twitterCard, ...data }) => {
430
485
  const seo = { ...data.seo };
486
+ const pageRobots = seo.robots ?? robots;
487
+ const fromMintlify = {
488
+ robots,
489
+ canonical,
490
+ noindex: pageRobots !== void 0 ? void 0 : noindex ?? (data.hidden ? true : void 0),
491
+ keywords,
492
+ ogImage,
493
+ ogType,
494
+ twitterCard
495
+ };
431
496
  let changed = false;
432
497
  for (const [key, value] of Object.entries(fromMintlify)) {
433
498
  if (value === void 0 || seo[key] !== void 0) continue;
434
499
  seo[key] = value;
435
500
  changed = true;
436
501
  }
502
+ if (pageRobots !== void 0) {
503
+ seo.noindex = /\bnoindex\b|\bnone\b/i.test(pageRobots);
504
+ changed = true;
505
+ }
437
506
  return changed ? { ...data, seo } : data;
438
507
  }
439
508
  );
@@ -493,7 +562,11 @@ const notFoundSchema = z.object({
493
562
  }).strict().default({});
494
563
  const scriptEntrySchema = z.object({
495
564
  src: z.string().optional(),
496
- content: z.string().optional()
565
+ content: z.string().optional(),
566
+ // With `integrations.consent` on, a script marked `true` loads only
567
+ // once the reader accepts, like the analytics integrations. Without the
568
+ // banner it loads as any other script.
569
+ consent: z.boolean().optional()
497
570
  }).strict().refine((v) => v.src ? !v.content : !!v.content, {
498
571
  message: 'Each scripts.head/scripts.body entry needs exactly one of "src" or "content", not both or neither.'
499
572
  });
@@ -551,6 +624,17 @@ const umamiIntegrationSchema = z.object({
551
624
  const askAiIntegrationSchema = z.object({
552
625
  id: z.string()
553
626
  }).strict();
627
+ const consentSchema = z.union([
628
+ z.boolean(),
629
+ z.object({
630
+ message: z.string().optional(),
631
+ acceptLabel: z.string().optional(),
632
+ declineLabel: z.string().optional(),
633
+ // A link after the message - a privacy or cookie policy.
634
+ policyUrl: z.string().optional(),
635
+ policyLabel: z.string().optional()
636
+ }).strict()
637
+ ]);
554
638
  const integrationsSchema = z.object({
555
639
  ga4: ga4IntegrationSchema.optional(),
556
640
  googleTagManager: googleTagManagerIntegrationSchema.optional(),
@@ -558,7 +642,8 @@ const integrationsSchema = z.object({
558
642
  fathom: fathomIntegrationSchema.optional(),
559
643
  posthog: posthogIntegrationSchema.optional(),
560
644
  umami: umamiIntegrationSchema.optional(),
561
- askAi: askAiIntegrationSchema.optional()
645
+ askAi: askAiIntegrationSchema.optional(),
646
+ consent: consentSchema.optional()
562
647
  }).strict().default({});
563
648
  const docsConfigSchema = z.object({
564
649
  name: z.string(),
@@ -596,7 +681,7 @@ const docsConfigSchema = z.object({
596
681
  // frontmatter `seo` (content.config.ts's docsSchema) overrides these
597
682
  // field by field via mergeSeo(), rather than needing to repeat every
598
683
  // field on every page.
599
- seo: seoFieldsSchema.default({}),
684
+ seo: siteSeoFieldsSchema.default({}),
600
685
  // The "Copy page" menu - see contextMenuSchema above. Absent means on,
601
686
  // with every option; read it through contextMenuOptions().
602
687
  contextMenu: contextMenuSchema.optional(),
@@ -975,7 +1060,9 @@ export {
975
1060
  formatValidationIssuesDetailed,
976
1061
  mergeSeo,
977
1062
  pageFrontmatterSchema,
1063
+ pageSeoFieldsSchema,
978
1064
  seoFieldsSchema,
1065
+ siteSeoFieldsSchema,
979
1066
  unknownRootKeyIssues,
980
1067
  validateDocsConfig
981
1068
  };