@brillout/docpress 0.13.2 → 0.15.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 +8 -16
  4. package/Layout.tsx +26 -26
  5. package/MenuModal.tsx +1 -1
  6. package/NavItemComponent.tsx +1 -1
  7. package/components/Link.tsx +4 -4
  8. package/components/RepoLink.tsx +2 -3
  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 +2 -3
  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} +25 -30
  22. package/dist/types/Config.d.ts +19 -24
  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 +56 -29
  33. package/renderer/usePageContext.tsx +12 -28
  34. package/{config/resolveHeadingsData.ts → resolveConf.ts} +31 -53
  35. package/tsconfig.config.json +1 -4
  36. package/tsconfig.json +1 -0
  37. package/types/Config.ts +24 -24
  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
@@ -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,20 +125,15 @@ 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
152
133
  let documentTitle = activeHeading.titleDocument || jsxToTextContent(parseMarkdownMini(title))
153
134
 
154
135
  if (!isLandingPage) {
155
- documentTitle += ' | ' + config.projectInfo.projectName
136
+ documentTitle += ' | ' + config.name
156
137
  }
157
138
 
158
139
  if (isLandingPage) {
@@ -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
@@ -3,36 +3,36 @@ export type { Config }
3
3
  import type { HeadingDefinition, HeadingDetachedDefinition } from './Heading'
4
4
 
5
5
  type Config = {
6
- projectInfo: {
7
- githubRepository: string
8
- githubIssues: string
9
- githubDiscussions?: string
10
- projectName: string
11
- projectVersion: string
12
- discordInvite?: string
13
- twitterProfile: string
14
- blueskyHandle?: string
15
- }
16
- docsDir?: string
17
- logoUrl?: string
18
- faviconUrl?: string
19
- algolia: null | {
6
+ name: string
7
+ version: string
8
+ url: string
9
+ /** Sets `<meta name="description" content="${tagline}" />` */
10
+ tagline: string
11
+ logo: string
12
+ favicon?: string
13
+ banner?: string
14
+
15
+ github: string
16
+ discord?: string
17
+ twitter?: string
18
+ bluesky?: string
19
+
20
+ headings: HeadingDefinition[]
21
+ headingsDetached: HeadingDetachedDefinition[]
22
+ categories?: Category[]
23
+
24
+ algolia?: {
20
25
  appId: string
21
26
  apiKey: string
22
27
  indexName: string
23
28
  }
24
- headings: HeadingDefinition[]
25
- headingsDetached: HeadingDetachedDefinition[]
26
- categories?: Category[]
27
- /** Sets `<meta name="description" content="${tagline}" />` */
28
- tagline: string
29
- websiteUrl: string
30
- bannerUrl?: string
31
- twitterHandle: string
32
- globalNote?: React.ReactNode
29
+
33
30
  i18n?: true
34
31
  pressKit?: true
35
- sponsorGithubAccount?: string
32
+ docsDir?: string
33
+
34
+ globalNote?: React.ReactNode
35
+ topNavigation?: React.ReactNode
36
36
  navMaxWidth?: number
37
37
  navLogoSize?: number
38
38
  navLogoStyle?: React.CSSProperties
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
- }