@brillout/docpress 0.13.2 → 0.14.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.
Files changed (44) hide show
  1. package/+config.ts +11 -16
  2. package/EditLink.tsx +1 -1
  3. package/ExternalLinks.tsx +2 -2
  4. package/Layout.tsx +24 -21
  5. package/MenuModal.tsx +1 -1
  6. package/NavItemComponent.tsx +1 -1
  7. package/components/Link.tsx +4 -4
  8. package/components/RepoLink.tsx +1 -1
  9. package/{renderer/determineNavItemsColumnLayout.ts → determineNavItemsColumnLayout.ts} +2 -3
  10. package/dist/+config.d.ts +9 -20
  11. package/dist/+config.js +3 -11
  12. package/dist/NavItemComponent.js +1 -1
  13. package/dist/components/Link.js +1 -1
  14. package/dist/components/RepoLink.js +1 -1
  15. package/dist/{renderer/determineNavItemsColumnLayout.d.ts → determineNavItemsColumnLayout.d.ts} +1 -1
  16. package/dist/{renderer/determineNavItemsColumnLayout.js → determineNavItemsColumnLayout.js} +1 -2
  17. package/dist/parsePageSections.js +1 -1
  18. package/dist/renderer/usePageContext.d.ts +17 -10
  19. package/dist/renderer/usePageContext.js +11 -19
  20. package/dist/resolveConf.d.ts +19 -0
  21. package/dist/{config/resolveHeadingsData.js → resolveConf.js} +24 -29
  22. package/dist/types/Config.d.ts +1 -0
  23. package/dist/types/Heading.d.ts +9 -14
  24. package/docsearch/DocSearchInstall.tsx +1 -1
  25. package/index.ts +5 -1
  26. package/installSectionUrlHashs.ts +1 -0
  27. package/package.json +7 -9
  28. package/parsePageSections.ts +1 -1
  29. package/renderer/getPageElement.tsx +7 -15
  30. package/renderer/onCreatePageContext.ts +8 -0
  31. package/renderer/onRenderClient.tsx +2 -8
  32. package/renderer/onRenderHtml.tsx +53 -23
  33. package/renderer/usePageContext.tsx +12 -28
  34. package/{config/resolveHeadingsData.ts → resolveConf.ts} +30 -52
  35. package/tsconfig.config.json +1 -4
  36. package/tsconfig.json +1 -0
  37. package/types/Config.ts +1 -0
  38. package/types/Heading.ts +13 -20
  39. package/config/resolveConfig/resolveHeading.ts +0 -0
  40. package/config/resolvePageContext.ts +0 -49
  41. package/dist/config/resolveHeadingsData.d.ts +0 -24
  42. package/dist/config/resolvePageContext.d.ts +0 -41
  43. package/dist/config/resolvePageContext.js +0 -25
  44. package/renderer/onBeforeRender.ts +0 -12
@@ -28,6 +28,7 @@ type Config = {
28
28
  bannerUrl?: string;
29
29
  twitterHandle: string;
30
30
  globalNote?: React.ReactNode;
31
+ topNavigation?: React.ReactNode;
31
32
  i18n?: true;
32
33
  pressKit?: true;
33
34
  sponsorGithubAccount?: string;
@@ -15,7 +15,8 @@ type HeadingResolved = {
15
15
  color?: string;
16
16
  titleIcon?: string;
17
17
  titleIconStyle?: React.CSSProperties;
18
- } & Tmp;
18
+ titleDocument?: string;
19
+ };
19
20
  type PageDesign = {
20
21
  hideTitle?: true;
21
22
  hideMenuLeft?: true;
@@ -35,16 +36,7 @@ type HeadingDetachedDefinition = HeadingDefinitionCommon & {
35
36
  sectionTitles?: string[];
36
37
  category?: string;
37
38
  };
38
- type HeadingDefinition = HeadingDefinitionCommon & {
39
- url?: null | string;
40
- titleInNav?: string;
41
- } & HeadingDefinitionLevel & Tmp;
42
- type IsCategory = {
43
- url?: undefined;
44
- titleDocument?: undefined;
45
- titleInNav?: undefined;
46
- };
47
- type HeadingDefinitionLevel = ({
39
+ type HeadingDefinition = HeadingDefinitionCommon & {} & (({
48
40
  level: 1;
49
41
  color: string;
50
42
  titleIcon?: string;
@@ -53,9 +45,12 @@ type HeadingDefinitionLevel = ({
53
45
  level: 4;
54
46
  } & IsCategory) | {
55
47
  level: 2;
48
+ titleInNav?: string;
49
+ titleDocument?: string;
56
50
  sectionTitles?: string[];
57
51
  url: null | string;
58
- };
59
- type Tmp = {
60
- titleDocument?: string;
52
+ });
53
+ type IsCategory = {
54
+ url?: undefined;
55
+ titleInNav?: undefined;
61
56
  };
@@ -7,7 +7,7 @@ import { Hit } from '../components/Algolia/Hit'
7
7
 
8
8
  function DocSearchInstall() {
9
9
  const pageContext = usePageContext()
10
- const { algolia } = pageContext.meta
10
+ const { algolia } = pageContext.globalContext.config.docpress
11
11
  if (!algolia) return null
12
12
  return (
13
13
  <div style={{ display: 'none' }}>
package/index.ts CHANGED
@@ -8,7 +8,11 @@ export {
8
8
  Emoji,
9
9
  } from './components'
10
10
  export { MenuToggle } from './Layout'
11
- export { usePageContext, usePageContext2 } from './renderer/usePageContext'
11
+
12
+ // The only place usePageContext() is used at:
13
+ // https://github.com/vikejs/vike/blob/0b1b109f64aafbed23a1c2ac2630e6146a270ec0/packages/vike.dev/components/CommunityNote.tsx#L4
14
+ export { usePageContext } from './renderer/usePageContext'
15
+
12
16
  export * from './components/Note'
13
17
  export * from './icons/index'
14
18
  export { assert } from './utils/assert'
@@ -2,6 +2,7 @@ export { installSectionUrlHashs }
2
2
 
3
3
  import { assert } from './utils/client'
4
4
 
5
+ // TO-DO/eventually: use React instead of manually installing click handlers?
5
6
  function installSectionUrlHashs() {
6
7
  {
7
8
  const isLandingPage = window.location.pathname === '/'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brillout/docpress",
3
- "version": "0.13.2",
3
+ "version": "0.14.0",
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "@brillout/picocolors": "^1.0.10",
@@ -10,18 +10,18 @@
10
10
  "@mdx-js/react": "3.0.1",
11
11
  "@mdx-js/rollup": "3.0.1",
12
12
  "@shikijs/transformers": "1.2.0",
13
- "@vitejs/plugin-react-swc": ">=3.0.0",
13
+ "@vitejs/plugin-react-swc": "^3.10.2",
14
14
  "rehype-pretty-code": "0.13.0",
15
15
  "remark-gfm": "4.0.0",
16
16
  "shiki": "1.2.0",
17
- "vite": ">=5.2.0"
17
+ "vite": "^6.3.5"
18
18
  },
19
19
  "peerDependencies": {
20
20
  "@vitejs/plugin-react-swc": ">=3.0.0",
21
21
  "react": ">=18.0.0",
22
22
  "react-dom": ">=18.0.0",
23
23
  "typescript": ">=5.0.0",
24
- "vike": ">=0.4.222",
24
+ "vike": ">=0.4.234",
25
25
  "vite": ">=5.2.0"
26
26
  },
27
27
  "peerDependenciesMeta": {
@@ -35,8 +35,7 @@
35
35
  "exports": {
36
36
  "./renderer/onRenderHtml": "./renderer/onRenderHtml.tsx",
37
37
  "./renderer/onRenderClient": "./renderer/onRenderClient.tsx",
38
- "./renderer/onBeforeRender": "./renderer/onBeforeRender.ts",
39
- "./Layout": "./Layout.tsx",
38
+ "./renderer/onCreatePageContext": "./renderer/onCreatePageContext.ts",
40
39
  ".": "./index.ts",
41
40
  "./config": "./dist/+config.js",
42
41
  "./style": "./css/index.css",
@@ -73,9 +72,8 @@
73
72
  "// Build vite.config.ts and +config.ts (other files don't need to be built as @brillout/docpress is noExternal)": "",
74
73
  "build": "rm -rf dist/ && tsc --project tsconfig.config.json",
75
74
  "======== Develop": "",
76
- "dev": "tsc --watch --project tsconfig.config.json",
77
- "// Check types of all source files while developing": "",
78
- "typecheck": "tsc --noEmit --watch",
75
+ "// Typecheck + build vite.config.ts and +config.ts": "",
76
+ "dev": "tsc --watch",
79
77
  "========= Release": "",
80
78
  "release": "release-me patch",
81
79
  "release:minor": "release-me minor",
@@ -47,7 +47,7 @@ function transform(code: string) {
47
47
 
48
48
  if (
49
49
  line.startsWith('#')
50
- /* TODO/eventually: implement.
50
+ /* TO-DO/eventually: implement.
51
51
  || line.startsWith('<h2')
52
52
  */
53
53
  ) {
@@ -1,18 +1,16 @@
1
1
  export { getPageElement }
2
2
 
3
3
  import type { PageContext } from 'vike/types'
4
- import type { PageContextResolved } from '../config/resolvePageContext'
5
- import { PageContextProvider, PageContextProvider2 } from './usePageContext'
4
+ import { PageContextProvider } from './usePageContext'
6
5
  import React from 'react'
7
6
  import { DocSearchInstall } from '../docsearch/DocSearchInstall'
8
- import { PassThrough } from '../utils/PassTrough'
7
+ import { Layout } from '../Layout'
9
8
 
10
- function getPageElement(pageContext: PageContext, pageContextResolved: PageContextResolved) {
9
+ function getPageElement(pageContext: PageContext) {
11
10
  const { Page } = pageContext
12
- const Layout = pageContext.config.Layout || PassThrough
13
11
  const page = (
14
- <Wrapper {...{ pageContext, pageContextResolved }}>
15
- <Layout pageContext={pageContextResolved} pageContext2={pageContext}>
12
+ <Wrapper {...{ pageContext }}>
13
+ <Layout>
16
14
  <Page />
17
15
  </Layout>
18
16
  <DocSearchInstall />
@@ -21,16 +19,10 @@ function getPageElement(pageContext: PageContext, pageContextResolved: PageConte
21
19
  return page
22
20
  }
23
21
 
24
- function Wrapper({
25
- children,
26
- pageContext,
27
- pageContextResolved,
28
- }: { children: React.ReactNode; pageContext: PageContext; pageContextResolved: PageContextResolved }) {
22
+ function Wrapper({ children, pageContext }: { children: React.ReactNode; pageContext: PageContext }) {
29
23
  return (
30
24
  <React.StrictMode>
31
- <PageContextProvider2 pageContext={pageContext}>
32
- <PageContextProvider pageContext={pageContextResolved}>{children}</PageContextProvider>
33
- </PageContextProvider2>
25
+ <PageContextProvider pageContext={pageContext}>{children}</PageContextProvider>
34
26
  </React.StrictMode>
35
27
  )
36
28
  }
@@ -0,0 +1,8 @@
1
+ export { onCreatePageContext }
2
+
3
+ import type { PageContextServer } from 'vike/types'
4
+ import { resolveConf } from '../resolveConf'
5
+
6
+ function onCreatePageContext(pageContext: PageContextServer) {
7
+ pageContext.conf = resolveConf(pageContext)
8
+ }
@@ -3,7 +3,6 @@ export { onRenderClient }
3
3
  import React, { useEffect } from 'react'
4
4
  import type { PageContextClient } from 'vike/types'
5
5
  import ReactDOM from 'react-dom/client'
6
- import { PageContextResolved } from '../config/resolvePageContext'
7
6
  import { getPageElement } from './getPageElement'
8
7
  import { closeMenuModal } from '../MenuModal/toggleMenuModal'
9
8
  import '../css/index.css'
@@ -25,13 +24,11 @@ initOnNavigation()
25
24
  async function onRenderClient(pageContext: PageContextClient) {
26
25
  onRenderStart()
27
26
 
28
- // TODO: stop using any
29
- const pageContextResolved: PageContextResolved = (pageContext as any).pageContextResolved
30
27
  let renderPromiseResolve!: () => void
31
28
  const renderPromise = new Promise<void>((r) => {
32
29
  renderPromiseResolve = r
33
30
  })
34
- let page = getPageElement(pageContext, pageContextResolved)
31
+ let page = getPageElement(pageContext)
35
32
  page = <OnRenderDoneHook renderPromiseResolve={renderPromiseResolve}>{page}</OnRenderDoneHook>
36
33
  const container = document.getElementById('page-view')!
37
34
  if (pageContext.isHydration) {
@@ -49,9 +46,7 @@ async function onRenderClient(pageContext: PageContextClient) {
49
46
  }
50
47
 
51
48
  function applyHead(pageContext: PageContextClient) {
52
- // TODO: stop using any
53
- const pageContextResolved: PageContextResolved = (pageContext as any).pageContextResolved
54
- document.title = pageContextResolved.documentTitle
49
+ document.title = pageContext.conf.documentTitle
55
50
  }
56
51
 
57
52
  function onRenderStart() {
@@ -61,7 +56,6 @@ function onRenderStart() {
61
56
 
62
57
  function onRenderDone(renderPromiseResolve: () => void) {
63
58
  autoScrollNav()
64
- // TODO/refactor: use React?
65
59
  installSectionUrlHashs()
66
60
  setHydrationIsFinished()
67
61
  renderPromiseResolve()
@@ -3,37 +3,36 @@ export { onRenderHtml }
3
3
  import ReactDOMServer from 'react-dom/server'
4
4
  import { escapeInject, dangerouslySkipEscape } from 'vike/server'
5
5
  import { assert } from '../utils/server'
6
- import type { PageContextResolved } from '../config/resolvePageContext'
7
6
  import { getPageElement } from './getPageElement'
8
- import type { OnRenderHtmlAsync } from 'vike/types'
9
- import { ActiveCategory } from '../config/resolveHeadingsData'
7
+ import type { PageContextServer } from 'vike/types'
10
8
 
11
- const onRenderHtml: OnRenderHtmlAsync = async (
12
- pageContext,
13
- ): // TODO: Why is Promise<Awaited<>> needed?
14
- Promise<Awaited<ReturnType<OnRenderHtmlAsync>>> => {
15
- const pageContextResolved: PageContextResolved = (pageContext as any).pageContextResolved
9
+ async function onRenderHtml(pageContext: PageContextServer): Promise<any> {
10
+ const page = getPageElement(pageContext)
16
11
 
17
- const page = getPageElement(pageContext, pageContextResolved)
18
-
19
- const descriptionTag = pageContextResolved.isLandingPage
20
- ? dangerouslySkipEscape(`<meta name="description" content="${pageContextResolved.meta.tagline}" />`)
21
- : ''
12
+ const { isLandingPage } = pageContext.conf
13
+ assert(typeof isLandingPage === 'boolean')
14
+ const { tagline } = pageContext.globalContext.config.docpress
15
+ assert(tagline)
16
+ const descriptionTag = isLandingPage ? escapeInject`<meta name="description" content="${tagline}" />` : ''
22
17
 
23
18
  const pageHtml = ReactDOMServer.renderToString(page)
24
19
 
25
- const faviconUrl = pageContextResolved.config.faviconUrl ?? pageContextResolved.config.logoUrl
20
+ const faviconUrl =
21
+ pageContext.globalContext.config.docpress.faviconUrl ?? pageContext.globalContext.config.docpress.logoUrl
22
+ assert(faviconUrl)
26
23
 
24
+ const { documentTitle } = pageContext.conf
25
+ assert(documentTitle)
27
26
  return escapeInject`<!DOCTYPE html>
28
27
  <html>
29
28
  <head>
30
29
  <meta charset="UTF-8" />
31
30
  <link rel="icon" href="${faviconUrl ?? ''}" />
32
- <title>${pageContextResolved.documentTitle}</title>
31
+ <title>${documentTitle}</title>
33
32
  ${descriptionTag}
34
33
  <meta name="viewport" content="width=device-width,initial-scale=1">
35
- ${getOpenGraphTags(pageContext.urlPathname, pageContextResolved.documentTitle, pageContextResolved.meta)}
36
- ${getAlgoliaTags(pageContextResolved.activeCategory)}
34
+ ${getOpenGraphTags(pageContext.urlPathname, documentTitle, pageContext.globalContext.config.docpress)}
35
+ ${getAlgoliaTags(pageContext)}
37
36
  </head>
38
37
  <body>
39
38
  <div id="page-view">${dangerouslySkipEscape(pageHtml)}</div>
@@ -41,7 +40,8 @@ Promise<Awaited<ReturnType<OnRenderHtmlAsync>>> => {
41
40
  </html>`
42
41
  }
43
42
 
44
- function getAlgoliaTags(activeCategory: ActiveCategory) {
43
+ function getAlgoliaTags(pageContext: PageContextServer) {
44
+ const activeCategory = getActiveCategory(pageContext)
45
45
  const categoryNameTag = escapeInject`<meta name="algolia:category" content="${activeCategory.name}">`
46
46
  if (activeCategory.hide) {
47
47
  return escapeInject`${categoryNameTag}<meta name="algolia:category:hide"> `
@@ -49,6 +49,28 @@ function getAlgoliaTags(activeCategory: ActiveCategory) {
49
49
  return escapeInject`${categoryNameTag}<meta name="algolia:category:order" content="${activeCategory.order.toString()}"> `
50
50
  }
51
51
  }
52
+ type ActiveCategory = {
53
+ name: string
54
+ order: number
55
+ hide?: boolean
56
+ }
57
+ function getActiveCategory(pageContext: PageContextServer) {
58
+ const config = pageContext.globalContext.config.docpress
59
+ const { activeCategoryName } = pageContext.conf
60
+
61
+ const activeCategory: ActiveCategory = config.categories
62
+ // normalize
63
+ ?.map((c, i) => ({
64
+ order: i,
65
+ ...(typeof c === 'string' ? { name: c } : c),
66
+ }))
67
+ .find((c) => c.name === activeCategoryName) ?? {
68
+ name: activeCategoryName,
69
+ order: 99999999999,
70
+ }
71
+
72
+ return activeCategory
73
+ }
52
74
 
53
75
  function getOpenGraphTags(
54
76
  url: string,
@@ -56,18 +78,26 @@ function getOpenGraphTags(
56
78
  meta: { tagline: string; websiteUrl: string; twitterHandle: string; bannerUrl?: string },
57
79
  ) {
58
80
  const { tagline, websiteUrl, twitterHandle, bannerUrl } = meta
59
-
60
81
  assert(url.startsWith('/'))
61
- if (!bannerUrl) return ''
62
82
 
83
+ const metaBanner = !bannerUrl
84
+ ? ''
85
+ : escapeInject`
86
+ <meta property="og:image" content="${bannerUrl}">
87
+ <meta name="twitter:card" content="summary_large_image">
88
+ `
89
+ const metaTwitter = !twitterHandle
90
+ ? ''
91
+ : escapeInject`
92
+ <meta name="twitter:site" content="${twitterHandle}">
93
+ `
63
94
  // See view-source:https://vitejs.dev/
64
95
  return escapeInject`
65
96
  <meta property="og:type" content="website">
66
97
  <meta property="og:title" content="${documentTitle}">
67
- <meta property="og:image" content="${bannerUrl}">
68
98
  <meta property="og:url" content="${websiteUrl}">
69
99
  <meta property="og:description" content="${tagline}">
70
- <meta name="twitter:card" content="summary_large_image">
71
- <meta name="twitter:site" content="${twitterHandle}">
100
+ ${metaBanner}
101
+ ${metaTwitter}
72
102
  `
73
103
  }
@@ -1,48 +1,32 @@
1
- export { usePageContext }
2
1
  export { PageContextProvider }
2
+ export { usePageContext }
3
+ export { usePageContextLegacy }
3
4
 
4
5
  import React, { useContext } from 'react'
5
- import type { PageContextResolved } from '../config/resolvePageContext'
6
6
  import type { PageContext } from 'vike/types'
7
7
  import { getGlobalObject } from '../utils/getGlobalObject'
8
8
 
9
9
  const globalObject = getGlobalObject('usePageContext.ts', {
10
- Context: React.createContext<PageContextResolved>(undefined as any),
11
- Context2: React.createContext<PageContext>(undefined as any),
10
+ Ctx: React.createContext<PageContext>(undefined as any),
12
11
  })
13
12
 
14
- function PageContextProvider({
15
- pageContext,
16
- children,
17
- }: {
18
- pageContext: PageContextResolved
19
- children: React.ReactNode
20
- }) {
21
- const { Context } = globalObject
22
- return <Context.Provider value={pageContext}>{children}</Context.Provider>
23
- }
24
-
25
- function usePageContext(): PageContextResolved {
26
- const { Context } = globalObject
27
- const pageContext = useContext(Context)
28
- return pageContext
13
+ function usePageContextLegacy() {
14
+ const { Ctx } = globalObject
15
+ const pageContext = useContext(Ctx)
16
+ return pageContext.conf
29
17
  }
30
18
 
31
- export { PageContextProvider2 }
32
- // TODO/refactor: rename to usePageContext and remove old implementation
33
- export { usePageContext2 }
34
-
35
- function usePageContext2(): PageContext {
36
- const pageContext = useContext(globalObject.Context2)
19
+ function usePageContext(): PageContext {
20
+ const pageContext = useContext(globalObject.Ctx)
37
21
  return pageContext
38
22
  }
39
- function PageContextProvider2({
23
+ function PageContextProvider({
40
24
  pageContext,
41
25
  children,
42
26
  }: {
43
27
  pageContext: PageContext
44
28
  children: React.ReactNode
45
29
  }) {
46
- const { Context2 } = globalObject
47
- return <Context2.Provider value={pageContext}>{children}</Context2.Provider>
30
+ const { Ctx } = globalObject
31
+ return <Ctx.Provider value={pageContext}>{children}</Ctx.Provider>
48
32
  }
@@ -1,21 +1,22 @@
1
- export { resolveHeadingsData }
2
- export type { ActiveCategory }
1
+ export { resolveConf }
2
+ export type Conf = ReturnType<typeof resolveConf>
3
3
 
4
- import { assert, isBrowser, jsxToTextContent } from '../utils/server'
4
+ import type { Config } from './types/Config'
5
+ import type { NavItem } from './NavItemComponent'
6
+ import type { LinkData } from './components'
7
+ import type { PageContextServer } from 'vike/types'
8
+ import type { PageSection } from './parsePageSections'
5
9
  import type {
6
10
  HeadingDefinition,
7
11
  HeadingDetachedDefinition,
8
12
  HeadingResolved,
9
13
  HeadingDetachedResolved,
10
- } from '../types/Heading'
11
- import type { Config } from '../types/Config'
12
- import type { NavItem } from '../NavItemComponent'
13
- import type { LinkData } from '../components'
14
- import type { Exports, PageContextOriginal } from './resolvePageContext'
14
+ } from './types/Heading'
15
+ import { assert } from './utils/assert'
16
+ import { jsxToTextContent } from './utils/jsxToTextContent'
15
17
  import pc from '@brillout/picocolors'
16
- import { parseMarkdownMini } from '../parseMarkdownMini'
17
- import { determineNavItemsColumnLayout } from '../renderer/determineNavItemsColumnLayout'
18
- assert(!isBrowser())
18
+ import { parseMarkdownMini } from './parseMarkdownMini'
19
+ import { determineNavItemsColumnLayout } from './determineNavItemsColumnLayout'
19
20
 
20
21
  type PageSectionResolved = {
21
22
  url: string | null
@@ -25,14 +26,10 @@ type PageSectionResolved = {
25
26
  pageSectionLevel: number
26
27
  }
27
28
 
28
- type ActiveCategory = {
29
- name: string
30
- order: number
31
- hide?: boolean
32
- }
33
-
34
- function resolveHeadingsData(pageContext: PageContextOriginal) {
35
- const config = pageContext.config.docpress!
29
+ function resolveConf(pageContext: PageContextServer) {
30
+ const config = pageContext.globalContext.config.docpress
31
+ const { urlPathname } = pageContext
32
+ const pageSections = pageContext.config.pageSectionsExport ?? []
36
33
 
37
34
  {
38
35
  const { headings, headingsDetached } = config
@@ -46,18 +43,19 @@ function resolveHeadingsData(pageContext: PageContextOriginal) {
46
43
  const { activeHeading, isDetachedPage, activeCategoryName } = getActiveHeading(
47
44
  headingsResolved,
48
45
  headingsDetachedResolved,
49
- pageContext,
46
+ urlPathname,
50
47
  )
51
48
 
52
- const { documentTitle, isLandingPage, pageTitle } = getTitles(activeHeading, pageContext, config)
49
+ const { documentTitle, isLandingPage, pageTitle } = getTitles(activeHeading, urlPathname, config)
53
50
 
54
- const pageSectionsResolved = getPageSectionsResolved(pageContext, activeHeading)
51
+ const pageSectionsResolved = getPageSectionsResolved(pageSections, activeHeading)
55
52
 
56
- const linksAll: LinkData[] = [
57
- ...pageSectionsResolved.map(pageSectionToLinkData),
53
+ const linksGlobal: LinkData[] = [
58
54
  ...headingsResolved.map(headingToLinkData),
59
55
  ...headingsDetachedResolved.map(headingToLinkData),
60
56
  ]
57
+ const linksPage: LinkData[] = pageSectionsResolved.map(pageSectionToLinkData)
58
+ const linksAll = [...linksPage, ...linksGlobal]
61
59
 
62
60
  let navItemsAll: NavItem[]
63
61
  let navItemsDetached: NavItem[] | undefined
@@ -70,7 +68,7 @@ function resolveHeadingsData(pageContext: PageContextOriginal) {
70
68
  if (isDetachedPage) {
71
69
  navItemsDetached = [headingToNavItem(activeHeading), ...navItemsPageSections]
72
70
  } else {
73
- const activeHeadingIndex = navItemsAll.findIndex((navItem) => navItem.url === pageContext.urlPathname)
71
+ const activeHeadingIndex = navItemsAll.findIndex((navItem) => navItem.url === urlPathname)
74
72
  assert(activeHeadingIndex >= 0)
75
73
  navItemsPageSections.forEach((navItem, i) => {
76
74
  navItemsAll.splice(activeHeadingIndex + 1 + i, 0, navItem)
@@ -78,18 +76,7 @@ function resolveHeadingsData(pageContext: PageContextOriginal) {
78
76
  }
79
77
  }
80
78
 
81
- const activeCategory: ActiveCategory = config.categories
82
- // normalize
83
- ?.map((c, i) => ({
84
- order: i,
85
- ...(typeof c === 'string' ? { name: c } : c),
86
- }))
87
- .find((c) => c.name === activeCategoryName) ?? {
88
- name: activeCategoryName,
89
- order: 99999999999,
90
- }
91
-
92
- const pageContextAddendum = {
79
+ const conf = {
93
80
  navItemsAll,
94
81
  navItemsDetached,
95
82
  pageDesign: activeHeading.pageDesign,
@@ -97,10 +84,9 @@ function resolveHeadingsData(pageContext: PageContextOriginal) {
97
84
  isLandingPage,
98
85
  pageTitle,
99
86
  documentTitle,
100
- // TODO: don't pass to client-side
101
- activeCategory,
87
+ activeCategoryName,
102
88
  }
103
- return pageContextAddendum
89
+ return conf
104
90
  }
105
91
 
106
92
  function headingToNavItem(heading: HeadingResolved | HeadingDetachedResolved): NavItem {
@@ -139,13 +125,8 @@ function pageSectionToLinkData(pageSection: PageSectionResolved): LinkData {
139
125
  }
140
126
  }
141
127
 
142
- function getTitles(
143
- activeHeading: HeadingResolved | HeadingDetachedResolved,
144
- pageContext: { urlPathname: string },
145
- config: Config,
146
- ) {
147
- const url = pageContext.urlPathname
148
- const isLandingPage = url === '/'
128
+ function getTitles(activeHeading: HeadingResolved | HeadingDetachedResolved, urlPathname: string, config: Config) {
129
+ const isLandingPage = urlPathname === '/'
149
130
 
150
131
  const { title } = activeHeading
151
132
  let pageTitle = isLandingPage ? null : title
@@ -165,12 +146,11 @@ function getTitles(
165
146
  function getActiveHeading(
166
147
  headingsResolved: HeadingResolved[],
167
148
  headingsDetachedResolved: HeadingDetachedResolved[],
168
- pageContext: { urlPathname: string; exports: Exports },
149
+ urlPathname: string,
169
150
  ) {
170
151
  let activeHeading: HeadingResolved | HeadingDetachedResolved | null = null
171
152
  let activeCategoryName = 'Miscellaneous'
172
153
  let headingCategory: string | undefined
173
- const { urlPathname } = pageContext
174
154
  assert(urlPathname)
175
155
  for (const heading of headingsResolved) {
176
156
  if (heading.level === 1) {
@@ -206,11 +186,9 @@ function getActiveHeading(
206
186
  }
207
187
 
208
188
  function getPageSectionsResolved(
209
- pageContext: { exports: Exports },
189
+ pageSections: PageSection[],
210
190
  activeHeading: HeadingResolved | HeadingDetachedResolved,
211
191
  ): PageSectionResolved[] {
212
- const pageSections = pageContext.exports.pageSectionsExport ?? []
213
-
214
192
  const pageSectionsResolved = pageSections.map((pageSection) => {
215
193
  const { pageSectionTitle } = pageSection
216
194
  const url: null | string = pageSection.pageSectionId === null ? null : '#' + pageSection.pageSectionId
@@ -1,7 +1,4 @@
1
1
  {
2
2
  "extends": "./tsconfig.json",
3
- "files": ["vite.config.ts", "+config.ts"],
4
- "compilerOptions": {
5
- "outDir": "./dist/"
6
- }
3
+ "files": ["vite.config.ts", "+config.ts"]
7
4
  }
package/tsconfig.json CHANGED
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "compilerOptions": {
3
+ "outDir": "./dist/",
3
4
  "jsx": "react",
4
5
  "module": "ES2020",
5
6
  "moduleResolution": "Bundler",
package/types/Config.ts CHANGED
@@ -30,6 +30,7 @@ type Config = {
30
30
  bannerUrl?: string
31
31
  twitterHandle: string
32
32
  globalNote?: React.ReactNode
33
+ topNavigation?: React.ReactNode
33
34
  i18n?: true
34
35
  pressKit?: true
35
36
  sponsorGithubAccount?: string
package/types/Heading.ts CHANGED
@@ -16,7 +16,8 @@ type HeadingResolved = {
16
16
  color?: string
17
17
  titleIcon?: string
18
18
  titleIconStyle?: React.CSSProperties
19
- } & Tmp
19
+ titleDocument?: string
20
+ }
20
21
 
21
22
  type PageDesign = {
22
23
  hideTitle?: true
@@ -41,26 +42,18 @@ type HeadingDetachedDefinition = HeadingDefinitionCommon & {
41
42
  category?: string
42
43
  }
43
44
 
44
- type HeadingDefinition = HeadingDefinitionCommon & {
45
- url?: null | string
46
- titleInNav?: string
47
- } & HeadingDefinitionLevel &
48
- Tmp
45
+ type HeadingDefinition = HeadingDefinitionCommon & {} & (
46
+ | ({ level: 1; color: string; titleIcon?: string; titleIconStyle?: React.CSSProperties } & IsCategory)
47
+ | ({ level: 4 } & IsCategory)
48
+ | {
49
+ level: 2
50
+ titleInNav?: string
51
+ titleDocument?: string
52
+ sectionTitles?: string[]
53
+ url: null | string
54
+ }
55
+ )
49
56
  type IsCategory = {
50
57
  url?: undefined
51
- titleDocument?: undefined
52
58
  titleInNav?: undefined
53
59
  }
54
- type HeadingDefinitionLevel =
55
- | ({ level: 1; color: string; titleIcon?: string; titleIconStyle?: React.CSSProperties } & IsCategory)
56
- | ({ level: 4 } & IsCategory)
57
- | {
58
- level: 2
59
- sectionTitles?: string[]
60
- url: null | string
61
- }
62
-
63
- type Tmp = {
64
- // TODO: remove? Both Vike and Telefunc set it to the same value than docpress.config.js#projectInfo.projectName
65
- titleDocument?: string
66
- }
File without changes