@brillout/docpress 0.8.4 → 0.8.6

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/+config.ts CHANGED
@@ -15,8 +15,10 @@ export default {
15
15
  Layout: {
16
16
  env: { client: true, server: true },
17
17
  },
18
+ TopNavigation: {
19
+ env: { client: true, server: true },
20
+ },
18
21
  },
19
-
20
22
  prefetch: {
21
23
  staticAssets: 'hover',
22
24
  pageContext: Infinity,
@@ -32,6 +34,7 @@ declare global {
32
34
  }
33
35
  interface Config {
34
36
  Layout?: ReactComponent | null | ImportString
37
+ TopNavigation?: ReactComponent
35
38
  }
36
39
  }
37
40
  }
package/Layout.tsx CHANGED
@@ -5,7 +5,7 @@ import React from 'react'
5
5
  import { NavigationContent } from './navigation/Navigation'
6
6
  import { EditPageNote } from './components/EditPageNote'
7
7
  import { parseTitle } from './parseTitle'
8
- import { usePageContext } from './renderer/usePageContext'
8
+ import { usePageContext, usePageContext2 } from './renderer/usePageContext'
9
9
  import { Links } from './Links'
10
10
  import { toggleMenuModal } from './MenuModal'
11
11
  import { MenuModal } from './MenuModal'
@@ -13,6 +13,7 @@ import { autoScrollNav_SSR } from './autoScrollNav'
13
13
  import { SearchLink } from './docsearch/SearchLink'
14
14
  import { navigate } from 'vike/client/router'
15
15
  import { css } from './utils/css'
16
+ import { PassThrough } from './utils/PassTrough'
16
17
 
17
18
  const mainViewWidthMax = 800
18
19
  const mainViewPadding = 20
@@ -54,7 +55,7 @@ function Layout({ children }: { children: React.ReactNode }) {
54
55
  style={{
55
56
  ['--bg-color']: '#f5f5f7',
56
57
  ['--block-margin']: `${blockMargin}px`,
57
- ['--icon-padding']: '8px',
58
+ ['--icon-text-padding']: '8px',
58
59
  }}
59
60
  >
60
61
  <MenuModal />
@@ -195,16 +196,16 @@ function PageContent({ children }: { children: React.ReactNode }) {
195
196
  function NavMobile() {
196
197
  return (
197
198
  <div id="nav-mobile">
198
- <NavigationHeader headerHeight={70} headerPadding={12} style={{ justifyContent: 'center' }} />
199
+ <NavigationHeader headerHeight={70} iconSize={40} paddingLeft={12} style={{ justifyContent: 'center' }} />
199
200
  </div>
200
201
  )
201
202
  }
202
203
 
203
204
  function NavTop() {
204
- const pageContext = usePageContext()
205
- const { topNavigationList, topNavigationStyle } = pageContext
205
+ const pageContext2 = usePageContext2()
206
206
  const paddingSize = 35
207
207
  const padding = `0 ${paddingSize}px`
208
+ const TopNavigation = pageContext2.config.TopNavigation || PassThrough
208
209
  return (
209
210
  <div
210
211
  id="top-navigation"
@@ -217,30 +218,13 @@ function NavTop() {
217
218
  textDecoration: 'none',
218
219
  marginBottom: 'var(--block-margin)',
219
220
  backgroundColor: 'var(--bg-color)',
221
+ ['--padding-side']: `${paddingSize}px`,
220
222
  fontSize: '1.06em',
221
223
  color: '#666',
222
- ...topNavigationStyle,
223
224
  }}
224
225
  >
225
226
  <div style={{ display: 'flex', alignItems: 'center', height: 70 }}>
226
- {topNavigationList.map(({ title, url }) => (
227
- <a
228
- href={url!}
229
- key={url}
230
- style={{
231
- color: 'inherit',
232
- height: '100%',
233
- display: 'inline-flex',
234
- alignItems: 'center',
235
- justifyContent: 'center',
236
- cursor: 'pointer',
237
- padding,
238
- marginRight: 7,
239
- }}
240
- >
241
- {title}
242
- </a>
243
- ))}
227
+ <TopNavigation />
244
228
  <SearchLink style={{ padding }} />
245
229
  <MenuLink style={{ padding }} />
246
230
  <Links style={{ display: 'inline-flex', padding, marginLeft: -8 }} />
@@ -253,7 +237,6 @@ function NavLeft() {
253
237
  const pageContext = usePageContext()
254
238
  const { navItems, navItemsAll, isDetachedPage } = pageContext
255
239
  const headerHeight = 60
256
- const headerPadding = 10
257
240
  return (
258
241
  <>
259
242
  <div
@@ -270,7 +253,7 @@ function NavLeft() {
270
253
  top: 0,
271
254
  }}
272
255
  >
273
- <NavigationHeader {...{ headerHeight, headerPadding }} />
256
+ <NavigationHeader headerHeight={headerHeight} iconSize={39} paddingLeft={6} />
274
257
  <div
275
258
  style={{
276
259
  backgroundColor: 'var(--bg-color)',
@@ -309,11 +292,11 @@ function NavLeft() {
309
292
 
310
293
  function NavigationHeader({
311
294
  headerHeight,
312
- headerPadding,
295
+ iconSize,
313
296
  style,
314
- }: { headerHeight: number; headerPadding: number; style?: React.CSSProperties }) {
297
+ paddingLeft,
298
+ }: { headerHeight: number; iconSize: number; paddingLeft: number; style?: React.CSSProperties }) {
315
299
  const pageContext = usePageContext()
316
- const iconSize = headerHeight - 2 * headerPadding
317
300
  /*
318
301
  const {projectName} = pageContext.meta
319
302
  /*/
@@ -323,8 +306,9 @@ function NavigationHeader({
323
306
  const childrenStyle: React.CSSProperties = {
324
307
  justifyContent: 'center',
325
308
  fontSize: isProjectNameShort ? '4.8cqw' : '4.5cqw',
326
- ['--icon-padding']: '1.8cqw',
309
+ ['--icon-text-padding']: '1.8cqw',
327
310
  }
311
+ const marginLeft = -10
328
312
  return (
329
313
  <div
330
314
  style={{
@@ -350,9 +334,8 @@ function NavigationHeader({
350
334
  color: 'inherit',
351
335
  textDecoration: 'none',
352
336
  height: '100%',
353
- padding: `${headerPadding}px 0`,
354
- paddingLeft: 4 + 10,
355
- marginLeft: -10,
337
+ paddingLeft: paddingLeft + marginLeft * -1,
338
+ marginLeft: marginLeft,
356
339
  ...childrenStyle,
357
340
  justifyContent: 'flex-start',
358
341
  flexGrow: 0.5,
@@ -372,8 +355,8 @@ function NavigationHeader({
372
355
  />
373
356
  <span
374
357
  style={{
375
- marginLeft: `calc(var(--icon-padding) + 2px)`,
376
- fontSize: isProjectNameShort ? '1.7em' : '1.3em',
358
+ marginLeft: `calc(var(--icon-text-padding) + 2px)`,
359
+ fontSize: isProjectNameShort ? '1.65em' : '1.3em',
377
360
  }}
378
361
  >
379
362
  {projectName}
@@ -425,7 +408,7 @@ function MenuLink(props: PropsAnchor) {
425
408
  function MenuIcon() {
426
409
  return (
427
410
  <svg
428
- style={{ marginRight: 'calc(var(--icon-padding) + 2px)', lineHeight: 0, width: '1.3em' }}
411
+ style={{ marginRight: 'calc(var(--icon-text-padding) + 2px)', lineHeight: 0, width: '1.3em' }}
429
412
  className="decolorize-6"
430
413
  viewBox="0 0 448 512"
431
414
  >
@@ -37,7 +37,11 @@ function resolveHeadingsData(pageContext: PageContextOriginal) {
37
37
  const { headingsDetachedResolved } = resolved
38
38
  let { headingsResolved } = resolved
39
39
 
40
- const { activeHeading, isDetachedPage } = getActiveHeading(headingsResolved, headingsDetachedResolved, pageContext)
40
+ const { activeHeading, isDetachedPage, activeCategory } = getActiveHeading(
41
+ headingsResolved,
42
+ headingsDetachedResolved,
43
+ pageContext,
44
+ )
41
45
 
42
46
  const { documentTitle, isLandingPage, pageTitle } = getTitles(activeHeading, pageContext, config)
43
47
 
@@ -72,10 +76,6 @@ function resolveHeadingsData(pageContext: PageContextOriginal) {
72
76
  }
73
77
  }
74
78
 
75
- const topNavigationList = headingsResolved
76
- .filter((heading) => heading.topNavigation)
77
- .map((h) => ({ title: typeof h.topNavigation === 'string' ? h.topNavigation : h.title, url: h.url }))
78
-
79
79
  const pageContextAddendum = {
80
80
  isDetachedPage,
81
81
  navItems,
@@ -84,9 +84,10 @@ function resolveHeadingsData(pageContext: PageContextOriginal) {
84
84
  isLandingPage,
85
85
  pageTitle,
86
86
  documentTitle,
87
- topNavigationList,
88
87
  // TODO: don't pass to client-side
89
88
  columnLayouts,
89
+ // TODO: don't pass to client-side
90
+ activeCategory,
90
91
  }
91
92
  return pageContextAddendum
92
93
  }
@@ -153,14 +154,22 @@ function getActiveHeading(
153
154
  pageContext: { urlPathname: string; exports: Exports },
154
155
  ) {
155
156
  let activeHeading: HeadingResolved | HeadingDetachedResolved | null = null
157
+ let activeCategory = 'Miscellaneous'
158
+ let headingCategory: string | undefined
156
159
  const { urlPathname } = pageContext
157
160
  assert(urlPathname)
158
- headingsResolved.forEach((heading) => {
161
+ for (const heading of headingsResolved) {
162
+ if (heading.level === 1) {
163
+ headingCategory = heading.title
164
+ }
159
165
  if (heading.url === urlPathname) {
160
166
  activeHeading = heading
167
+ assert(headingCategory)
168
+ activeCategory = headingCategory
161
169
  assert(heading.level === 2, { pageUrl: urlPathname, heading })
170
+ break
162
171
  }
163
- })
172
+ }
164
173
  const isDetachedPage = !activeHeading
165
174
  if (!activeHeading) {
166
175
  activeHeading = headingsDetachedResolved.find(({ url }) => urlPathname === url) ?? null
@@ -178,7 +187,8 @@ function getActiveHeading(
178
187
  ].join('\n'),
179
188
  )
180
189
  }
181
- return { activeHeading, isDetachedPage }
190
+ if (activeHeading.category) activeCategory = activeHeading.category
191
+ return { activeHeading, isDetachedPage, activeCategory }
182
192
  }
183
193
 
184
194
  function getPageSectionsResolved(
@@ -30,7 +30,6 @@ function resolvePageContext(pageContext: PageContextOriginal) {
30
30
  twitterHandle,
31
31
  bannerUrl,
32
32
  websiteUrl,
33
- topNavigationStyle,
34
33
  projectInfo: { projectName },
35
34
  } = config
36
35
  objectAssign(pageContextResolved, {
@@ -44,7 +43,6 @@ function resolvePageContext(pageContext: PageContextOriginal) {
44
43
  tagline,
45
44
  algolia,
46
45
  },
47
- topNavigationStyle,
48
46
  config,
49
47
  })
50
48
 
package/dist/+config.d.ts CHANGED
@@ -16,6 +16,12 @@ declare const _default: {
16
16
  server: true;
17
17
  };
18
18
  };
19
+ TopNavigation: {
20
+ env: {
21
+ client: true;
22
+ server: true;
23
+ };
24
+ };
19
25
  };
20
26
  prefetch: {
21
27
  staticAssets: "hover";
@@ -32,6 +38,7 @@ declare global {
32
38
  }
33
39
  interface Config {
34
40
  Layout?: ReactComponent | null | ImportString;
41
+ TopNavigation?: ReactComponent;
35
42
  }
36
43
  }
37
44
  }
package/dist/+config.js CHANGED
@@ -12,6 +12,9 @@ export default {
12
12
  Layout: {
13
13
  env: { client: true, server: true },
14
14
  },
15
+ TopNavigation: {
16
+ env: { client: true, server: true },
17
+ },
15
18
  },
16
19
  prefetch: {
17
20
  staticAssets: 'hover',
@@ -10,9 +10,6 @@ declare function resolveHeadingsData(pageContext: PageContextOriginal): {
10
10
  isLandingPage: boolean;
11
11
  pageTitle: string | null;
12
12
  documentTitle: string;
13
- topNavigationList: {
14
- title: string;
15
- url: string | null | undefined;
16
- }[];
17
13
  columnLayouts: number[][];
14
+ activeCategory: string;
18
15
  };
@@ -34,7 +34,7 @@ function resolveHeadingsData(pageContext) {
34
34
  var resolved = getHeadingsResolved(config);
35
35
  var headingsDetachedResolved = resolved.headingsDetachedResolved;
36
36
  var headingsResolved = resolved.headingsResolved;
37
- var _a = getActiveHeading(headingsResolved, headingsDetachedResolved, pageContext), activeHeading = _a.activeHeading, isDetachedPage = _a.isDetachedPage;
37
+ var _a = getActiveHeading(headingsResolved, headingsDetachedResolved, pageContext), activeHeading = _a.activeHeading, isDetachedPage = _a.isDetachedPage, activeCategory = _a.activeCategory;
38
38
  var _b = getTitles(activeHeading, pageContext, config), documentTitle = _b.documentTitle, isLandingPage = _b.isLandingPage, pageTitle = _b.pageTitle;
39
39
  var pageSectionsResolved = getPageSectionsResolved(pageContext, activeHeading);
40
40
  var linksAll = __spreadArray(__spreadArray(__spreadArray([], pageSectionsResolved.map(pageSectionToLinkData), true), headingsResolved.map(headingToLinkData), true), headingsDetachedResolved.map(headingToLinkData), true);
@@ -61,9 +61,6 @@ function resolveHeadingsData(pageContext) {
61
61
  });
62
62
  }
63
63
  }
64
- var topNavigationList = headingsResolved
65
- .filter(function (heading) { return heading.topNavigation; })
66
- .map(function (h) { return ({ title: typeof h.topNavigation === 'string' ? h.topNavigation : h.title, url: h.url }); });
67
64
  var pageContextAddendum = {
68
65
  isDetachedPage: isDetachedPage,
69
66
  navItems: navItems,
@@ -72,9 +69,10 @@ function resolveHeadingsData(pageContext) {
72
69
  isLandingPage: isLandingPage,
73
70
  pageTitle: pageTitle,
74
71
  documentTitle: documentTitle,
75
- topNavigationList: topNavigationList,
76
72
  // TODO: don't pass to client-side
77
73
  columnLayouts: columnLayouts,
74
+ // TODO: don't pass to client-side
75
+ activeCategory: activeCategory,
78
76
  };
79
77
  return pageContextAddendum;
80
78
  }
@@ -127,14 +125,23 @@ function getTitles(activeHeading, pageContext, config) {
127
125
  function getActiveHeading(headingsResolved, headingsDetachedResolved, pageContext) {
128
126
  var _a;
129
127
  var activeHeading = null;
128
+ var activeCategory = 'Miscellaneous';
129
+ var headingCategory;
130
130
  var urlPathname = pageContext.urlPathname;
131
131
  assert(urlPathname);
132
- headingsResolved.forEach(function (heading) {
132
+ for (var _i = 0, headingsResolved_1 = headingsResolved; _i < headingsResolved_1.length; _i++) {
133
+ var heading = headingsResolved_1[_i];
134
+ if (heading.level === 1) {
135
+ headingCategory = heading.title;
136
+ }
133
137
  if (heading.url === urlPathname) {
134
138
  activeHeading = heading;
139
+ assert(headingCategory);
140
+ activeCategory = headingCategory;
135
141
  assert(heading.level === 2, { pageUrl: urlPathname, heading: heading });
142
+ break;
136
143
  }
137
- });
144
+ }
138
145
  var isDetachedPage = !activeHeading;
139
146
  if (!activeHeading) {
140
147
  activeHeading = (_a = headingsDetachedResolved.find(function (_a) {
@@ -152,7 +159,9 @@ function getActiveHeading(headingsResolved, headingsDetachedResolved, pageContex
152
159
  .join('\n'),
153
160
  ].join('\n'));
154
161
  }
155
- return { activeHeading: activeHeading, isDetachedPage: isDetachedPage };
162
+ if (activeHeading.category)
163
+ activeCategory = activeHeading.category;
164
+ return { activeHeading: activeHeading, isDetachedPage: isDetachedPage, activeCategory: activeCategory };
156
165
  }
157
166
  function getPageSectionsResolved(pageContext, activeHeading) {
158
167
  var _a;
@@ -17,11 +17,8 @@ declare function resolvePageContext(pageContext: PageContextOriginal): {
17
17
  isLandingPage: boolean;
18
18
  pageTitle: string | null;
19
19
  documentTitle: string;
20
- topNavigationList: {
21
- title: string;
22
- url: string | null | undefined;
23
- }[];
24
20
  columnLayouts: number[][];
21
+ activeCategory: string;
25
22
  } & {
26
23
  urlPathname: string;
27
24
  meta: {
@@ -37,6 +34,5 @@ declare function resolvePageContext(pageContext: PageContextOriginal): {
37
34
  indexName: string;
38
35
  } | null;
39
36
  };
40
- topNavigationStyle: import("react").CSSProperties | undefined;
41
37
  config: import("../types/Config").Config;
42
38
  };
@@ -6,7 +6,7 @@ function resolvePageContext(pageContext) {
6
6
  var pageContextResolved = {};
7
7
  objectAssign(pageContextResolved, resolveHeadingsData(pageContext));
8
8
  var config = getConfig();
9
- var faviconUrl = config.faviconUrl, algolia = config.algolia, tagline = config.tagline, twitterHandle = config.twitterHandle, bannerUrl = config.bannerUrl, websiteUrl = config.websiteUrl, topNavigationStyle = config.topNavigationStyle, projectName = config.projectInfo.projectName;
9
+ var faviconUrl = config.faviconUrl, algolia = config.algolia, tagline = config.tagline, twitterHandle = config.twitterHandle, bannerUrl = config.bannerUrl, websiteUrl = config.websiteUrl, projectName = config.projectInfo.projectName;
10
10
  objectAssign(pageContextResolved, {
11
11
  urlPathname: pageContext.urlPathname, // TODO: remove
12
12
  meta: {
@@ -18,7 +18,6 @@ function resolvePageContext(pageContext) {
18
18
  tagline: tagline,
19
19
  algolia: algolia,
20
20
  },
21
- topNavigationStyle: topNavigationStyle,
22
21
  config: config,
23
22
  });
24
23
  return pageContextResolved;
@@ -18,7 +18,6 @@ type Config = {
18
18
  };
19
19
  headings: HeadingDefinition[];
20
20
  headingsDetached: HeadingDetachedDefinition[];
21
- topNavigationStyle?: React.CSSProperties;
22
21
  /** Sets `<meta name="description" content="${tagline}" />` */
23
22
  tagline: string;
24
23
  websiteUrl: string;
@@ -7,10 +7,10 @@ type HeadingResolved = {
7
7
  level: number;
8
8
  title: string;
9
9
  titleInNav: string;
10
- topNavigation?: true | string;
11
10
  linkBreadcrumb: string[];
12
11
  sectionTitles?: string[];
13
12
  menuModalFullWidth?: true;
13
+ category?: string;
14
14
  } & Tmp;
15
15
  type HeadingDetachedResolved = Omit<HeadingResolved, 'level' | 'linkBreadcrumb'> & {
16
16
  level: 2;
@@ -18,7 +18,6 @@ type HeadingDetachedResolved = Omit<HeadingResolved, 'level' | 'linkBreadcrumb'>
18
18
  };
19
19
  type HeadingDefinitionCommon = {
20
20
  title: string;
21
- topNavigation?: true | string;
22
21
  menuModalFullWidth?: true;
23
22
  };
24
23
  type HeadingDetachedDefinition = HeadingDefinitionCommon & {
@@ -30,7 +30,7 @@ function SearchLink(props: PropsAnchor) {
30
30
  function SearchIcon() {
31
31
  return (
32
32
  <svg
33
- style={{ marginRight: 'var(--icon-padding)', lineHeight: 0, width: '1.3em' }}
33
+ style={{ marginRight: 'var(--icon-text-padding)', lineHeight: 0, width: '1.3em' }}
34
34
  className="decolorize-7"
35
35
  viewBox="0 0 20 20"
36
36
  >
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brillout/docpress",
3
- "version": "0.8.4",
3
+ "version": "0.8.6",
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "@brillout/picocolors": "^1.0.10",
@@ -5,6 +5,7 @@ import type { PageContextResolved } from '../config/resolvePageContext'
5
5
  import { PageContextProvider, PageContextProvider2 } from './usePageContext'
6
6
  import React from 'react'
7
7
  import { DocSearchInstall } from '../docsearch/DocSearchInstall'
8
+ import { PassThrough } from '../utils/PassTrough'
8
9
 
9
10
  function getPageElement(pageContext: PageContext, pageContextResolved: PageContextResolved) {
10
11
  const { Page } = pageContext
@@ -33,7 +34,3 @@ function Wrapper({
33
34
  </React.StrictMode>
34
35
  )
35
36
  }
36
-
37
- function PassThrough({ children }: any) {
38
- return <>{children}</>
39
- }
@@ -34,6 +34,7 @@ Promise<Awaited<ReturnType<OnRenderHtmlAsync>>> => {
34
34
  <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" />
35
35
  ${getOpenGraphTags(pageContext.urlPathname, pageContextResolved.documentTitle, pageContextResolved.meta)}
36
36
  <style>${dangerouslySkipEscape(styleMenuModalLayout)}</style>
37
+ <meta name="docsearch:category" content="${pageContextResolved.activeCategory}" />
37
38
  </head>
38
39
  <body>
39
40
  <div id="page-view">${dangerouslySkipEscape(pageHtml)}</div>
package/types/Config.ts CHANGED
@@ -20,8 +20,6 @@ type Config = {
20
20
  }
21
21
  headings: HeadingDefinition[]
22
22
  headingsDetached: HeadingDetachedDefinition[]
23
- topNavigationStyle?: React.CSSProperties
24
-
25
23
  /** Sets `<meta name="description" content="${tagline}" />` */
26
24
  tagline: string
27
25
  websiteUrl: string
package/types/Heading.ts CHANGED
@@ -8,10 +8,10 @@ type HeadingResolved = {
8
8
  level: number
9
9
  title: string
10
10
  titleInNav: string
11
- topNavigation?: true | string
12
11
  linkBreadcrumb: string[]
13
12
  sectionTitles?: string[]
14
13
  menuModalFullWidth?: true
14
+ category?: string
15
15
  } & Tmp
16
16
 
17
17
  type HeadingDetachedResolved = Omit<HeadingResolved, 'level' | 'linkBreadcrumb'> & {
@@ -21,7 +21,6 @@ type HeadingDetachedResolved = Omit<HeadingResolved, 'level' | 'linkBreadcrumb'>
21
21
 
22
22
  type HeadingDefinitionCommon = {
23
23
  title: string
24
- topNavigation?: true | string
25
24
  menuModalFullWidth?: true
26
25
  }
27
26
 
@@ -0,0 +1,7 @@
1
+ export { PassThrough }
2
+
3
+ import React from 'react'
4
+
5
+ function PassThrough({ children }: any) {
6
+ return <>{children}</>
7
+ }