@brillout/docpress 0.13.1 → 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 (45) hide show
  1. package/+config.ts +11 -16
  2. package/EditLink.tsx +2 -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 +4 -4
  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.d.ts +2 -3
  15. package/dist/components/RepoLink.js +4 -3
  16. package/dist/{renderer/determineNavItemsColumnLayout.d.ts → determineNavItemsColumnLayout.d.ts} +1 -1
  17. package/dist/{renderer/determineNavItemsColumnLayout.js → determineNavItemsColumnLayout.js} +1 -2
  18. package/dist/parsePageSections.js +1 -1
  19. package/dist/renderer/usePageContext.d.ts +17 -10
  20. package/dist/renderer/usePageContext.js +11 -19
  21. package/dist/resolveConf.d.ts +19 -0
  22. package/dist/{config/resolveHeadingsData.js → resolveConf.js} +24 -29
  23. package/dist/types/Config.d.ts +2 -0
  24. package/dist/types/Heading.d.ts +9 -14
  25. package/docsearch/DocSearchInstall.tsx +1 -1
  26. package/index.ts +5 -1
  27. package/installSectionUrlHashs.ts +1 -0
  28. package/package.json +7 -9
  29. package/parsePageSections.ts +1 -1
  30. package/renderer/getPageElement.tsx +7 -15
  31. package/renderer/onCreatePageContext.ts +8 -0
  32. package/renderer/onRenderClient.tsx +2 -8
  33. package/renderer/onRenderHtml.tsx +53 -23
  34. package/renderer/usePageContext.tsx +12 -28
  35. package/{config/resolveHeadingsData.ts → resolveConf.ts} +30 -52
  36. package/tsconfig.config.json +1 -4
  37. package/tsconfig.json +1 -0
  38. package/types/Config.ts +2 -0
  39. package/types/Heading.ts +13 -20
  40. package/config/resolveConfig/resolveHeading.ts +0 -0
  41. package/config/resolvePageContext.ts +0 -49
  42. package/dist/config/resolveHeadingsData.d.ts +0 -24
  43. package/dist/config/resolvePageContext.d.ts +0 -41
  44. package/dist/config/resolvePageContext.js +0 -25
  45. package/renderer/onBeforeRender.ts +0 -12
@@ -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
@@ -13,6 +13,7 @@ type Config = {
13
13
  twitterProfile: string
14
14
  blueskyHandle?: string
15
15
  }
16
+ docsDir?: string
16
17
  logoUrl?: string
17
18
  faviconUrl?: string
18
19
  algolia: null | {
@@ -29,6 +30,7 @@ type Config = {
29
30
  bannerUrl?: string
30
31
  twitterHandle: string
31
32
  globalNote?: React.ReactNode
33
+ topNavigation?: React.ReactNode
32
34
  i18n?: true
33
35
  pressKit?: true
34
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
@@ -1,49 +0,0 @@
1
- export { resolvePageContext }
2
- export type { PageContextOriginal }
3
- export type { PageContextResolved }
4
- export type { Exports }
5
-
6
- import { objectAssign } from '../utils/server'
7
- import type { PageContextServer } from 'vike/types'
8
- import type { PageSection } from '../parsePageSections'
9
- import { resolveHeadingsData } from './resolveHeadingsData'
10
-
11
- type Exports = {
12
- pageSectionsExport?: PageSection[]
13
- }
14
- // TODO/refactor: remove PageContextOriginal in favor of using PageContextServer
15
- type PageContextOriginal = PageContextServer
16
-
17
- type PageContextResolved = ReturnType<typeof resolvePageContext>
18
-
19
- function resolvePageContext(pageContext: PageContextOriginal) {
20
- const pageContextResolved = {}
21
-
22
- objectAssign(pageContextResolved, resolveHeadingsData(pageContext))
23
-
24
- const config = pageContext.config.docpress!
25
- const {
26
- algolia,
27
- tagline,
28
- twitterHandle,
29
- bannerUrl,
30
- websiteUrl,
31
- projectInfo: { projectName },
32
- } = config
33
- const logoUrl = config.logoUrl ?? config.faviconUrl
34
- objectAssign(pageContextResolved, {
35
- urlPathname: pageContext.urlPathname, // TODO: remove
36
- meta: {
37
- projectName,
38
- logoUrl,
39
- twitterHandle,
40
- bannerUrl,
41
- websiteUrl,
42
- tagline,
43
- algolia,
44
- },
45
- config,
46
- })
47
-
48
- return pageContextResolved
49
- }
@@ -1,24 +0,0 @@
1
- export { resolveHeadingsData };
2
- export type { ActiveCategory };
3
- import type { NavItem } from '../NavItemComponent';
4
- import type { LinkData } from '../components';
5
- import type { PageContextOriginal } from './resolvePageContext';
6
- type ActiveCategory = {
7
- name: string;
8
- order: number;
9
- hide?: boolean;
10
- };
11
- declare function resolveHeadingsData(pageContext: PageContextOriginal): {
12
- navItemsAll: NavItem[];
13
- navItemsDetached: NavItem[] | undefined;
14
- pageDesign: {
15
- hideTitle?: true;
16
- hideMenuLeft?: true;
17
- contentMaxWidth?: number;
18
- } | undefined;
19
- linksAll: LinkData[];
20
- isLandingPage: boolean;
21
- pageTitle: string | null;
22
- documentTitle: string;
23
- activeCategory: ActiveCategory;
24
- };
@@ -1,41 +0,0 @@
1
- export { resolvePageContext };
2
- export type { PageContextOriginal };
3
- export type { PageContextResolved };
4
- export type { Exports };
5
- import type { PageContextServer } from 'vike/types';
6
- import type { PageSection } from '../parsePageSections';
7
- type Exports = {
8
- pageSectionsExport?: PageSection[];
9
- };
10
- type PageContextOriginal = PageContextServer;
11
- type PageContextResolved = ReturnType<typeof resolvePageContext>;
12
- declare function resolvePageContext(pageContext: PageContextOriginal): {
13
- navItemsAll: import("../NavItemComponent").NavItem[];
14
- navItemsDetached: import("../NavItemComponent").NavItem[] | undefined;
15
- pageDesign: {
16
- hideTitle?: true;
17
- hideMenuLeft?: true;
18
- contentMaxWidth?: number;
19
- } | undefined;
20
- linksAll: import("../components").LinkData[];
21
- isLandingPage: boolean;
22
- pageTitle: string | null;
23
- documentTitle: string;
24
- activeCategory: import("./resolveHeadingsData").ActiveCategory;
25
- } & {
26
- urlPathname: string;
27
- meta: {
28
- projectName: string;
29
- logoUrl: string | undefined;
30
- twitterHandle: string;
31
- bannerUrl: string | undefined;
32
- websiteUrl: string;
33
- tagline: string;
34
- algolia: {
35
- appId: string;
36
- apiKey: string;
37
- indexName: string;
38
- } | null;
39
- };
40
- config: import("../types/Config").Config;
41
- };
@@ -1,25 +0,0 @@
1
- export { resolvePageContext };
2
- import { objectAssign } from '../utils/server';
3
- import { resolveHeadingsData } from './resolveHeadingsData';
4
- function resolvePageContext(pageContext) {
5
- var _a;
6
- var pageContextResolved = {};
7
- objectAssign(pageContextResolved, resolveHeadingsData(pageContext));
8
- var config = pageContext.config.docpress;
9
- var algolia = config.algolia, tagline = config.tagline, twitterHandle = config.twitterHandle, bannerUrl = config.bannerUrl, websiteUrl = config.websiteUrl, projectName = config.projectInfo.projectName;
10
- var logoUrl = (_a = config.logoUrl) !== null && _a !== void 0 ? _a : config.faviconUrl;
11
- objectAssign(pageContextResolved, {
12
- urlPathname: pageContext.urlPathname, // TODO: remove
13
- meta: {
14
- projectName: projectName,
15
- logoUrl: logoUrl,
16
- twitterHandle: twitterHandle,
17
- bannerUrl: bannerUrl,
18
- websiteUrl: websiteUrl,
19
- tagline: tagline,
20
- algolia: algolia,
21
- },
22
- config: config,
23
- });
24
- return pageContextResolved;
25
- }
@@ -1,12 +0,0 @@
1
- export { onBeforeRender }
2
-
3
- import { resolvePageContext, type PageContextOriginal } from '../config/resolvePageContext'
4
-
5
- function onBeforeRender(pageContextOriginal: PageContextOriginal) {
6
- const pageContextResolved = resolvePageContext(pageContextOriginal)
7
- return {
8
- pageContext: {
9
- pageContextResolved,
10
- },
11
- }
12
- }