@brillout/docpress 0.6.20 → 0.6.21-commit-74553e7
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 +26 -7
- package/MobileHeader.tsx +5 -3
- package/PageLayout.css +11 -11
- package/PageLayout.tsx +27 -20
- package/algolia/DocSearch.css +6 -9
- package/autoScrollNav.ts +4 -3
- package/components/FeatureList/FeatureList.client.ts +6 -11
- package/components/Link.tsx +9 -9
- package/config/getConfig.ts +2 -1
- package/config/resolveHeadingsData.ts +22 -30
- package/config/resolvePageContext.ts +4 -6
- package/dist/+config.d.ts +25 -8
- package/dist/+config.js +7 -7
- package/dist/components/CodeBlockTransformer.d.ts +7 -0
- package/dist/components/CodeBlockTransformer.js +9 -0
- package/dist/components/Comment.d.ts +5 -0
- package/dist/components/Comment.js +6 -0
- package/dist/components/Consulting.d.ts +4 -0
- package/dist/components/Consulting.js +39 -0
- package/dist/components/Contributors.d.ts +7 -0
- package/dist/components/Contributors.js +74 -0
- package/dist/components/FileRemoved.d.ts +9 -0
- package/dist/components/FileRemoved.js +28 -0
- package/dist/components/HorizontalLine.d.ts +5 -0
- package/dist/components/HorizontalLine.js +15 -0
- package/dist/components/ImportMeta.d.ts +5 -0
- package/dist/components/ImportMeta.js +10 -0
- package/dist/components/Link.d.ts +16 -0
- package/dist/components/Link.js +108 -0
- package/dist/components/Note.d.ts +22 -0
- package/dist/components/Note.js +93 -0
- package/dist/components/P.d.ts +4 -0
- package/dist/components/P.js +17 -0
- package/dist/components/ReadingRecommendation.d.ts +6 -0
- package/dist/components/ReadingRecommendation.js +40 -0
- package/dist/components/RepoLink.d.ts +9 -0
- package/dist/components/RepoLink.js +22 -0
- package/dist/components/Sponsors.d.ts +22 -0
- package/dist/components/Sponsors.js +161 -0
- package/dist/components/Supporters.d.ts +32 -0
- package/dist/components/Supporters.js +80 -0
- package/dist/components/index.d.ts +15 -0
- package/dist/components/index.js +15 -0
- package/dist/config/getConfig.d.ts +3 -0
- package/dist/config/getConfig.js +14 -0
- package/dist/config/resolveHeadingsData.d.ts +16 -0
- package/dist/config/resolveHeadingsData.js +223 -0
- package/dist/config/resolvePageContext.d.ts +38 -0
- package/dist/config/resolvePageContext.js +23 -0
- package/dist/data/maintainersList.d.ts +9 -0
- package/dist/data/maintainersList.js +83 -0
- package/dist/data/sponsorsList.d.ts +3 -0
- package/dist/data/sponsorsList.js +151 -0
- package/dist/navigation/Navigation.d.ts +20 -0
- package/dist/navigation/Navigation.js +127 -0
- package/dist/navigation/NavigationHeader.d.ts +4 -0
- package/dist/navigation/NavigationHeader.js +85 -0
- package/dist/navigation/navigation-fullscreen/NavigationFullscreenButton.d.ts +6 -0
- package/dist/navigation/navigation-fullscreen/NavigationFullscreenButton.js +22 -0
- package/dist/parsePageSections.js +2 -2
- package/dist/parseTitle.d.ts +5 -0
- package/dist/parseTitle.js +52 -0
- package/dist/renderer/usePageContext.d.ts +17 -0
- package/dist/renderer/usePageContext.js +26 -0
- package/dist/types/Config.d.ts +30 -0
- package/dist/types/Config.js +1 -0
- package/dist/types/Heading.d.ts +45 -0
- package/dist/types/Heading.js +1 -0
- package/dist/utils/Emoji/Emoji.d.ts +8 -0
- package/dist/utils/Emoji/Emoji.js +191 -0
- package/dist/utils/Emoji/assets.d.ts +6 -0
- package/dist/utils/Emoji/assets.js +7 -0
- package/dist/utils/Emoji/index.d.ts +1 -0
- package/dist/utils/Emoji/index.js +1 -0
- package/dist/utils/client.d.ts +2 -0
- package/dist/utils/client.js +2 -0
- package/dist/utils/filter.d.ts +2 -0
- package/dist/utils/filter.js +11 -0
- package/dist/utils/isBrowser.d.ts +2 -0
- package/dist/utils/isBrowser.js +4 -0
- package/dist/utils/jsxToTextContent.d.ts +2 -0
- package/dist/utils/jsxToTextContent.js +12 -0
- package/dist/utils/objectAssign.d.ts +2 -0
- package/dist/utils/objectAssign.js +5 -0
- package/dist/utils/server.d.ts +7 -0
- package/dist/utils/server.js +7 -0
- package/dist/vite.config.js +7 -2
- package/installSectionUrlHashs.ts +7 -6
- package/navigation/Navigation-layout.css +2 -2
- package/navigation/Navigation.tsx +9 -6
- package/navigation/NavigationHeader.tsx +33 -4
- package/navigation/initPressKit.ts +2 -1
- package/package.json +17 -13
- package/renderer/getPageElement.tsx +16 -0
- package/renderer/onBeforeRender.ts +12 -0
- package/renderer/onRenderClient.tsx +53 -0
- package/renderer/onRenderHtml.tsx +7 -22
- package/renderer/usePageContext.tsx +20 -0
- package/tsconfig.json +1 -1
- package/types/Config.ts +6 -20
- package/types/Heading.ts +4 -4
- package/vite.config.ts +7 -2
- package/algolia/DocSearch.ts +0 -62
- package/navigation/Navigation.client.ts +0 -7
- package/renderer/client.ts +0 -4
package/+config.ts
CHANGED
|
@@ -1,17 +1,36 @@
|
|
|
1
1
|
import type { Config } from 'vike/types'
|
|
2
|
+
import type { Exports } from './config/resolvePageContext'
|
|
2
3
|
|
|
3
4
|
export default {
|
|
4
5
|
// @ts-ignore Remove this ts-ignore once Vike's new version is released.
|
|
5
6
|
name: '@brillout/docpress',
|
|
6
7
|
onRenderHtml: 'import:@brillout/docpress/renderer/onRenderHtml:onRenderHtml',
|
|
7
|
-
|
|
8
|
+
onRenderClient: 'import:@brillout/docpress/renderer/onRenderClient:onRenderClient',
|
|
9
|
+
onBeforeRender: 'import:@brillout/docpress/renderer/onBeforeRender:onBeforeRender',
|
|
10
|
+
clientRouting: true,
|
|
11
|
+
hydrationCanBeAborted: true,
|
|
12
|
+
passToClient: ['pageContextResolved'],
|
|
8
13
|
meta: {
|
|
9
|
-
|
|
10
|
-
env: { client:
|
|
11
|
-
},
|
|
12
|
-
// Vike already defines the setting 'name', but we redundantly define it here for older Vike versions (otherwise older Vike versions will complain that 'name` is an unknown config).
|
|
13
|
-
name: {
|
|
14
|
-
env: { config: true },
|
|
14
|
+
NavHeader: {
|
|
15
|
+
env: { client: true, server: true }
|
|
15
16
|
},
|
|
16
17
|
},
|
|
17
18
|
} satisfies Config
|
|
19
|
+
|
|
20
|
+
type ReactComponent = () => JSX.Element
|
|
21
|
+
declare global {
|
|
22
|
+
namespace Vike {
|
|
23
|
+
interface PageContext {
|
|
24
|
+
Page: ReactComponent
|
|
25
|
+
exports: Exports
|
|
26
|
+
}
|
|
27
|
+
interface Config {
|
|
28
|
+
NavHeader?: {
|
|
29
|
+
NavHeader: ReactComponent
|
|
30
|
+
navHeaderWrapperStyle?: React.CSSProperties
|
|
31
|
+
NavHeaderMobile: ReactComponent
|
|
32
|
+
navHeaderMobileWrapperStyle?: React.CSSProperties
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
package/MobileHeader.tsx
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import { usePageContext } from './renderer/usePageContext'
|
|
2
|
+
import { usePageContext, usePageContext2 } from './renderer/usePageContext'
|
|
3
3
|
|
|
4
4
|
export { MobileHeader }
|
|
5
5
|
|
|
6
6
|
function MobileHeader() {
|
|
7
7
|
const pageContext = usePageContext()
|
|
8
|
+
const pageContext2 = usePageContext2()
|
|
9
|
+
const { NavHeaderMobile } = pageContext2.config.NavHeader!
|
|
8
10
|
return (
|
|
9
11
|
<div
|
|
10
12
|
id="mobile-header"
|
|
@@ -37,10 +39,10 @@ function MobileHeader() {
|
|
|
37
39
|
alignItems: 'center',
|
|
38
40
|
justifyContent: 'left',
|
|
39
41
|
textDecoration: 'none',
|
|
40
|
-
...
|
|
42
|
+
...pageContext2.config.NavHeader?.navHeaderMobileWrapperStyle,
|
|
41
43
|
}}
|
|
42
44
|
>
|
|
43
|
-
|
|
45
|
+
<NavHeaderMobile />
|
|
44
46
|
</a>
|
|
45
47
|
</div>
|
|
46
48
|
</div>
|
package/PageLayout.css
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
.doc-page
|
|
1
|
+
.doc-page .page-container {
|
|
2
2
|
padding-bottom: 100px;
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
.page-layout {
|
|
6
6
|
display: flex;
|
|
7
7
|
justify-content: center;
|
|
8
8
|
width: 100%;
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
.page-layout > #navigation-wrapper,
|
|
11
|
+
.page-layout > .page-wrapper {
|
|
12
12
|
flex-grow: 1;
|
|
13
13
|
}
|
|
14
14
|
/* Avoid overflow, see https://stackoverflow.com/questions/36230944/prevent-flex-items-from-overflowing-a-container/66689926#66689926 */
|
|
15
|
-
|
|
15
|
+
.page-layout > .page-wrapper {
|
|
16
16
|
min-width: 0;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
.doc-page
|
|
19
|
+
.doc-page .page-wrapper {
|
|
20
20
|
--main-view-max-width: 800px;
|
|
21
21
|
}
|
|
22
|
-
.landing-page
|
|
22
|
+
.landing-page .page-wrapper {
|
|
23
23
|
--main-view-max-width: 1010px;
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
.page-wrapper {
|
|
26
26
|
max-width: calc(var(--main-view-max-width) + 80px);
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
.page-content {
|
|
29
29
|
box-sizing: content-box;
|
|
30
30
|
max-width: var(--main-view-max-width);
|
|
31
31
|
padding: 20px var(--main-view-padding);
|
|
32
32
|
margin: auto;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
.page-content {
|
|
36
36
|
--main-view-padding: 20px;
|
|
37
37
|
}
|
|
38
38
|
@media screen and (max-width: 1139px) {
|
|
39
|
-
|
|
39
|
+
.page-content {
|
|
40
40
|
--main-view-padding: 10px;
|
|
41
41
|
}
|
|
42
42
|
}
|
package/PageLayout.tsx
CHANGED
|
@@ -3,37 +3,44 @@ import { Navigation, NavigationMask } from './navigation/Navigation'
|
|
|
3
3
|
import type { PageContextResolved } from './config/resolvePageContext'
|
|
4
4
|
import { MobileHeader } from './MobileHeader'
|
|
5
5
|
import { EditPageNote } from './components/EditPageNote'
|
|
6
|
-
import { PageContextProvider } from './renderer/usePageContext'
|
|
6
|
+
import { PageContextProvider, PageContextProvider2 } from './renderer/usePageContext'
|
|
7
7
|
import './PageLayout.css'
|
|
8
8
|
import { NavigationFullscreenButton } from './navigation/navigation-fullscreen/NavigationFullscreenButton'
|
|
9
|
+
import type { PageContext } from 'vike/types'
|
|
9
10
|
|
|
10
11
|
export { PageLayout }
|
|
11
12
|
|
|
12
|
-
function PageLayout({
|
|
13
|
-
|
|
13
|
+
function PageLayout({
|
|
14
|
+
pageContext,
|
|
15
|
+
children,
|
|
16
|
+
pageContext2,
|
|
17
|
+
}: { pageContext: PageContextResolved; children: React.ReactNode; pageContext2: PageContext }) {
|
|
18
|
+
const { isLandingPage, pageTitle, navigationData } = pageContext
|
|
14
19
|
const { globalNote } = pageContext.config
|
|
15
20
|
return (
|
|
16
21
|
<React.StrictMode>
|
|
17
|
-
<
|
|
18
|
-
<
|
|
19
|
-
<div
|
|
20
|
-
<
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
<div
|
|
25
|
-
<
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
<PageContextProvider2 pageContext={pageContext2}>
|
|
23
|
+
<PageContextProvider pageContext={pageContext}>
|
|
24
|
+
<div className={`page-layout ${isLandingPage ? 'landing-page' : 'doc-page'}`}>
|
|
25
|
+
<div id="navigation-wrapper">
|
|
26
|
+
<Navigation {...pageContext.navigationData} />
|
|
27
|
+
</div>
|
|
28
|
+
<NavigationFullscreenButton />
|
|
29
|
+
<div className="page-wrapper">
|
|
30
|
+
<div className="page-container">
|
|
31
|
+
<MobileHeader />
|
|
32
|
+
<div className="page-content">
|
|
33
|
+
{globalNote}
|
|
34
|
+
{pageTitle && <h1 id={`${navigationData.currentUrl.replace('/', '')}`}>{pageTitle}</h1>}
|
|
35
|
+
{children}
|
|
36
|
+
{!isLandingPage && <EditPageNote pageContext={pageContext} />}
|
|
37
|
+
</div>
|
|
31
38
|
</div>
|
|
39
|
+
<NavigationMask />
|
|
32
40
|
</div>
|
|
33
|
-
<NavigationMask />
|
|
34
41
|
</div>
|
|
35
|
-
</
|
|
36
|
-
</
|
|
42
|
+
</PageContextProvider>
|
|
43
|
+
</PageContextProvider2>
|
|
37
44
|
</React.StrictMode>
|
|
38
45
|
)
|
|
39
46
|
}
|
package/algolia/DocSearch.css
CHANGED
|
@@ -8,14 +8,11 @@
|
|
|
8
8
|
padding-right: 6px !important;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
#docsearch-desktop .DocSearch-Button-Placeholder,
|
|
15
|
-
#docsearch-desktop .DocSearch-Button-Keys {
|
|
16
|
-
display: none;
|
|
11
|
+
.DocSearch-Button-Placeholder,
|
|
12
|
+
.DocSearch-Button-Keys {
|
|
13
|
+
display: none !important;
|
|
17
14
|
}
|
|
18
|
-
|
|
15
|
+
.DocSearch-Button {
|
|
19
16
|
background: transparent !important;
|
|
20
17
|
padding: 0 !important;
|
|
21
18
|
position: relative;
|
|
@@ -24,11 +21,11 @@
|
|
|
24
21
|
border: none !important;
|
|
25
22
|
box-shadow: none !important;
|
|
26
23
|
}
|
|
27
|
-
|
|
24
|
+
.DocSearch-Search-Icon {
|
|
28
25
|
height: 21px !important;
|
|
29
26
|
width: 21px !important;
|
|
30
27
|
}
|
|
31
|
-
|
|
28
|
+
.DocSearch-Button {
|
|
32
29
|
margin-right: 3px !important;
|
|
33
30
|
margin-left: 1px !important;
|
|
34
31
|
}
|
package/autoScrollNav.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
export { autoScrollNav }
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { assert } from './utils/client'
|
|
4
4
|
|
|
5
5
|
function autoScrollNav() {
|
|
6
6
|
const navigationEl = document.getElementById('navigation-content-main')
|
|
@@ -31,6 +31,7 @@ function autoScrollNav() {
|
|
|
31
31
|
block: 'center',
|
|
32
32
|
inline: 'start',
|
|
33
33
|
})
|
|
34
|
-
// Avoid scrollIntoView() from scrolling the main view.
|
|
34
|
+
// Avoid scrollIntoView() from scrolling the main view.
|
|
35
|
+
// - Alternatively scrollIntoViewIfNeeded() (https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoViewIfNeeded) would work (it doesn't scroll the main view) but Firefox doesn't support it.
|
|
35
36
|
document.documentElement.scrollTop = scrollTopOriginal
|
|
36
37
|
}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
export { addTwitterWidgets }
|
|
2
|
+
export { addFeatureClickHandlers }
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
addFeatureClickHandlers()
|
|
5
|
-
window.__docpress_hydrationFinished = true
|
|
4
|
+
import { assert } from '../../utils/client'
|
|
6
5
|
|
|
7
6
|
function addTwitterWidgets() {
|
|
8
7
|
loadScript('https://platform.twitter.com/widgets.js')
|
|
9
8
|
}
|
|
10
9
|
|
|
11
10
|
function addFeatureClickHandlers() {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
)
|
|
11
|
+
const featuresEl = document.getElementById('features')
|
|
12
|
+
if (!featuresEl) return
|
|
13
|
+
const featureEls: HTMLElement[] = Array.from(featuresEl.querySelectorAll('.feature.has-learn-more'))
|
|
15
14
|
featureEls.forEach((featureEl) => {
|
|
16
15
|
featureEl.onclick = () => {
|
|
17
16
|
expandLearnMore(featureEl)
|
|
@@ -59,7 +58,3 @@ function loadScript(scriptUrl: string): void {
|
|
|
59
58
|
function getComputedStyle(el: HTMLElement, styleProp: string) {
|
|
60
59
|
return window.document.defaultView!.getComputedStyle(el).getPropertyValue(styleProp)
|
|
61
60
|
}
|
|
62
|
-
|
|
63
|
-
declare global {
|
|
64
|
-
var __docpress_hydrationFinished: undefined | true
|
|
65
|
-
}
|
package/components/Link.tsx
CHANGED
|
@@ -48,25 +48,25 @@ function getLinkText({
|
|
|
48
48
|
noBreadcrumb: true | undefined
|
|
49
49
|
pageContext: PageContextResolved
|
|
50
50
|
doNotInferSectionTitle: true | undefined
|
|
51
|
-
}):
|
|
51
|
+
}): JSX.Element {
|
|
52
52
|
const { hrefPathname, hrefHash } = parseHref(href)
|
|
53
53
|
|
|
54
54
|
const linkData = findLinkData(hrefPathname || pageContext.urlPathname, pageContext)
|
|
55
55
|
const isLinkOnSamePage = linkData.url === pageContext.urlPathname
|
|
56
56
|
if (!hrefPathname) assert(isLinkOnSamePage)
|
|
57
57
|
|
|
58
|
-
const breadcrumbParts:
|
|
58
|
+
const breadcrumbParts: JSX.Element[] = []
|
|
59
59
|
if (linkData.linkBreadcrumb) {
|
|
60
|
-
breadcrumbParts.push(...(linkData.linkBreadcrumb ?? []).slice().reverse())
|
|
60
|
+
breadcrumbParts.push(...(linkData.linkBreadcrumb ?? []).slice().reverse().map(parseTitle))
|
|
61
61
|
}
|
|
62
|
-
breadcrumbParts.push(linkData.title)
|
|
62
|
+
breadcrumbParts.push(parseTitle(linkData.title))
|
|
63
63
|
|
|
64
64
|
if (hrefHash) {
|
|
65
|
-
let sectionTitle:
|
|
65
|
+
let sectionTitle: JSX.Element | undefined = undefined
|
|
66
66
|
assert(!hrefHash.startsWith('#'))
|
|
67
67
|
if (isLinkOnSamePage) {
|
|
68
68
|
const linkDataPageSection = findLinkData(`#${hrefHash}`, pageContext)
|
|
69
|
-
sectionTitle = linkDataPageSection.title
|
|
69
|
+
sectionTitle = parseTitle(linkDataPageSection.title)
|
|
70
70
|
} else if ('sectionTitles' in linkData && linkData.sectionTitles) {
|
|
71
71
|
linkData.sectionTitles.forEach((title) => {
|
|
72
72
|
if (determineSectionUrlHash(title) === hrefHash) {
|
|
@@ -79,7 +79,7 @@ function getLinkText({
|
|
|
79
79
|
!doNotInferSectionTitle,
|
|
80
80
|
`Page section title not found for <Link href="\`${href}\`" doNotInferSectionTitle={true} />.`,
|
|
81
81
|
)
|
|
82
|
-
sectionTitle = determineSectionTitle(href)
|
|
82
|
+
sectionTitle = <>{determineSectionTitle(href)}</>
|
|
83
83
|
}
|
|
84
84
|
breadcrumbParts.push(sectionTitle)
|
|
85
85
|
}
|
|
@@ -107,8 +107,8 @@ function getLinkText({
|
|
|
107
107
|
|
|
108
108
|
type LinkData = {
|
|
109
109
|
url?: null | string
|
|
110
|
-
title:
|
|
111
|
-
linkBreadcrumb: null |
|
|
110
|
+
title: string
|
|
111
|
+
linkBreadcrumb: null | string[]
|
|
112
112
|
sectionTitles?: string[]
|
|
113
113
|
}
|
|
114
114
|
|
package/config/getConfig.ts
CHANGED
|
@@ -12,7 +12,8 @@ function getConfig(): Config {
|
|
|
12
12
|
files.length === 1,
|
|
13
13
|
`Found multiple \`docpress.config.js\` files: ${files.map((f) => `\`${f}\``).join(', ')}. Define only one instead.`,
|
|
14
14
|
)
|
|
15
|
-
const
|
|
15
|
+
const exports: any = Object.values(globResult)[0]
|
|
16
|
+
const config: Config = exports.default || exports.config
|
|
16
17
|
assert(config)
|
|
17
18
|
return config
|
|
18
19
|
}
|
|
@@ -9,7 +9,6 @@ import type {
|
|
|
9
9
|
} from '../types/Heading'
|
|
10
10
|
import type { Config } from '../types/Config'
|
|
11
11
|
import { getConfig } from './getConfig'
|
|
12
|
-
import { parseTitle, withEmoji } from '../parseTitle'
|
|
13
12
|
import { NavigationData, NavItem } from '../navigation/Navigation'
|
|
14
13
|
import type { LinkData } from '../components'
|
|
15
14
|
import type { Exports, PageContextOriginal } from './resolvePageContext'
|
|
@@ -17,9 +16,9 @@ import pc from '@brillout/picocolors'
|
|
|
17
16
|
|
|
18
17
|
type PageSectionResolved = {
|
|
19
18
|
url: string | null
|
|
20
|
-
title:
|
|
21
|
-
titleInNav:
|
|
22
|
-
linkBreadcrumb:
|
|
19
|
+
title: string
|
|
20
|
+
titleInNav: string
|
|
21
|
+
linkBreadcrumb: string[]
|
|
23
22
|
pageSectionLevel: number
|
|
24
23
|
}
|
|
25
24
|
|
|
@@ -123,10 +122,10 @@ function pageSectionToLinkData(pageSection: PageSectionResolved): LinkData {
|
|
|
123
122
|
|
|
124
123
|
function getTitles(
|
|
125
124
|
activeHeading: HeadingResolved | HeadingDetachedResolved,
|
|
126
|
-
pageContext: {
|
|
125
|
+
pageContext: { urlPathname: string },
|
|
127
126
|
config: Config,
|
|
128
127
|
) {
|
|
129
|
-
const url = pageContext.
|
|
128
|
+
const url = pageContext.urlPathname
|
|
130
129
|
const isLandingPage = url === '/'
|
|
131
130
|
|
|
132
131
|
const { title } = activeHeading
|
|
@@ -147,25 +146,25 @@ function getTitles(
|
|
|
147
146
|
function getActiveHeading(
|
|
148
147
|
headingsResolved: HeadingResolved[],
|
|
149
148
|
headingsDetachedResolved: HeadingDetachedResolved[],
|
|
150
|
-
pageContext: {
|
|
149
|
+
pageContext: { urlPathname: string; exports: Exports },
|
|
151
150
|
) {
|
|
152
151
|
let activeHeading: HeadingResolved | HeadingDetachedResolved | null = null
|
|
153
|
-
const {
|
|
154
|
-
assert(
|
|
152
|
+
const { urlPathname } = pageContext
|
|
153
|
+
assert(urlPathname)
|
|
155
154
|
headingsResolved.forEach((heading) => {
|
|
156
|
-
if (heading.url ===
|
|
155
|
+
if (heading.url === urlPathname) {
|
|
157
156
|
activeHeading = heading
|
|
158
|
-
assert(heading.level === 2, { pageUrl:
|
|
157
|
+
assert(heading.level === 2, { pageUrl: urlPathname, heading })
|
|
159
158
|
}
|
|
160
159
|
})
|
|
161
160
|
const isDetachedPage = !activeHeading
|
|
162
161
|
if (!activeHeading) {
|
|
163
|
-
activeHeading = headingsDetachedResolved.find(({ url }) =>
|
|
162
|
+
activeHeading = headingsDetachedResolved.find(({ url }) => urlPathname === url) ?? null
|
|
164
163
|
}
|
|
165
164
|
if (!activeHeading) {
|
|
166
165
|
throw new Error(
|
|
167
166
|
[
|
|
168
|
-
`URL ${pc.bold(
|
|
167
|
+
`URL ${pc.bold(urlPathname)} not found in following URLs:`,
|
|
169
168
|
...headingsResolved
|
|
170
169
|
.map((h) => ` ${h.url}`)
|
|
171
170
|
.filter(Boolean)
|
|
@@ -177,19 +176,19 @@ function getActiveHeading(
|
|
|
177
176
|
}
|
|
178
177
|
|
|
179
178
|
function getPageSectionsResolved(
|
|
180
|
-
pageContext: { exports: Exports
|
|
179
|
+
pageContext: { exports: Exports },
|
|
181
180
|
activeHeading: HeadingResolved | HeadingDetachedResolved,
|
|
182
181
|
): PageSectionResolved[] {
|
|
183
182
|
const pageSections = pageContext.exports.pageSectionsExport ?? []
|
|
184
183
|
|
|
185
184
|
const pageSectionsResolved = pageSections.map((pageSection) => {
|
|
186
|
-
const
|
|
185
|
+
const { pageSectionTitle } = pageSection
|
|
187
186
|
const url: null | string = pageSection.pageSectionId === null ? null : '#' + pageSection.pageSectionId
|
|
188
187
|
const pageSectionResolved: PageSectionResolved = {
|
|
189
188
|
url,
|
|
190
|
-
title:
|
|
189
|
+
title: pageSectionTitle,
|
|
191
190
|
linkBreadcrumb: [activeHeading.title, ...(activeHeading.linkBreadcrumb ?? [])],
|
|
192
|
-
titleInNav:
|
|
191
|
+
titleInNav: pageSectionTitle,
|
|
193
192
|
pageSectionLevel: pageSection.pageSectionLevel,
|
|
194
193
|
}
|
|
195
194
|
return pageSectionResolved
|
|
@@ -205,10 +204,6 @@ function getPageSectionsResolved(
|
|
|
205
204
|
return pageSectionsResolved
|
|
206
205
|
}
|
|
207
206
|
|
|
208
|
-
/**
|
|
209
|
-
* - Parse title (from `string` to `JSX.Element`)
|
|
210
|
-
* - Determine navigation breadcrumbs
|
|
211
|
-
*/
|
|
212
207
|
function getHeadingsResolved(config: {
|
|
213
208
|
headings: HeadingDefinition[]
|
|
214
209
|
headingsDetached: HeadingDetachedDefinition[]
|
|
@@ -218,20 +213,19 @@ function getHeadingsResolved(config: {
|
|
|
218
213
|
} {
|
|
219
214
|
const headingsWithoutBreadcrumb: Omit<HeadingResolved, 'linkBreadcrumb'>[] = config.headings.map(
|
|
220
215
|
(heading: HeadingDefinition) => {
|
|
221
|
-
const titleParsed: JSX.Element = parseTitle(heading.title)
|
|
222
|
-
|
|
223
216
|
const titleInNav = heading.titleInNav || heading.title
|
|
217
|
+
/* TODO: remove this and all realted code
|
|
224
218
|
let titleInNavParsed: JSX.Element
|
|
225
219
|
titleInNavParsed = parseTitle(titleInNav)
|
|
226
220
|
if ('titleEmoji' in heading) {
|
|
227
221
|
assert(heading.titleEmoji)
|
|
228
222
|
titleInNavParsed = withEmoji(heading.titleEmoji, titleInNavParsed)
|
|
229
223
|
}
|
|
224
|
+
*/
|
|
230
225
|
|
|
231
226
|
const headingResolved: Omit<HeadingResolved, 'linkBreadcrumb'> = {
|
|
232
227
|
...heading,
|
|
233
|
-
|
|
234
|
-
titleInNav: titleInNavParsed,
|
|
228
|
+
titleInNav,
|
|
235
229
|
}
|
|
236
230
|
return headingResolved
|
|
237
231
|
},
|
|
@@ -247,17 +241,15 @@ function getHeadingsResolved(config: {
|
|
|
247
241
|
})
|
|
248
242
|
|
|
249
243
|
const headingsDetachedResolved = config.headingsDetached.map((headingsDetached) => {
|
|
250
|
-
const { url
|
|
244
|
+
const { url } = headingsDetached
|
|
251
245
|
assert(
|
|
252
246
|
headingsResolved.find((heading) => heading.url === url) === undefined,
|
|
253
247
|
`remove ${headingsDetached.url} from headingsDetached`,
|
|
254
248
|
)
|
|
255
|
-
const titleParsed = typeof title === 'string' ? parseTitle(title) : title
|
|
256
249
|
return {
|
|
257
250
|
...headingsDetached,
|
|
258
251
|
level: 2 as const,
|
|
259
|
-
|
|
260
|
-
titleInNav: titleParsed,
|
|
252
|
+
titleInNav: headingsDetached.title,
|
|
261
253
|
linkBreadcrumb: null,
|
|
262
254
|
}
|
|
263
255
|
})
|
|
@@ -266,7 +258,7 @@ function getHeadingsResolved(config: {
|
|
|
266
258
|
}
|
|
267
259
|
|
|
268
260
|
function getHeadingsBreadcrumb(heading: Omit<HeadingResolved, 'linkBreadcrumb'>, headings: HeadingResolved[]) {
|
|
269
|
-
const linkBreadcrumb:
|
|
261
|
+
const linkBreadcrumb: string[] = []
|
|
270
262
|
let levelCurrent = heading.level
|
|
271
263
|
headings
|
|
272
264
|
.slice()
|
|
@@ -9,14 +9,12 @@ import type { PageSection } from '../parsePageSections'
|
|
|
9
9
|
import { getConfig } from './getConfig'
|
|
10
10
|
import { resolveHeadingsData } from './resolveHeadingsData'
|
|
11
11
|
|
|
12
|
-
type ReactComponent = () => JSX.Element
|
|
13
12
|
type Exports = {
|
|
14
13
|
pageSectionsExport?: PageSection[]
|
|
15
14
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
15
|
+
// TODO/refactor: remove PageContextOriginal in favor of using PageContextServer
|
|
16
|
+
type PageContextOriginal = PageContextServer
|
|
17
|
+
|
|
20
18
|
type PageContextResolved = ReturnType<typeof resolvePageContext>
|
|
21
19
|
|
|
22
20
|
function resolvePageContext(pageContext: PageContextOriginal) {
|
|
@@ -27,7 +25,7 @@ function resolvePageContext(pageContext: PageContextOriginal) {
|
|
|
27
25
|
const config = getConfig()
|
|
28
26
|
const { faviconUrl, algolia, tagline, twitterHandle, bannerUrl, websiteUrl } = config
|
|
29
27
|
objectAssign(pageContextResolved, {
|
|
30
|
-
|
|
28
|
+
urlPathname: pageContext.urlPathname, // TODO: remove
|
|
31
29
|
meta: {
|
|
32
30
|
faviconUrl,
|
|
33
31
|
twitterHandle,
|
package/dist/+config.d.ts
CHANGED
|
@@ -1,19 +1,36 @@
|
|
|
1
|
+
import type { Exports } from './config/resolvePageContext';
|
|
1
2
|
declare const _default: {
|
|
2
3
|
name: string;
|
|
3
4
|
onRenderHtml: "import:@brillout/docpress/renderer/onRenderHtml:onRenderHtml";
|
|
4
|
-
|
|
5
|
+
onRenderClient: "import:@brillout/docpress/renderer/onRenderClient:onRenderClient";
|
|
6
|
+
onBeforeRender: "import:@brillout/docpress/renderer/onBeforeRender:onBeforeRender";
|
|
7
|
+
clientRouting: true;
|
|
8
|
+
hydrationCanBeAborted: true;
|
|
9
|
+
passToClient: string[];
|
|
5
10
|
meta: {
|
|
6
|
-
|
|
11
|
+
NavHeader: {
|
|
7
12
|
env: {
|
|
8
|
-
client:
|
|
13
|
+
client: true;
|
|
9
14
|
server: true;
|
|
10
15
|
};
|
|
11
16
|
};
|
|
12
|
-
name: {
|
|
13
|
-
env: {
|
|
14
|
-
config: true;
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
17
|
};
|
|
18
18
|
};
|
|
19
19
|
export default _default;
|
|
20
|
+
type ReactComponent = () => JSX.Element;
|
|
21
|
+
declare global {
|
|
22
|
+
namespace Vike {
|
|
23
|
+
interface PageContext {
|
|
24
|
+
Page: ReactComponent;
|
|
25
|
+
exports: Exports;
|
|
26
|
+
}
|
|
27
|
+
interface Config {
|
|
28
|
+
NavHeader?: {
|
|
29
|
+
NavHeader: ReactComponent;
|
|
30
|
+
navHeaderWrapperStyle?: React.CSSProperties;
|
|
31
|
+
NavHeaderMobile: ReactComponent;
|
|
32
|
+
navHeaderMobileWrapperStyle?: React.CSSProperties;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
package/dist/+config.js
CHANGED
|
@@ -2,14 +2,14 @@ export default {
|
|
|
2
2
|
// @ts-ignore Remove this ts-ignore once Vike's new version is released.
|
|
3
3
|
name: '@brillout/docpress',
|
|
4
4
|
onRenderHtml: 'import:@brillout/docpress/renderer/onRenderHtml:onRenderHtml',
|
|
5
|
-
|
|
5
|
+
onRenderClient: 'import:@brillout/docpress/renderer/onRenderClient:onRenderClient',
|
|
6
|
+
onBeforeRender: 'import:@brillout/docpress/renderer/onBeforeRender:onBeforeRender',
|
|
7
|
+
clientRouting: true,
|
|
8
|
+
hydrationCanBeAborted: true,
|
|
9
|
+
passToClient: ['pageContextResolved'],
|
|
6
10
|
meta: {
|
|
7
|
-
|
|
8
|
-
env: { client:
|
|
9
|
-
},
|
|
10
|
-
// Vike already defines the setting 'name', but we redundantly define it here for older Vike versions (otherwise older Vike versions will complain that 'name` is an unknown config).
|
|
11
|
-
name: {
|
|
12
|
-
env: { config: true },
|
|
11
|
+
NavHeader: {
|
|
12
|
+
env: { client: true, server: true }
|
|
13
13
|
},
|
|
14
14
|
},
|
|
15
15
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { CodeBlockTransformer };
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { assert } from '../utils/server';
|
|
4
|
+
function CodeBlockTransformer(_a) {
|
|
5
|
+
var children = _a.children, lineBreak = _a.lineBreak;
|
|
6
|
+
assert(lineBreak === 'white-space' || lineBreak === 'break-word', '`lineBreak` is currently the only use case for <CodeBlockTransformer>');
|
|
7
|
+
var className = "with-line-break_".concat(lineBreak);
|
|
8
|
+
return React.createElement("div", { className: className }, children);
|
|
9
|
+
}
|