@brillout/docpress 0.3.12 → 0.4.0

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.
@@ -74,20 +74,23 @@ function getHeadings(config) {
74
74
  const parentHeadings = findParentHeadings(heading, headings);
75
75
  headings.push({ ...heading, parentHeadings });
76
76
  });
77
- const headingsWithoutLink = config.headingsWithoutLink.map((headingsWithoutLink2) => {
78
- const { url, title } = headingsWithoutLink2;
77
+ const headingsDetached = config.headingsDetached.map((headingsDetached2) => {
78
+ const { url, title } = headingsDetached2;
79
79
  assert(
80
80
  headings.find((heading) => heading.url === url) === void 0,
81
- `remove ${headingsWithoutLink2.url} from headingsWithoutLink`
81
+ `remove ${headingsDetached2.url} from headingsDetached`
82
82
  );
83
83
  const titleProcessed = typeof title === "string" ? parseTitle(title) : title;
84
84
  return {
85
- ...headingsWithoutLink2,
86
- title: titleProcessed
85
+ ...headingsDetached2,
86
+ level: 2,
87
+ title: titleProcessed,
88
+ titleInNav: titleProcessed,
89
+ parentHeadings: null
87
90
  };
88
91
  });
89
- assertHeadingsUrl([...headings, ...headingsWithoutLink]);
90
- return { headings, headingsWithoutLink };
92
+ assertHeadingsUrl([...headings, ...headingsDetached]);
93
+ return { headings, headingsDetached };
91
94
  }
92
95
  function findParentHeadings(heading, headings) {
93
96
  const parentHeadings = [];
package/dist/index.d.ts CHANGED
@@ -24,7 +24,7 @@ declare function Emoji({ name, style }: {
24
24
  style?: React$1.CSSProperties;
25
25
  }): JSX.Element;
26
26
 
27
- type HeadingWithoutLink = {
27
+ type HeadingDetachedDefinition = {
28
28
  url: string;
29
29
  title: string | JSX.Element;
30
30
  };
@@ -72,7 +72,7 @@ type Config = {
72
72
  indexName: string;
73
73
  };
74
74
  headings: HeadingDefinition[];
75
- headingsWithoutLink: HeadingWithoutLink[];
75
+ headingsDetached: HeadingDetachedDefinition[];
76
76
  navHeaderMobile: React.ReactNode;
77
77
  navHeader: React.ReactNode;
78
78
  titleNormalCase: boolean;
@@ -128,11 +128,17 @@ type SponsorCompany = {
128
128
  companyLogo: string;
129
129
  website: string;
130
130
  plan: Plan;
131
+ divSize?: Partial<DivSize>;
131
132
  };
132
133
  type SponsorIndividual = {
133
134
  username: string;
134
135
  };
135
136
  type Sponsor = SponsorCompany | SponsorIndividual;
137
+ type DivSize = {
138
+ width: number;
139
+ height: number;
140
+ padding: number;
141
+ };
136
142
  declare function Sponsors(): JSX.Element;
137
143
 
138
144
  declare function CodeBlock({ children, lineBreak }: {
@@ -140,4 +146,4 @@ declare function CodeBlock({ children, lineBreak }: {
140
146
  lineBreak?: true;
141
147
  }): JSX.Element;
142
148
 
143
- export { CodeBlock, Config, Emoji, EmojiName, HeadingDefinition, HeadingWithoutLink, HorizontalLine, ImportMeta, Info, Link, Note, P, ReadingRecommendation, RepoLink, Sponsor, Sponsors, assert, assertUsage, assertWarning, crawlAllFiles, determineSectionTitle, determineSectionUrlHash, filter, isBrowser, isRepoLink, jsxToTextContent, objectAssign };
149
+ export { CodeBlock, Config, Emoji, EmojiName, HeadingDefinition, HeadingDetachedDefinition, HorizontalLine, ImportMeta, Info, Link, Note, P, ReadingRecommendation, RepoLink, Sponsor, Sponsors, assert, assertUsage, assertWarning, crawlAllFiles, determineSectionTitle, determineSectionUrlHash, filter, isBrowser, isRepoLink, jsxToTextContent, objectAssign };
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  isRepoLink,
5
5
  parseTitle,
6
6
  usePageContext
7
- } from "./chunk-IZDN24FQ.js";
7
+ } from "./chunk-H7GTGR6A.js";
8
8
  import {
9
9
  FeatureList
10
10
  } from "./chunk-NVJING6T.js";
@@ -76,9 +76,9 @@ function getTitle({
76
76
  assert(heading);
77
77
  assert(heading === pageContext.activeHeading || !linkIsOnSamePage);
78
78
  const breadcrumbs = [];
79
- if ("parentHeadings" in heading) {
79
+ if (heading.parentHeadings) {
80
80
  breadcrumbs.push(
81
- ...heading.parentHeadings.slice().reverse().map(({ title }) => title)
81
+ ...(heading.parentHeadings ?? []).slice().reverse().map(({ title }) => title)
82
82
  );
83
83
  }
84
84
  breadcrumbs.push(heading.title);
@@ -114,9 +114,9 @@ function getTitle({
114
114
  }
115
115
  function findHeading(href, pageContext) {
116
116
  assert(href.startsWith("/"), `\`href==='${href}'\` but should start with \`/\`.`);
117
- const { headings, headingsWithoutLink } = getHeadings(pageContext.config);
117
+ const { headings, headingsDetached } = getHeadings(pageContext.config);
118
118
  {
119
- const heading2 = headingsWithoutLink.find(({ url }) => href === url);
119
+ const heading2 = headingsDetached.find(({ url }) => href === url);
120
120
  if (heading2) {
121
121
  return heading2;
122
122
  }
@@ -267,6 +267,27 @@ var inlang_default = "/assets/inlang-GFRWND6X.png";
267
267
 
268
268
  // src/components/Sponsors/sponsorsList.ts
269
269
  var individuals = [
270
+ {
271
+ username: "fortezhuo"
272
+ },
273
+ {
274
+ username: "nshelia"
275
+ },
276
+ {
277
+ username: "marcusway"
278
+ },
279
+ {
280
+ username: "edikdeisling"
281
+ },
282
+ {
283
+ username: "AurelienLourot"
284
+ },
285
+ {
286
+ username: "jahredhope"
287
+ },
288
+ {
289
+ username: "charlieforward9"
290
+ },
270
291
  {
271
292
  username: "leonmondria"
272
293
  },
@@ -282,6 +303,9 @@ var individuals = [
282
303
  {
283
304
  username: "ser1us"
284
305
  },
306
+ {
307
+ username: "nikitavoloboev"
308
+ },
285
309
  {
286
310
  username: "samuelstroschein"
287
311
  },
@@ -345,7 +369,10 @@ var companies = [
345
369
  companyName: "Optimizers",
346
370
  companyLogo: optimizers_default,
347
371
  plan: "bronze",
348
- website: "https://www.optimizers.nl/"
372
+ website: "https://www.optimizers.nl/",
373
+ divSize: {
374
+ padding: 20
375
+ }
349
376
  },
350
377
  {
351
378
  companyName: "My Favorite Quilt Store",
@@ -372,8 +399,8 @@ var sponsorsList = [...companies, ...individuals];
372
399
  function Sponsors() {
373
400
  const pageContext = usePageContext();
374
401
  const { projectInfo } = pageContext.config;
375
- const sponsorsCompany = sponsorsList.filter((sponsor) => !("username" in sponsor));
376
- const sponsorsHumanidual = sponsorsList.filter((sponsor) => "username" in sponsor);
402
+ const sponsorsCompanies = sponsorsList.filter(isCompany);
403
+ const sponsorsIndividuals = sponsorsList.filter(isIndividual);
377
404
  return /* @__PURE__ */ React8.createElement("div", {
378
405
  style: { textAlign: "center", marginTop: 19 }
379
406
  }, /* @__PURE__ */ React8.createElement("a", {
@@ -395,12 +422,19 @@ function Sponsors() {
395
422
  style: { maxWidth: 400, display: "inline-block", marginTop: 12, marginBottom: 12 }
396
423
  }, projectInfo.projectNameJsx || projectInfo.projectName, " is free and open source, made possible by wonderful sponsors."), /* @__PURE__ */ React8.createElement("div", {
397
424
  style: { display: "flex", flexWrap: "wrap", justifyContent: "space-evenly", alignItems: "end" }
398
- }, sponsorsCompany.map((sponsor, i) => /* @__PURE__ */ React8.createElement(SponsorDiv, {
425
+ }, sponsorsCompanies.map((sponsor, i) => /* @__PURE__ */ React8.createElement(SponsorDiv, {
399
426
  sponsor,
400
427
  key: i
401
428
  }))), /* @__PURE__ */ React8.createElement("div", {
402
- style: { display: "flex", flexWrap: "wrap", justifyContent: "center", alignItems: "end", marginTop: 20 }
403
- }, sponsorsHumanidual.map((sponsor, i) => /* @__PURE__ */ React8.createElement(SponsorDiv, {
429
+ style: {
430
+ display: "flex",
431
+ flexWrap: "wrap",
432
+ justifyContent: "center",
433
+ alignItems: "end",
434
+ margin: "17px auto",
435
+ maxWidth: 700
436
+ }
437
+ }, sponsorsIndividuals.map((sponsor, i) => /* @__PURE__ */ React8.createElement(SponsorDiv, {
404
438
  sponsor,
405
439
  key: i
406
440
  }))));
@@ -412,32 +446,37 @@ function SponsorDiv({ sponsor }) {
412
446
  let height;
413
447
  let website;
414
448
  let padding;
449
+ let marginHeight;
450
+ let marginWidth;
415
451
  let backgroundColor = "#f0f0f0";
416
452
  let label = null;
417
- if ("username" in sponsor) {
453
+ if (isIndividual(sponsor)) {
418
454
  website = `https://github.com/${sponsor.username}`;
419
455
  imgSrc = `https://github.com/${sponsor.username}.png?size=30`;
420
456
  width = 30;
421
457
  height = 30;
422
458
  padding = 0;
459
+ marginHeight = 5;
460
+ marginWidth = 5;
423
461
  backgroundColor = "none";
424
462
  } else {
425
463
  imgSrc = sponsor.companyLogo;
426
464
  website = sponsor.website;
427
- const size = getSize(sponsor.plan);
465
+ const size = getSize(sponsor);
428
466
  width = size.width;
429
467
  height = size.height;
430
468
  padding = size.padding;
431
469
  imgAlt = sponsor.companyName;
470
+ marginHeight = 20;
471
+ marginWidth = 10;
432
472
  label = /* @__PURE__ */ React8.createElement(Label, {
433
473
  sponsor
434
474
  });
435
475
  }
436
- const marginWidth = 5;
437
476
  return /* @__PURE__ */ React8.createElement("a", {
438
477
  href: website,
439
478
  style: {
440
- margin: `10px ${marginWidth}px`
479
+ margin: `${marginHeight}px ${marginWidth}px`
441
480
  }
442
481
  }, label, /* @__PURE__ */ React8.createElement("div", {
443
482
  style: {
@@ -459,7 +498,7 @@ function SponsorDiv({ sponsor }) {
459
498
  })));
460
499
  }
461
500
  function Label({ sponsor }) {
462
- assert(!("username" in sponsor));
501
+ assert(isCompany(sponsor));
463
502
  const labelBg = getLabelBg(sponsor);
464
503
  const labelIcon = getLabelIcon(sponsor);
465
504
  const labelText = getLabelText(sponsor);
@@ -527,27 +566,39 @@ function getLabelIcon(sponsor) {
527
566
  style: { height: 15, zIndex: 1, marginRight: 5 }
528
567
  });
529
568
  }
530
- function getSize(plan) {
569
+ function getSize(sponsor) {
570
+ const { plan } = sponsor;
571
+ let divSize;
531
572
  if (plan === "platinum") {
532
- return { width: 500, height: 180, padding: 100 };
573
+ divSize = { width: 500, height: 180, padding: 100 };
533
574
  }
534
575
  if (plan === "gold") {
535
- return { width: 400, height: 150, padding: 95 };
576
+ divSize = { width: 400, height: 150, padding: 95 };
536
577
  }
537
578
  if (plan === "silver") {
538
- return { width: 300, height: 100, padding: 45 };
579
+ divSize = { width: 300, height: 100, padding: 45 };
539
580
  }
540
581
  if (plan === "bronze") {
541
- return { width: 200, height: 70, padding: 30 };
582
+ divSize = { width: 200, height: 70, padding: 30 };
542
583
  }
543
584
  if (plan === "indie") {
544
- return { width: 140, height: 50, padding: 20 };
585
+ divSize = { width: 140, height: 50, padding: 20 };
545
586
  }
546
- assert(false);
587
+ assert(divSize);
588
+ if (sponsor.divSize) {
589
+ Object.assign(divSize, sponsor.divSize);
590
+ }
591
+ return divSize;
547
592
  }
548
593
  function capitalizeFirstLetter(word) {
549
594
  return word[0].toUpperCase() + word.slice(1);
550
595
  }
596
+ function isCompany(sponsor) {
597
+ return !isIndividual(sponsor);
598
+ }
599
+ function isIndividual(sponsor) {
600
+ return "username" in sponsor;
601
+ }
551
602
 
552
603
  // src/components/CodeBlock.tsx
553
604
  import React9 from "react";
@@ -6,7 +6,7 @@ import "../chunk-3QC7HYIF.js";
6
6
  // src/autoScrollNav.ts
7
7
  autoScrollNav();
8
8
  function autoScrollNav() {
9
- const navigationEl = document.getElementById("navigation-content");
9
+ const navigationEl = document.getElementById("navigation-content-main");
10
10
  assert(navigationEl);
11
11
  const href = window.location.pathname;
12
12
  const navLinks = Array.from(navigationEl.querySelectorAll(`a[href="${href}"]`));
@@ -29,18 +29,20 @@ function installSectionUrlHashs() {
29
29
  assert(window.location.pathname === "/");
30
30
  return;
31
31
  }
32
- const navigationEl = document.getElementById("navigation-content");
33
- assert(navigationEl);
34
- const docSections = Array.from(document.querySelectorAll("h2"));
35
- docSections.forEach((docSection) => {
36
- if (!docSection.id)
37
- return;
38
- const urlHash = "#" + docSection.id;
39
- assertNavLink(navigationEl, urlHash);
40
- docSection.onclick = () => {
41
- window.location.hash = urlHash;
42
- jumpToSection();
43
- };
32
+ const navigationsEl = Array.from(document.querySelectorAll(".navigation-content"));
33
+ assert(navigationsEl.length > 0);
34
+ navigationsEl.forEach((navigationEl) => {
35
+ const docSections = Array.from(document.querySelectorAll("h2"));
36
+ docSections.forEach((docSection) => {
37
+ if (!docSection.id)
38
+ return;
39
+ const urlHash = "#" + docSection.id;
40
+ assertNavLink(navigationEl, urlHash);
41
+ docSection.onclick = () => {
42
+ window.location.hash = urlHash;
43
+ jumpToSection();
44
+ };
45
+ });
44
46
  });
45
47
  }
46
48
  function assertNavLink(navigationEl, urlHash) {
@@ -93,7 +95,7 @@ function toggleNavExpend() {
93
95
  }
94
96
  function updateColumnWidth() {
95
97
  const navMinWidth = 299;
96
- const navH1Groups = Array.from(document.querySelectorAll(".nav-h1-group"));
98
+ const navH1Groups = Array.from(document.querySelectorAll("#navigation-content-main .nav-h1-group"));
97
99
  const numberOfColumnsMax = navH1Groups.length;
98
100
  const widthAvailable = getViewportWidth();
99
101
  const numberOfColumns = Math.max(1, Math.min(numberOfColumnsMax, Math.floor(widthAvailable / navMinWidth)));
@@ -107,7 +109,7 @@ function updateColumnWidth() {
107
109
  return column;
108
110
  });
109
111
  mergeColumns(columns, numberOfColumns);
110
- const navContent = document.getElementById("navigation-content");
112
+ const navContent = document.getElementById("navigation-content-main");
111
113
  Array.from(navContent.children).forEach((child) => {
112
114
  assert(child.className === "nav-column");
113
115
  });
@@ -18,6 +18,14 @@
18
18
  overflow-y: auto;
19
19
  overscroll-behavior: contain;
20
20
  border-right: 1px solid #eee;
21
+ --background-color: #f0f0f0;
22
+ padding-bottom: 70px;
23
+ }
24
+ .navigation-content {
25
+ margin-top: 20px;
26
+ }
27
+ #navigation-content-detached {
28
+ margin-top: 25px;
21
29
  }
22
30
  #navigation-mask {
23
31
  position: fixed;
@@ -92,14 +100,16 @@ html.navigation-fullscreen #navigation-container {
92
100
  left: 0;
93
101
  background-color: white;
94
102
  }
95
- html.navigation-fullscreen #navigation-header {
103
+ html.navigation-fullscreen #navigation-header,
104
+ html.navigation-fullscreen #navigation-content-detached,
105
+ html.navigation-fullscreen #detached-note {
96
106
  display: none !important;
97
107
  }
98
- html.navigation-fullscreen #navigation-content {
108
+ html.navigation-fullscreen .navigation-content {
99
109
  display: flex;
100
110
  margin: auto;
101
111
  }
102
- html.navigation-fullscreen #navigation-content > .nav-column {
112
+ html.navigation-fullscreen .navigation-content > .nav-column {
103
113
  flex-grow: 1;
104
114
  max-width: 350px;
105
115
  }
@@ -231,13 +241,6 @@ html.navigation-fullscreen .nav-item {
231
241
  /* src/navigation/Navigation-highlight.css */
232
242
 
233
243
  /* src/navigation/Navigation.css */
234
- #navigation-container {
235
- --background-color: #f0f0f0;
236
- padding-bottom: 70px;
237
- }
238
- html.navigation-fullscreen #detached-note {
239
- display: none;
240
- }
241
244
 
242
245
  /* src/navigation/navigation-fullscreen/NavigationFullscreenButton.css */
243
246
  :root {
@@ -4,7 +4,7 @@ import {
4
4
  getHeadings,
5
5
  parseTitle,
6
6
  usePageContext
7
- } from "../chunk-IZDN24FQ.js";
7
+ } from "../chunk-H7GTGR6A.js";
8
8
  import {
9
9
  Emoji,
10
10
  jsxToTextContent,
@@ -184,11 +184,17 @@ function NavigationFullscreenClose() {
184
184
  function Navigation({
185
185
  pageContext
186
186
  }) {
187
- const { isDetachedPage } = pageContext;
187
+ const currentUrl = pageContext.urlPathname;
188
188
  return /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement("div", {
189
189
  id: "navigation-container"
190
- }, /* @__PURE__ */ React3.createElement(NavigationHeader, null), isDetachedPage && /* @__PURE__ */ React3.createElement(DetachedPageNote, null), /* @__PURE__ */ React3.createElement(NavigationContent, {
191
- pageContext
190
+ }, /* @__PURE__ */ React3.createElement(NavigationHeader, null), pageContext.detachedPageHeadings && /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(NavigationContent, {
191
+ id: "navigation-content-detached",
192
+ headings: pageContext.detachedPageHeadings,
193
+ currentUrl
194
+ }), /* @__PURE__ */ React3.createElement(DetachedPageNote, null)), /* @__PURE__ */ React3.createElement(NavigationContent, {
195
+ id: "navigation-content-main",
196
+ headings: pageContext.headingsWithSubHeadings,
197
+ currentUrl
192
198
  }), /* @__PURE__ */ React3.createElement(NavigationFullscreenClose, null)));
193
199
  }
194
200
  function NavigationMask() {
@@ -196,13 +202,12 @@ function NavigationMask() {
196
202
  id: "navigation-mask"
197
203
  });
198
204
  }
199
- function NavigationContent({
200
- pageContext
201
- }) {
202
- const headings = getHeadingsWithComputedProps(pageContext);
205
+ function NavigationContent(props) {
206
+ const headings = getHeadingsWithComputedProps(props.headings, props.currentUrl);
203
207
  const headingsGrouped = groupHeadings(headings);
204
208
  return /* @__PURE__ */ React3.createElement("div", {
205
- id: "navigation-content"
209
+ id: props.id,
210
+ className: "navigation-content"
206
211
  }, /* @__PURE__ */ React3.createElement("div", {
207
212
  className: "nav-column",
208
213
  style: { position: "relative" }
@@ -247,8 +252,9 @@ function Heading({
247
252
  }
248
253
  function groupHeadings(headings) {
249
254
  const headingsGrouped = [];
255
+ const headingLevelMin = Math.min(...headings.map((h) => h.level));
250
256
  headings.forEach((heading) => {
251
- if (heading.level === 1) {
257
+ if (heading.level === headingLevelMin) {
252
258
  headingsGrouped.push({ ...heading, headings: [] });
253
259
  } else {
254
260
  headingsGrouped[headingsGrouped.length - 1].headings.push(heading);
@@ -256,18 +262,17 @@ function groupHeadings(headings) {
256
262
  });
257
263
  return headingsGrouped;
258
264
  }
259
- function getHeadingsWithComputedProps(pageContext) {
260
- const { headingsWithSubHeadings, urlPathname } = pageContext;
261
- return headingsWithSubHeadings.map((heading, i) => {
265
+ function getHeadingsWithComputedProps(headings, currentUrl) {
266
+ return headings.map((heading, i) => {
262
267
  var _a2;
263
268
  assert([1, 2, 3, 4].includes(heading.level), heading);
264
- const headingPrevious = headingsWithSubHeadings[i - 1];
265
- const headingNext = headingsWithSubHeadings[i + 1];
269
+ const headingPrevious = headings[i - 1];
270
+ const headingNext = headings[i + 1];
266
271
  let isActiveFirst = false;
267
272
  let isActiveLast = false;
268
273
  let isActive = false;
269
- if (heading.url === urlPathname) {
270
- assert(heading.level === 2, { urlPathname });
274
+ if (heading.url === currentUrl) {
275
+ assert(heading.level === 2, { currentUrl });
271
276
  isActive = true;
272
277
  isActiveFirst = true;
273
278
  if ((headingNext == null ? void 0 : headingNext.level) !== 3) {
@@ -282,7 +287,7 @@ function getHeadingsWithComputedProps(pageContext) {
282
287
  }
283
288
  const isFirstOfItsKind = heading.level !== (headingPrevious == null ? void 0 : headingPrevious.level);
284
289
  const isLastOfItsKind = heading.level !== (headingNext == null ? void 0 : headingNext.level);
285
- const isChildOfListHeading = !!((_a2 = heading.parentHeadings[0]) == null ? void 0 : _a2.isListTitle);
290
+ const isChildOfListHeading = !!heading.parentHeadings && !!((_a2 = heading.parentHeadings[0]) == null ? void 0 : _a2.isListTitle);
286
291
  return {
287
292
  ...heading,
288
293
  computed: {
@@ -304,8 +309,8 @@ function DetachedPageNote() {
304
309
  textAlign: "left",
305
310
  marginLeft: 10,
306
311
  marginRight: 10,
307
- marginTop: 30,
308
- marginBottom: -8,
312
+ marginTop: 25,
313
+ marginBottom: -5,
309
314
  borderRadius: 5,
310
315
  padding: 10
311
316
  }
@@ -427,11 +432,19 @@ function getConfig() {
427
432
  // src/config/resolvePageContext.ts
428
433
  function resolvePageContext(pageContext) {
429
434
  const config = getConfig();
430
- const { headings, headingsWithoutLink } = getHeadings(config);
431
- const { activeHeading, activeNavigationHeading } = findHeading(headings, headingsWithoutLink, pageContext);
432
- const headingsWithSubHeadings = getHeadingsWithSubHeadings(headings, pageContext, activeNavigationHeading);
433
- const { title, isLandingPage, pageTitle, isDetachedPage } = getMetaData(
434
- headingsWithoutLink,
435
+ const { headings, headingsDetached } = getHeadings(config);
436
+ const { activeHeading, activeNavigationHeading } = findHeading(headings, headingsDetached, pageContext);
437
+ let headingsWithSubHeadings;
438
+ let detachedPageHeadings;
439
+ if (activeNavigationHeading) {
440
+ detachedPageHeadings = null;
441
+ headingsWithSubHeadings = getHeadingsWithSubHeadings(headings, pageContext, activeNavigationHeading);
442
+ } else {
443
+ detachedPageHeadings = [activeHeading, ...getPageHeadings(pageContext, activeHeading)];
444
+ headingsWithSubHeadings = headings;
445
+ }
446
+ const { title, isLandingPage, pageTitle } = getMetaData(
447
+ headingsDetached,
435
448
  activeNavigationHeading,
436
449
  pageContext,
437
450
  config
@@ -452,26 +465,23 @@ function resolvePageContext(pageContext) {
452
465
  activeHeading,
453
466
  headings,
454
467
  headingsWithSubHeadings,
468
+ detachedPageHeadings,
455
469
  isLandingPage,
456
- isDetachedPage,
457
470
  pageTitle,
458
471
  config
459
472
  });
460
473
  return pageContextResolved;
461
474
  }
462
- function getMetaData(headingsWithoutLink, activeNavigationHeading, pageContext, config) {
475
+ function getMetaData(headingsDetached, activeNavigationHeading, pageContext, config) {
463
476
  const url = pageContext.urlOriginal;
464
477
  let title;
465
478
  let pageTitle;
466
- let isDetachedPage;
467
479
  if (activeNavigationHeading) {
468
480
  title = activeNavigationHeading.titleDocument || jsxToTextContent(activeNavigationHeading.title);
469
481
  pageTitle = activeNavigationHeading.title;
470
- isDetachedPage = false;
471
482
  } else {
472
- pageTitle = headingsWithoutLink.find((h) => h.url === url).title;
483
+ pageTitle = headingsDetached.find((h) => h.url === url).title;
473
484
  title = jsxToTextContent(pageTitle);
474
- isDetachedPage = true;
475
485
  }
476
486
  const isLandingPage = url === "/";
477
487
  if (!isLandingPage) {
@@ -480,9 +490,9 @@ function getMetaData(headingsWithoutLink, activeNavigationHeading, pageContext,
480
490
  if (isLandingPage) {
481
491
  pageTitle = null;
482
492
  }
483
- return { title, isLandingPage, pageTitle, isDetachedPage };
493
+ return { title, isLandingPage, pageTitle };
484
494
  }
485
- function findHeading(headings, headingsWithoutLink, pageContext) {
495
+ function findHeading(headings, headingsDetached, pageContext) {
486
496
  let activeNavigationHeading = null;
487
497
  let activeHeading = null;
488
498
  assert(pageContext.urlOriginal);
@@ -495,7 +505,7 @@ function findHeading(headings, headingsWithoutLink, pageContext) {
495
505
  }
496
506
  });
497
507
  if (!activeHeading) {
498
- activeHeading = headingsWithoutLink.find(({ url }) => pageUrl === url) ?? null;
508
+ activeHeading = headingsDetached.find(({ url }) => pageUrl === url) ?? null;
499
509
  }
500
510
  const debugInfo = {
501
511
  msg: "Heading not found for url: " + pageUrl,
@@ -509,34 +519,43 @@ function getHeadingsWithSubHeadings(headings, pageContext, activeNavigationHeadi
509
519
  const headingsWithSubHeadings = headings.slice();
510
520
  if (activeNavigationHeading === null)
511
521
  return headingsWithSubHeadings;
522
+ const pageHeadings = getPageHeadings(pageContext, activeNavigationHeading);
512
523
  const activeHeadingIdx = headingsWithSubHeadings.indexOf(activeNavigationHeading);
513
524
  assert(activeHeadingIdx >= 0);
514
- const pageHeadings = pageContext.exports.headings || [];
515
525
  pageHeadings.forEach((pageHeading, i) => {
516
- const title = parseTitle(pageHeading.title);
517
- const url = pageHeading.headingId && "#" + pageHeading.headingId;
518
- assert(
519
- pageHeading.headingLevel !== 3,
520
- "Wrong page heading level `" + pageHeading.headingLevel + "` (it should be `<h2>`) for sub-heading `" + pageHeading.title + "` of page `" + pageContext.urlOriginal + "`."
521
- );
522
- if (pageHeading.headingLevel === 2) {
526
+ headingsWithSubHeadings.splice(activeHeadingIdx + 1 + i, 0, pageHeading);
527
+ });
528
+ return headingsWithSubHeadings;
529
+ }
530
+ function getPageHeadings(pageContext, currentHeading) {
531
+ const pageHeadings = [];
532
+ const markdownHeadings = pageContext.exports.headings ?? [];
533
+ markdownHeadings.forEach((markdownHeading) => {
534
+ const title = parseTitle(markdownHeading.title);
535
+ const url = markdownHeading.headingId && "#" + markdownHeading.headingId;
536
+ if (markdownHeading.headingLevel === 3) {
537
+ console.warn(
538
+ "Wrong page heading level `" + markdownHeading.headingLevel + "` (it should be `<h2>`) for sub-heading `" + markdownHeading.title + "` of page `" + pageContext.urlOriginal + "`."
539
+ );
540
+ }
541
+ if (markdownHeading.headingLevel === 2) {
523
542
  const heading = {
524
543
  url,
525
544
  title,
526
- parentHeadings: [activeNavigationHeading, ...activeNavigationHeading.parentHeadings],
545
+ parentHeadings: [currentHeading, ...currentHeading.parentHeadings ?? []],
527
546
  titleInNav: title,
528
547
  level: 3
529
548
  };
530
- headingsWithSubHeadings.splice(activeHeadingIdx + 1 + i, 0, heading);
549
+ pageHeadings.push(heading);
531
550
  }
532
551
  });
533
- if (activeNavigationHeading == null ? void 0 : activeNavigationHeading.sectionTitles) {
534
- activeNavigationHeading.sectionTitles.forEach((sectionTitle) => {
535
- const pageHeadingTitles = pageHeadings.map((h) => h.title);
552
+ if (currentHeading == null ? void 0 : currentHeading.sectionTitles) {
553
+ currentHeading.sectionTitles.forEach((sectionTitle) => {
554
+ const pageHeadingTitles = markdownHeadings.map((h) => h.title);
536
555
  assert(pageHeadingTitles.includes(sectionTitle), { pageHeadingTitles, sectionTitle });
537
556
  });
538
557
  }
539
- return headingsWithSubHeadings;
558
+ return pageHeadings;
540
559
  }
541
560
 
542
561
  // src/algolia/DocSearch.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brillout/docpress",
3
- "version": "0.3.12",
3
+ "version": "0.4.0",
4
4
  "scripts": {
5
5
  "// Check types while developing": "",
6
6
  "types": "tsc --noEmit --watch",