@writedocs/generator 0.10.18 → 0.10.20

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.
@@ -78,6 +78,7 @@ import { selectorPlacements } from "../lib/selector-placement.js";
78
78
  import { spaceOf } from "../lib/hidden-sections.js";
79
79
  import { navigationPageOrder } from "../lib/pages.js";
80
80
  import { folderRedirects } from "../lib/folder-redirects.js";
81
+ import { oncePerBuild } from "../lib/build-memo.js";
81
82
 
82
83
  // A page is hand-written (the `pages` collection, sourced from anywhere
83
84
  // in the project - docs/ has no special status, see findAllPages() in
@@ -371,7 +372,8 @@ const {
371
372
  const contentDir = process.env.WRITEDOCS_CONTENT_DIR || process.cwd();
372
373
  const packageRoot = process.env.WRITEDOCS_PACKAGE_ROOT || process.cwd();
373
374
  const config = loadDocsConfig(contentDir);
374
- const sections = resolveSections(config.navigation);
375
+ // Once per build, like the lookup tables further down.
376
+ const sections = oncePerBuild("slug:sections", () => resolveSections(config.navigation));
375
377
  // Falls back to an empty stand-in section rather than crashing on
376
378
  // `.pages` below - only reachable for a hidden page (see hiddenRoutes in
377
379
  // getStaticPaths above) on a site whose writedocs.json has no navigation
@@ -379,12 +381,17 @@ const sections = resolveSections(config.navigation);
379
381
  // render in the first place.
380
382
  // An item's own page shown inside its item (landingRoutes above): the item's
381
383
  // path, and its own sidebar if it has one.
382
- const landing = landingIndex === undefined ? undefined : resolveLandings(config.navigation)[landingIndex];
384
+ const landing = landingIndex === undefined ? undefined : oncePerBuild("slug:landings", () => resolveLandings(config.navigation))[landingIndex];
383
385
  const activeSection = landing ? { pages: landing.pages, path: landing.path } : sections[sectionIndex] ?? { pages: [], path: [] };
384
386
 
385
387
  const { Content, headings } = await render(entry);
386
388
  const tocHeadings = headings.filter((h) => h.depth === 2 || h.depth === 3);
387
389
 
390
+ // The lookup tables below are the same for every page, so a build makes
391
+ // them once (oncePerBuild(), lib/build-memo.js) - findAllPages() alone reads
392
+ // every page file of the project, and ran here once per page. In
393
+ // `writedocs dev` they're made again on every request, as before.
394
+ const { titleByFileId, navTitleByFileId, entryByFileId, methodByFileId } = await oncePerBuild("slug:lookups", async () => {
388
395
  const hasGeneratedDocs = fs.existsSync(path.join(writedocsTempDir(contentDir), "generated-docs"));
389
396
  const hasPages = findAllPages(contentDir).length > 0;
390
397
  const [pagesEntries, generatedDocsEntries] = await Promise.all([
@@ -419,6 +426,8 @@ for (const e of entries) {
419
426
  methodByFileId.set(fileId, apiRef.method);
420
427
  }
421
428
  }
429
+ return { titleByFileId, navTitleByFileId, entryByFileId, methodByFileId };
430
+ });
422
431
  const titleForSlug = (slug: string) => titleByFileId.get(slug) ?? slug;
423
432
  const navTitleForSlug = (slug: string) => navTitleByFileId.get(slug) ?? slug;
424
433
  const methodForSlug = (slug: string) => methodByFileId.get(slug) ?? null;
@@ -435,7 +444,9 @@ const hrefForSlug = (slug: string) => {
435
444
  // and what every "is this the active page" comparison below needs, since
436
445
  // navTree/globalDropdowns are built from writedocs.json's file-id space.
437
446
  const currentFileId = fileIdForEntry(contentDir, packageRoot, entry);
438
- const navTree = buildNavTree(activeSection.pages, navTitleForSlug, methodForSlug, navMetaForSlug);
447
+ // A section's tree doesn't depend on which of its pages is open (NavTree.astro
448
+ // marks the current one), so it's built once per section in a build.
449
+ const navTree = oncePerBuild(`slug:nav:${landingIndex === undefined ? `s${sectionIndex}` : `l${landingIndex}`}`, () => buildNavTree(activeSection.pages, navTitleForSlug, methodForSlug, navMetaForSlug));
439
450
  // The ancestor sidebar-group trail above the auto <h1> (Breadcrumbs.astro)
440
451
  // - empty for a page sitting at the top level of its Section with no
441
452
  // enclosing group, in which case [...slug].astro below skips rendering
@@ -486,7 +497,7 @@ const globalDropdowns = buildGlobalDropdowns(
486
497
  const pageSeo = mergeSeo(config.seo, entry.data.seo);
487
498
  // A page with no picture of its own for link previews gets the generated
488
499
  // card (lib/og-image.js, served by src/pages/og/[...slug].png.ts).
489
- if (wantsGeneratedCard(pageSeo, entry.data)) pageSeo.ogImage = ogImagePath(normalizeEntryId(entry.id));
500
+ if (wantsGeneratedCard(pageSeo, entry.data, config.seo)) pageSeo.ogImage = ogImagePath(normalizeEntryId(entry.id));
490
501
  const currentPath = hrefForSlug(currentFileId);
491
502
  // This page in each language, for hreflang (languageAlternates() in
492
503
  // lib/item-pages.js) - a hidden page belongs to no language level.
@@ -12,7 +12,8 @@ import { imageFileFor } from '../../lib/image-size.js';
12
12
  // title and description, the site's primary color (lib/og-image.js).
13
13
  // [...slug].astro points the page's og:image here under the same condition
14
14
  // (wantsGeneratedCard()), so a card is only built for a page that uses it -
15
- // a site with `seo.ogImage` in writedocs.json builds none at all.
15
+ // a site with `seo.ogImage` in writedocs.json builds none at all, and neither
16
+ // does one with `"seo": { "generatedOgImage": false }`.
16
17
  //
17
18
  // A static route like [...slug].md.ts next to it: one file per page at build
18
19
  // time, and built on request in `writedocs dev`.
@@ -36,7 +37,7 @@ export async function getStaticPaths() {
36
37
  const logo = logoForCard(logoPath ? imageFileFor(logoPath, contentDir) : null);
37
38
 
38
39
  return entries
39
- .filter((entry) => wantsGeneratedCard(mergeSeo(config.seo, entry.data.seo), entry.data))
40
+ .filter((entry) => wantsGeneratedCard(mergeSeo(config.seo, entry.data.seo), entry.data, config.seo))
40
41
  .map((entry) => ({
41
42
  params: { slug: normalizeEntryId(entry.id) },
42
43
  props: {
@@ -757,6 +757,11 @@
757
757
  "description": "Other <meta> tags, name to content - like { \"google-site-verification\": \"...\" }. One with the name of a tag writedocs writes (\"og:image\", \"twitter:image\") replaces it.",
758
758
  "markdownDescription": "Other <meta> tags, name to content - like { \"google-site-verification\": \"...\" }. One with the name of a tag writedocs writes (\"og:image\", \"twitter:image\") replaces it."
759
759
  },
760
+ "generatedOgImage": {
761
+ "type": "boolean",
762
+ "description": "Whether a page without an `ogImage` gets a link preview image generated at build time. Default true; set false to skip them, which shortens the build of a large site.",
763
+ "markdownDescription": "Whether a page without an `ogImage` gets a link preview image generated at build time. Default true; set false to skip them, which shortens the build of a large site."
764
+ },
760
765
  "organization": {
761
766
  "type": "object",
762
767
  "properties": {