@brillout/docpress 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.
@@ -1,4 +1,5 @@
1
1
  export { resolveHeadingsData }
2
+ export type { ActiveCategory }
2
3
 
3
4
  import { assert, isBrowser, jsxToTextContent } from '../utils/server'
4
5
  import type {
@@ -7,7 +8,7 @@ import type {
7
8
  HeadingResolved,
8
9
  HeadingDetachedResolved,
9
10
  } from '../types/Heading'
10
- import type { Config } from '../types/Config'
11
+ import type { Category, Config } from '../types/Config'
11
12
  import { getConfig } from './getConfig'
12
13
  import type { NavItem } from '../NavItemComponent'
13
14
  import type { LinkData } from '../components'
@@ -25,6 +26,12 @@ type PageSectionResolved = {
25
26
  pageSectionLevel: number
26
27
  }
27
28
 
29
+ type ActiveCategory = {
30
+ name: string
31
+ order: NonNullable<Category['order']>
32
+ hide: Category['hide']
33
+ }
34
+
28
35
  function resolveHeadingsData(pageContext: PageContextOriginal) {
29
36
  const config = getConfig()
30
37
 
@@ -37,7 +44,7 @@ function resolveHeadingsData(pageContext: PageContextOriginal) {
37
44
  const { headingsDetachedResolved } = resolved
38
45
  let { headingsResolved } = resolved
39
46
 
40
- const { activeHeading, isDetachedPage, activeCategory } = getActiveHeading(
47
+ const { activeHeading, isDetachedPage, activeCategoryName } = getActiveHeading(
41
48
  headingsResolved,
42
49
  headingsDetachedResolved,
43
50
  pageContext,
@@ -72,6 +79,13 @@ function resolveHeadingsData(pageContext: PageContextOriginal) {
72
79
  }
73
80
  }
74
81
 
82
+ const categoryInfo = config.categories?.[activeCategoryName]
83
+ const activeCategory: ActiveCategory = {
84
+ name: activeCategoryName,
85
+ order: categoryInfo?.order ?? 0,
86
+ hide: categoryInfo?.hide,
87
+ }
88
+
75
89
  const pageContextAddendum = {
76
90
  navItemsAll,
77
91
  navItemsDetached,
@@ -150,7 +164,7 @@ function getActiveHeading(
150
164
  pageContext: { urlPathname: string; exports: Exports },
151
165
  ) {
152
166
  let activeHeading: HeadingResolved | HeadingDetachedResolved | null = null
153
- let activeCategory = 'Miscellaneous'
167
+ let activeCategoryName = 'Miscellaneous'
154
168
  let headingCategory: string | undefined
155
169
  const { urlPathname } = pageContext
156
170
  assert(urlPathname)
@@ -161,7 +175,7 @@ function getActiveHeading(
161
175
  if (heading.url === urlPathname) {
162
176
  activeHeading = heading
163
177
  assert(headingCategory)
164
- activeCategory = headingCategory
178
+ activeCategoryName = headingCategory
165
179
  assert(heading.level === 2, { pageUrl: urlPathname, heading })
166
180
  break
167
181
  }
@@ -183,8 +197,8 @@ function getActiveHeading(
183
197
  ].join('\n'),
184
198
  )
185
199
  }
186
- if (activeHeading.category) activeCategory = activeHeading.category
187
- return { activeHeading, isDetachedPage, activeCategory }
200
+ if (activeHeading.category) activeCategoryName = activeHeading.category
201
+ return { activeHeading, isDetachedPage, activeCategoryName }
188
202
  }
189
203
 
190
204
  function getPageSectionsResolved(
@@ -1,7 +1,14 @@
1
1
  export { resolveHeadingsData };
2
+ export type { ActiveCategory };
3
+ import type { Category } from '../types/Config';
2
4
  import type { NavItem } from '../NavItemComponent';
3
5
  import type { LinkData } from '../components';
4
6
  import type { PageContextOriginal } from './resolvePageContext';
7
+ type ActiveCategory = {
8
+ name: string;
9
+ order: NonNullable<Category['order']>;
10
+ hide: Category['hide'];
11
+ };
5
12
  declare function resolveHeadingsData(pageContext: PageContextOriginal): {
6
13
  navItemsAll: NavItem[];
7
14
  navItemsDetached: NavItem[] | undefined;
@@ -9,5 +16,5 @@ declare function resolveHeadingsData(pageContext: PageContextOriginal): {
9
16
  isLandingPage: boolean;
10
17
  pageTitle: string | null;
11
18
  documentTitle: string;
12
- activeCategory: string;
19
+ activeCategory: ActiveCategory;
13
20
  };
@@ -26,6 +26,7 @@ import { parseMarkdownMini } from '../parseMarkdownMini';
26
26
  import { determineNavItemsColumnLayout } from '../renderer/determineNavItemsColumnLayout';
27
27
  assert(!isBrowser());
28
28
  function resolveHeadingsData(pageContext) {
29
+ var _a, _b;
29
30
  var config = getConfig();
30
31
  {
31
32
  var headings = config.headings, headingsDetached = config.headingsDetached;
@@ -34,8 +35,8 @@ function resolveHeadingsData(pageContext) {
34
35
  var resolved = getHeadingsResolved(config);
35
36
  var headingsDetachedResolved = resolved.headingsDetachedResolved;
36
37
  var headingsResolved = resolved.headingsResolved;
37
- var _a = getActiveHeading(headingsResolved, headingsDetachedResolved, pageContext), activeHeading = _a.activeHeading, isDetachedPage = _a.isDetachedPage, activeCategory = _a.activeCategory;
38
- var _b = getTitles(activeHeading, pageContext, config), documentTitle = _b.documentTitle, isLandingPage = _b.isLandingPage, pageTitle = _b.pageTitle;
38
+ var _c = getActiveHeading(headingsResolved, headingsDetachedResolved, pageContext), activeHeading = _c.activeHeading, isDetachedPage = _c.isDetachedPage, activeCategoryName = _c.activeCategoryName;
39
+ var _d = getTitles(activeHeading, pageContext, config), documentTitle = _d.documentTitle, isLandingPage = _d.isLandingPage, pageTitle = _d.pageTitle;
39
40
  var pageSectionsResolved = getPageSectionsResolved(pageContext, activeHeading);
40
41
  var linksAll = __spreadArray(__spreadArray(__spreadArray([], pageSectionsResolved.map(pageSectionToLinkData), true), headingsResolved.map(headingToLinkData), true), headingsDetachedResolved.map(headingToLinkData), true);
41
42
  var navItemsAll;
@@ -57,6 +58,12 @@ function resolveHeadingsData(pageContext) {
57
58
  });
58
59
  }
59
60
  }
61
+ var categoryInfo = (_a = config.categories) === null || _a === void 0 ? void 0 : _a[activeCategoryName];
62
+ var activeCategory = {
63
+ name: activeCategoryName,
64
+ order: (_b = categoryInfo === null || categoryInfo === void 0 ? void 0 : categoryInfo.order) !== null && _b !== void 0 ? _b : 0,
65
+ hide: categoryInfo === null || categoryInfo === void 0 ? void 0 : categoryInfo.hide,
66
+ };
60
67
  var pageContextAddendum = {
61
68
  navItemsAll: navItemsAll,
62
69
  navItemsDetached: navItemsDetached,
@@ -121,7 +128,7 @@ function getTitles(activeHeading, pageContext, config) {
121
128
  function getActiveHeading(headingsResolved, headingsDetachedResolved, pageContext) {
122
129
  var _a;
123
130
  var activeHeading = null;
124
- var activeCategory = 'Miscellaneous';
131
+ var activeCategoryName = 'Miscellaneous';
125
132
  var headingCategory;
126
133
  var urlPathname = pageContext.urlPathname;
127
134
  assert(urlPathname);
@@ -133,7 +140,7 @@ function getActiveHeading(headingsResolved, headingsDetachedResolved, pageContex
133
140
  if (heading.url === urlPathname) {
134
141
  activeHeading = heading;
135
142
  assert(headingCategory);
136
- activeCategory = headingCategory;
143
+ activeCategoryName = headingCategory;
137
144
  assert(heading.level === 2, { pageUrl: urlPathname, heading: heading });
138
145
  break;
139
146
  }
@@ -156,8 +163,8 @@ function getActiveHeading(headingsResolved, headingsDetachedResolved, pageContex
156
163
  ].join('\n'));
157
164
  }
158
165
  if (activeHeading.category)
159
- activeCategory = activeHeading.category;
160
- return { activeHeading: activeHeading, isDetachedPage: isDetachedPage, activeCategory: activeCategory };
166
+ activeCategoryName = activeHeading.category;
167
+ return { activeHeading: activeHeading, isDetachedPage: isDetachedPage, activeCategoryName: activeCategoryName };
161
168
  }
162
169
  function getPageSectionsResolved(pageContext, activeHeading) {
163
170
  var _a;
@@ -16,7 +16,7 @@ declare function resolvePageContext(pageContext: PageContextOriginal): {
16
16
  isLandingPage: boolean;
17
17
  pageTitle: string | null;
18
18
  documentTitle: string;
19
- activeCategory: string;
19
+ activeCategory: import("./resolveHeadingsData").ActiveCategory;
20
20
  } & {
21
21
  urlPathname: string;
22
22
  meta: {
@@ -1,4 +1,5 @@
1
1
  export type { Config };
2
+ export type { Category };
2
3
  import type { HeadingDefinition, HeadingDetachedDefinition } from './Heading';
3
4
  type Config = {
4
5
  projectInfo: {
@@ -20,6 +21,7 @@ type Config = {
20
21
  };
21
22
  headings: HeadingDefinition[];
22
23
  headingsDetached: HeadingDetachedDefinition[];
24
+ categories?: Record<string, Category>;
23
25
  /** Sets `<meta name="description" content="${tagline}" />` */
24
26
  tagline: string;
25
27
  websiteUrl: string;
@@ -34,3 +36,9 @@ type Config = {
34
36
  navLogoStyle?: React.CSSProperties;
35
37
  navLogoTextStyle?: React.CSSProperties;
36
38
  };
39
+ type Category = {
40
+ /** Order in Algolia search results */
41
+ order?: number;
42
+ /** Hide from Algolia search */
43
+ hide?: boolean;
44
+ };
@@ -26,6 +26,7 @@ type HeadingDefinitionCommon = {
26
26
  type HeadingDetachedDefinition = HeadingDefinitionCommon & {
27
27
  url: string;
28
28
  sectionTitles?: string[];
29
+ category?: string;
29
30
  };
30
31
  type HeadingDefinition = HeadingDefinitionCommon & {
31
32
  url?: null | string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brillout/docpress",
3
- "version": "0.10.18",
3
+ "version": "0.10.20",
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "@brillout/picocolors": "^1.0.10",
@@ -6,6 +6,7 @@ import { assert } from '../utils/server'
6
6
  import type { PageContextResolved } from '../config/resolvePageContext'
7
7
  import { getPageElement } from './getPageElement'
8
8
  import type { OnRenderHtmlAsync } from 'vike/types'
9
+ import { ActiveCategory } from '../config/resolveHeadingsData'
9
10
 
10
11
  const onRenderHtml: OnRenderHtmlAsync = async (
11
12
  pageContext,
@@ -32,7 +33,7 @@ Promise<Awaited<ReturnType<OnRenderHtmlAsync>>> => {
32
33
  ${descriptionTag}
33
34
  <meta name="viewport" content="width=device-width,initial-scale=1">
34
35
  ${getOpenGraphTags(pageContext.urlPathname, pageContextResolved.documentTitle, pageContextResolved.meta)}
35
- <meta name="docsearch:category" content="${pageContextResolved.activeCategory}" />
36
+ ${getAlgoliaTags(pageContextResolved.activeCategory)}
36
37
  </head>
37
38
  <body>
38
39
  <div id="page-view">${dangerouslySkipEscape(pageHtml)}</div>
@@ -40,6 +41,15 @@ Promise<Awaited<ReturnType<OnRenderHtmlAsync>>> => {
40
41
  </html>`
41
42
  }
42
43
 
44
+ function getAlgoliaTags(activeCategory: ActiveCategory) {
45
+ const categoryNameTag = escapeInject`<meta name="algolia:category" content="${activeCategory.name}">`
46
+ if (activeCategory.hide) {
47
+ return escapeInject`${categoryNameTag}<meta name="algolia:category:hide"> `
48
+ } else {
49
+ return escapeInject`${categoryNameTag}<meta name="algolia:category:order" content="${activeCategory.order.toString()}"> `
50
+ }
51
+ }
52
+
43
53
  function getOpenGraphTags(
44
54
  url: string,
45
55
  documentTitle: string,
package/types/Config.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export type { Config }
2
+ export type { Category }
2
3
 
3
4
  import type { HeadingDefinition, HeadingDetachedDefinition } from './Heading'
4
5
 
@@ -22,6 +23,7 @@ type Config = {
22
23
  }
23
24
  headings: HeadingDefinition[]
24
25
  headingsDetached: HeadingDetachedDefinition[]
26
+ categories?: Record<string, Category>
25
27
  /** Sets `<meta name="description" content="${tagline}" />` */
26
28
  tagline: string
27
29
  websiteUrl: string
@@ -36,3 +38,10 @@ type Config = {
36
38
  navLogoStyle?: React.CSSProperties
37
39
  navLogoTextStyle?: React.CSSProperties
38
40
  }
41
+
42
+ type Category = {
43
+ /** Order in Algolia search results */
44
+ order?: number
45
+ /** Hide from Algolia search */
46
+ hide?: boolean
47
+ }
package/types/Heading.ts CHANGED
@@ -30,6 +30,7 @@ type HeadingDefinitionCommon = {
30
30
  type HeadingDetachedDefinition = HeadingDefinitionCommon & {
31
31
  url: string
32
32
  sectionTitles?: string[]
33
+ category?: string
33
34
  }
34
35
 
35
36
  type HeadingDefinition = HeadingDefinitionCommon & {