@brillout/docpress 0.6.21 → 0.7.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.
- package/+config.ts +26 -3
- package/MobileHeader.tsx +5 -3
- package/PageLayout.tsx +28 -19
- 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 +20 -37
- package/config/resolvePageContext.ts +4 -6
- package/dist/+config.d.ts +25 -3
- package/dist/+config.js +7 -3
- 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 +215 -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 +134 -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 +7 -3
- 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 +43 -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 +5 -3
- package/installSectionUrlHashs.ts +7 -13
- package/navigation/Navigation.tsx +28 -19
- package/navigation/NavigationHeader.tsx +33 -4
- package/navigation/initMobileNavigation.ts +2 -11
- package/navigation/initPressKit.ts +5 -2
- package/navigation/navigation-fullscreen/initNavigationFullscreen.ts +12 -5
- package/package.json +21 -15
- package/parsePageSections.ts +6 -1
- package/renderer/getPageElement.tsx +16 -0
- package/renderer/onBeforeRender.ts +12 -0
- package/renderer/onRenderClient.tsx +79 -0
- package/renderer/onRenderHtml.tsx +7 -22
- package/renderer/usePageContext.tsx +20 -0
- package/tsconfig.config.json +1 -1
- package/tsconfig.json +1 -1
- package/types/Config.ts +6 -20
- package/types/Heading.ts +5 -5
- package/vite.config.ts +5 -3
- package/algolia/DocSearch.ts +0 -62
- package/navigation/Navigation.client.ts +0 -7
- package/renderer/client.ts +0 -4
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
export { initNavigationFullscreen }
|
|
2
|
+
export { hideNavigationFullScreen }
|
|
2
3
|
|
|
3
4
|
import { assert } from '../../utils/client'
|
|
4
|
-
|
|
5
5
|
let scrollPositionBeforeToggle: number = 0
|
|
6
|
+
initOnce()
|
|
6
7
|
|
|
7
|
-
function
|
|
8
|
-
updateColumnWidth()
|
|
8
|
+
function initOnce() {
|
|
9
9
|
window.addEventListener('resize', updateColumnWidth, { passive: true })
|
|
10
|
-
document.getElementById('navigation-fullscreen-button')!.onclick = toggleNavExpend
|
|
11
|
-
document.getElementById('navigation-fullscreen-close')!.onclick = toggleNavExpend
|
|
12
10
|
document.addEventListener(
|
|
13
11
|
// We don't use keydown to not interfere with user pressing `<Esc>` for closing the browser's `<Ctrl-F>` search diablog, see https://stackoverflow.com/questions/66595035/how-to-detect-escape-key-if-search-bar-of-browser-is-open
|
|
14
12
|
'keydown',
|
|
@@ -19,6 +17,11 @@ function initNavigationFullscreen() {
|
|
|
19
17
|
false,
|
|
20
18
|
)
|
|
21
19
|
}
|
|
20
|
+
function initNavigationFullscreen() {
|
|
21
|
+
document.getElementById('navigation-fullscreen-button')!.onclick = toggleNavExpend
|
|
22
|
+
document.getElementById('navigation-fullscreen-close')!.onclick = toggleNavExpend
|
|
23
|
+
updateColumnWidth()
|
|
24
|
+
}
|
|
22
25
|
|
|
23
26
|
function toggleNavExpend() {
|
|
24
27
|
const navContainer = document.getElementById('navigation-container')!
|
|
@@ -29,6 +32,10 @@ function toggleNavExpend() {
|
|
|
29
32
|
}
|
|
30
33
|
scrollPositionBeforeToggle = scrollPos
|
|
31
34
|
}
|
|
35
|
+
function hideNavigationFullScreen() {
|
|
36
|
+
if (!document.documentElement.classList.contains('navigation-fullscreen')) return
|
|
37
|
+
toggleNavExpend()
|
|
38
|
+
}
|
|
32
39
|
|
|
33
40
|
function updateColumnWidth() {
|
|
34
41
|
const navMinWidth = 299
|
package/package.json
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brillout/docpress",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"
|
|
6
|
+
"======== Build": "",
|
|
7
|
+
"// Build vite.config.ts and +config.ts (other files don't need to be built as @brillout/docpress is noExternal)": "",
|
|
7
8
|
"build": "rm -rf dist/ && tsc --project tsconfig.config.json",
|
|
8
|
-
"
|
|
9
|
+
"======== Develop": "",
|
|
9
10
|
"dev": "tsc --watch --project tsconfig.config.json",
|
|
10
|
-
"// Check types while developing": "",
|
|
11
|
-
"
|
|
12
|
-
"
|
|
11
|
+
"// Check types of all source files while developing": "",
|
|
12
|
+
"typecheck": "tsc --noEmit --watch",
|
|
13
|
+
"========= Release": "",
|
|
13
14
|
"release": "release-me patch",
|
|
14
|
-
"release:
|
|
15
|
-
"release:
|
|
15
|
+
"release:minor": "release-me minor",
|
|
16
|
+
"release:commit": "release-me commit"
|
|
16
17
|
},
|
|
17
18
|
"dependencies": {
|
|
18
19
|
"@brillout/picocolors": "^1.0.10",
|
|
20
|
+
"@docsearch/css": "^3.6.1",
|
|
21
|
+
"@docsearch/react": "3.6.1",
|
|
19
22
|
"@mdx-js/mdx": "3.0.1",
|
|
20
23
|
"@mdx-js/react": "3.0.1",
|
|
21
24
|
"@mdx-js/rollup": "3.0.1",
|
|
@@ -39,7 +42,8 @@
|
|
|
39
42
|
},
|
|
40
43
|
"exports": {
|
|
41
44
|
"./renderer/onRenderHtml": "./renderer/onRenderHtml.tsx",
|
|
42
|
-
"./renderer/
|
|
45
|
+
"./renderer/onRenderClient": "./renderer/onRenderClient.tsx",
|
|
46
|
+
"./renderer/onBeforeRender": "./renderer/onBeforeRender.ts",
|
|
43
47
|
".": "./index.ts",
|
|
44
48
|
"./FeatureList/FeatureList": "./components/FeatureList/FeatureList.tsx",
|
|
45
49
|
"./FeatureList/FeatureList.client": {
|
|
@@ -70,12 +74,14 @@
|
|
|
70
74
|
},
|
|
71
75
|
"devDependencies": {
|
|
72
76
|
"@brillout/release-me": "^0.3.8",
|
|
73
|
-
"@types/node": "
|
|
74
|
-
"@types/react": "
|
|
75
|
-
"@types/react-dom": "
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
77
|
+
"@types/node": "link:../demo/node_modules/@types/node/",
|
|
78
|
+
"@types/react": "link:../demo/node_modules/@types/react/",
|
|
79
|
+
"@types/react-dom": "link:../demo/node_modules/@types/react-dom/",
|
|
80
|
+
"react": "link:../demo/node_modules/react/",
|
|
81
|
+
"react-dom": "link:../demo/node_modules/react-dom/",
|
|
82
|
+
"typescript": "link:../demo/node_modules/typescript/",
|
|
83
|
+
"vike": "link:../demo/node_modules/vike/",
|
|
84
|
+
"vite": "link:../demo/node_modules/vite/"
|
|
79
85
|
},
|
|
80
86
|
"repository": "https://github.com/brillout/docpress",
|
|
81
87
|
"license": "MIT",
|
package/parsePageSections.ts
CHANGED
|
@@ -44,7 +44,12 @@ function transform(code: string) {
|
|
|
44
44
|
return line
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
if (
|
|
47
|
+
if (
|
|
48
|
+
line.startsWith('#')
|
|
49
|
+
/* TODO/eventually: implement.
|
|
50
|
+
|| line.startsWith('<h2')
|
|
51
|
+
*/
|
|
52
|
+
) {
|
|
48
53
|
const { pageSectionId, pageSectionLevel, pageSectionTitle, headingHtml } = parsePageSection(line)
|
|
49
54
|
pageSections.push({ pageSectionId, pageSectionLevel, pageSectionTitle })
|
|
50
55
|
return headingHtml
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { getPageElement }
|
|
2
|
+
|
|
3
|
+
import type { PageContext } from 'vike/types'
|
|
4
|
+
import type { PageContextResolved } from '../config/resolvePageContext'
|
|
5
|
+
import { PageLayout } from '../PageLayout'
|
|
6
|
+
import React from 'react'
|
|
7
|
+
|
|
8
|
+
function getPageElement(pageContext: PageContext, pageContextResolved: PageContextResolved) {
|
|
9
|
+
const { Page } = pageContext
|
|
10
|
+
const page = (
|
|
11
|
+
<PageLayout pageContext={pageContextResolved} pageContext2={pageContext}>
|
|
12
|
+
<Page />
|
|
13
|
+
</PageLayout>
|
|
14
|
+
)
|
|
15
|
+
return page
|
|
16
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { onBeforeRender }
|
|
2
|
+
|
|
3
|
+
import { resolvePageContext, type PageContextOriginal, type PageContextResolved } from '../config/resolvePageContext'
|
|
4
|
+
|
|
5
|
+
function onBeforeRender(pageContextOriginal: PageContextOriginal) {
|
|
6
|
+
const pageContextResolved = resolvePageContext(pageContextOriginal)
|
|
7
|
+
return {
|
|
8
|
+
pageContext: {
|
|
9
|
+
pageContextResolved,
|
|
10
|
+
},
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export { onRenderClient }
|
|
2
|
+
|
|
3
|
+
import React, { useEffect } from 'react'
|
|
4
|
+
import type { PageContextClient } from 'vike/types'
|
|
5
|
+
import ReactDOM from 'react-dom/client'
|
|
6
|
+
import { PageContextResolved } from '../config/resolvePageContext'
|
|
7
|
+
import { getPageElement } from './getPageElement'
|
|
8
|
+
import {
|
|
9
|
+
hideNavigationFullScreen,
|
|
10
|
+
initNavigationFullscreen,
|
|
11
|
+
} from '../navigation/navigation-fullscreen/initNavigationFullscreen'
|
|
12
|
+
import { hideMobileNavigation, initMobileNavigation } from '../navigation/initMobileNavigation'
|
|
13
|
+
import { initPressKit } from '../navigation/initPressKit'
|
|
14
|
+
import '../css/index.css'
|
|
15
|
+
import { autoScrollNav } from '../autoScrollNav'
|
|
16
|
+
import { installSectionUrlHashs } from '../installSectionUrlHashs'
|
|
17
|
+
import { addFeatureClickHandlers, addTwitterWidgets } from '../components/FeatureList/FeatureList.client'
|
|
18
|
+
|
|
19
|
+
initOnLinkClick()
|
|
20
|
+
|
|
21
|
+
let root: ReactDOM.Root
|
|
22
|
+
function onRenderClient(pageContext: PageContextClient) {
|
|
23
|
+
const pageContextResolved: PageContextResolved = (pageContext as any).pageContextResolved
|
|
24
|
+
let page = getPageElement(pageContext, pageContextResolved)
|
|
25
|
+
page = <OnRenderDoneHook>{page}</OnRenderDoneHook>
|
|
26
|
+
const container = document.getElementById('page-view')!
|
|
27
|
+
if (pageContext.isHydration) {
|
|
28
|
+
root = ReactDOM.hydrateRoot(container, page)
|
|
29
|
+
} else {
|
|
30
|
+
if (!root) {
|
|
31
|
+
root = ReactDOM.createRoot(container)
|
|
32
|
+
}
|
|
33
|
+
root.render(page)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function onRenderDone() {
|
|
38
|
+
autoScrollNav()
|
|
39
|
+
installSectionUrlHashs()
|
|
40
|
+
initNavigationFullscreen()
|
|
41
|
+
initMobileNavigation()
|
|
42
|
+
initPressKit()
|
|
43
|
+
addFeatureClickHandlers()
|
|
44
|
+
addTwitterWidgets()
|
|
45
|
+
setHydrationIsFinished()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function OnRenderDoneHook({ children }: { children: React.ReactNode }) {
|
|
49
|
+
useEffect(onRenderDone)
|
|
50
|
+
return children
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function initOnLinkClick() {
|
|
54
|
+
document.addEventListener('click', (ev) => {
|
|
55
|
+
const linkTag = findLinkTag(ev.target as HTMLElement)
|
|
56
|
+
if (!linkTag) return
|
|
57
|
+
const url = linkTag.getAttribute('href')
|
|
58
|
+
if (!url) return
|
|
59
|
+
hideMobileNavigation()
|
|
60
|
+
hideNavigationFullScreen()
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
function findLinkTag(target: HTMLElement): null | HTMLElement {
|
|
64
|
+
while (target.tagName !== 'A') {
|
|
65
|
+
const { parentNode } = target
|
|
66
|
+
if (!parentNode) {
|
|
67
|
+
return null
|
|
68
|
+
}
|
|
69
|
+
target = parentNode as HTMLElement
|
|
70
|
+
}
|
|
71
|
+
return target
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function setHydrationIsFinished() {
|
|
75
|
+
// Used by:
|
|
76
|
+
// - https://github.com/vikejs/vike/blob/9d67f3dd4bdfb38c835186b8147251e0e3b06657/docs/.testRun.ts#L22
|
|
77
|
+
// - https://github.com/brillout/telefunc/blob/57c942c15b7795cfda96b5106acc9e098aa509aa/docs/.testRun.ts#L26
|
|
78
|
+
;(window as any).__docpress_hydrationFinished = true
|
|
79
|
+
}
|
|
@@ -1,30 +1,21 @@
|
|
|
1
1
|
export { onRenderHtml }
|
|
2
2
|
|
|
3
3
|
import ReactDOMServer from 'react-dom/server'
|
|
4
|
-
import React from 'react'
|
|
5
4
|
import { escapeInject, dangerouslySkipEscape } from 'vike/server'
|
|
6
|
-
import { PageLayout } from '../PageLayout'
|
|
7
|
-
import { resolvePageContext, PageContextOriginal } from '../config/resolvePageContext'
|
|
8
|
-
import { getDocSearchJS, getDocSearchCSS } from '../algolia/DocSearch'
|
|
9
5
|
import { assert } from '../utils/server'
|
|
6
|
+
import type { PageContextServer } from 'vike/types'
|
|
7
|
+
import type { PageContextResolved } from '../config/resolvePageContext'
|
|
8
|
+
import { getPageElement } from './getPageElement'
|
|
10
9
|
|
|
11
|
-
async function onRenderHtml(
|
|
12
|
-
const
|
|
13
|
-
const pageContextResolved = resolvePageContext(pageContextOriginal)
|
|
10
|
+
async function onRenderHtml(pageContext: PageContextServer) {
|
|
11
|
+
const pageContextResolved: PageContextResolved = (pageContext as any).pageContextResolved
|
|
14
12
|
|
|
15
|
-
const page = (
|
|
16
|
-
<PageLayout pageContext={pageContextResolved}>
|
|
17
|
-
<Page />
|
|
18
|
-
</PageLayout>
|
|
19
|
-
)
|
|
13
|
+
const page = getPageElement(pageContext, pageContextResolved)
|
|
20
14
|
|
|
21
15
|
const descriptionTag = pageContextResolved.isLandingPage
|
|
22
16
|
? dangerouslySkipEscape(`<meta name="description" content="${pageContextResolved.meta.tagline}" />`)
|
|
23
17
|
: ''
|
|
24
18
|
|
|
25
|
-
const docSearchJS = getDocSearchJS(pageContextResolved)
|
|
26
|
-
const docSearchCSS = getDocSearchCSS(pageContextResolved)
|
|
27
|
-
|
|
28
19
|
const pageHtml = ReactDOMServer.renderToString(page)
|
|
29
20
|
|
|
30
21
|
return escapeInject`<!DOCTYPE html>
|
|
@@ -35,16 +26,10 @@ async function onRenderHtml(pageContextOriginal: PageContextOriginal) {
|
|
|
35
26
|
<title>${pageContextResolved.documentTitle}</title>
|
|
36
27
|
${descriptionTag}
|
|
37
28
|
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" />
|
|
38
|
-
${
|
|
39
|
-
${getOpenGraphTags(
|
|
40
|
-
pageContextOriginal.urlPathname,
|
|
41
|
-
pageContextResolved.documentTitle,
|
|
42
|
-
pageContextResolved.meta,
|
|
43
|
-
)}
|
|
29
|
+
${getOpenGraphTags(pageContext.urlPathname, pageContextResolved.documentTitle, pageContextResolved.meta)}
|
|
44
30
|
</head>
|
|
45
31
|
<body>
|
|
46
32
|
<div id="page-view">${dangerouslySkipEscape(pageHtml)}</div>
|
|
47
|
-
${docSearchJS}
|
|
48
33
|
</body>
|
|
49
34
|
</html>`
|
|
50
35
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import React, { useContext } from 'react'
|
|
5
5
|
import type { PageContextResolved } from '../config/resolvePageContext'
|
|
6
|
+
import type { PageContext } from 'vike/types'
|
|
6
7
|
|
|
7
8
|
export { PageContextProvider }
|
|
8
9
|
export { usePageContext }
|
|
@@ -23,3 +24,22 @@ function usePageContext(): PageContextResolved {
|
|
|
23
24
|
const pageContext = useContext(Context)
|
|
24
25
|
return pageContext
|
|
25
26
|
}
|
|
27
|
+
|
|
28
|
+
export { PageContextProvider2 }
|
|
29
|
+
// TODO/refactor: rename to usePageContext and remove old implementation
|
|
30
|
+
export { usePageContext2 }
|
|
31
|
+
|
|
32
|
+
const Context2 = React.createContext<PageContext>(undefined as any)
|
|
33
|
+
function usePageContext2(): PageContext {
|
|
34
|
+
const pageContext = useContext(Context2)
|
|
35
|
+
return pageContext
|
|
36
|
+
}
|
|
37
|
+
function PageContextProvider2({
|
|
38
|
+
pageContext,
|
|
39
|
+
children,
|
|
40
|
+
}: {
|
|
41
|
+
pageContext: PageContext
|
|
42
|
+
children: React.ReactNode
|
|
43
|
+
}) {
|
|
44
|
+
return <Context2.Provider value={pageContext}>{children}</Context2.Provider>
|
|
45
|
+
}
|
package/tsconfig.config.json
CHANGED
package/tsconfig.json
CHANGED
package/types/Config.ts
CHANGED
|
@@ -13,28 +13,14 @@ type Config = {
|
|
|
13
13
|
twitterProfile: string
|
|
14
14
|
}
|
|
15
15
|
faviconUrl: string
|
|
16
|
-
algolia:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
| {
|
|
22
|
-
appId?: undefined
|
|
23
|
-
apiKey?: undefined
|
|
24
|
-
indexName?: undefined
|
|
25
|
-
}
|
|
26
|
-
| {
|
|
27
|
-
appId: string
|
|
28
|
-
apiKey: string
|
|
29
|
-
indexName: string
|
|
30
|
-
}
|
|
31
|
-
))
|
|
16
|
+
algolia: null | {
|
|
17
|
+
appId: string
|
|
18
|
+
apiKey: string
|
|
19
|
+
indexName: string
|
|
20
|
+
}
|
|
32
21
|
headings: HeadingDefinition[]
|
|
33
22
|
headingsDetached: HeadingDetachedDefinition[]
|
|
34
|
-
|
|
35
|
-
navHeaderMobileWrapperStyle?: React.CSSProperties
|
|
36
|
-
navHeader: React.ReactNode
|
|
37
|
-
navHeaderWrapperStyle?: React.CSSProperties
|
|
23
|
+
|
|
38
24
|
/** Sets `<meta name="description" content="${tagline}" />` */
|
|
39
25
|
tagline: string
|
|
40
26
|
websiteUrl: string
|
package/types/Heading.ts
CHANGED
|
@@ -8,9 +8,9 @@ import type { EmojiName } from '../utils/server'
|
|
|
8
8
|
type HeadingResolved = {
|
|
9
9
|
url?: null | string
|
|
10
10
|
level: number
|
|
11
|
-
title:
|
|
12
|
-
titleInNav:
|
|
13
|
-
linkBreadcrumb:
|
|
11
|
+
title: string
|
|
12
|
+
titleInNav: string
|
|
13
|
+
linkBreadcrumb: string[]
|
|
14
14
|
sectionTitles?: string[]
|
|
15
15
|
} & Tmp
|
|
16
16
|
|
|
@@ -21,7 +21,7 @@ type HeadingDetachedResolved = Omit<HeadingResolved, 'level' | 'linkBreadcrumb'>
|
|
|
21
21
|
|
|
22
22
|
type HeadingDetachedDefinition = {
|
|
23
23
|
url: string
|
|
24
|
-
title: string
|
|
24
|
+
title: string
|
|
25
25
|
sectionTitles?: string[]
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -37,7 +37,7 @@ type IsCategory = {
|
|
|
37
37
|
titleInNav?: undefined
|
|
38
38
|
}
|
|
39
39
|
type HeadingDefinitionLevel =
|
|
40
|
-
| ({ level: 1
|
|
40
|
+
| ({ level: 1 } & IsCategory)
|
|
41
41
|
| ({ level: 4 } & IsCategory)
|
|
42
42
|
| {
|
|
43
43
|
level: 2
|
package/vite.config.ts
CHANGED
|
@@ -26,10 +26,12 @@ const config: UserConfig = {
|
|
|
26
26
|
includeAssetsImportedByServer: true,
|
|
27
27
|
}),
|
|
28
28
|
],
|
|
29
|
-
optimizeDeps: {
|
|
30
|
-
|
|
29
|
+
optimizeDeps: {
|
|
30
|
+
include: ['react', 'react-dom', 'react-dom/client'],
|
|
31
|
+
exclude: ['@brillout/docpress'],
|
|
32
|
+
},
|
|
31
33
|
ssr: {
|
|
32
|
-
noExternal: ['@brillout/docpress'],
|
|
34
|
+
noExternal: ['@brillout/docpress', '@docsearch/react'],
|
|
33
35
|
},
|
|
34
36
|
clearScreen: false,
|
|
35
37
|
}
|
package/algolia/DocSearch.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
export { getDocSearchCSS }
|
|
2
|
-
export { getDocSearchJS }
|
|
3
|
-
|
|
4
|
-
import { dangerouslySkipEscape, escapeInject } from 'vike/server'
|
|
5
|
-
import { PageContextResolved } from '../config/resolvePageContext'
|
|
6
|
-
/* Imorted in /src/css/index.css instead
|
|
7
|
-
import './DocSearch.css'
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
function getDocSearchCSS(pageContext: PageContextResolved) {
|
|
11
|
-
const docSearchCSS = !pageContext.meta.algolia
|
|
12
|
-
? ''
|
|
13
|
-
: escapeInject`
|
|
14
|
-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@docsearch/css@alpha" />
|
|
15
|
-
`
|
|
16
|
-
return docSearchCSS
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function getDocSearchJS(pageContext: PageContextResolved) {
|
|
20
|
-
const { algolia } = pageContext.meta
|
|
21
|
-
// If the docpress website doesn't use algolia => we don't inject the algolia assets => the search icon wrapper stays empty
|
|
22
|
-
// If algolia is PENDING_APPROVAL => we fill a FAKE API key so that the algolia popup shows (while no results are shown).
|
|
23
|
-
// - We show an alert warning users that there aren't any results until algolia's approval is pending (see below).
|
|
24
|
-
let docSearchJS = !algolia
|
|
25
|
-
? ''
|
|
26
|
-
: escapeInject`
|
|
27
|
-
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@docsearch/js@alpha"></script>
|
|
28
|
-
<script type="text/javascript">
|
|
29
|
-
const appId = '${algolia.appId || 'FAKE'}';
|
|
30
|
-
const apiKey = '${algolia.apiKey || 'FAKE'}';
|
|
31
|
-
const indexName = '${algolia.indexName || 'FAKE'}';
|
|
32
|
-
const transformItems = ${dangerouslySkipEscape(getTransformItems())};
|
|
33
|
-
docsearch({
|
|
34
|
-
container: '#docsearch-desktop',
|
|
35
|
-
appId, apiKey, indexName, transformItems,
|
|
36
|
-
insights: true,
|
|
37
|
-
});
|
|
38
|
-
</script>
|
|
39
|
-
`
|
|
40
|
-
if (algolia?.PENDING_APPROVAL) {
|
|
41
|
-
docSearchJS = escapeInject`
|
|
42
|
-
${docSearchJS}
|
|
43
|
-
<script>document.getElementById('docsearch-desktop').addEventListener('click', () => window.alert("Algolia approval is pending: the search results may be empty until the approval process is completed."))</script>
|
|
44
|
-
`
|
|
45
|
-
}
|
|
46
|
-
return docSearchJS
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Remove superfluous hash '#page-content' from URLs pointing to whole pages
|
|
50
|
-
// - https://github.com/algolia/docsearch/issues/1801
|
|
51
|
-
// - https://discourse.algolia.com/t/how-to-avoid-hash-in-search-result-url/6486
|
|
52
|
-
// - https://discourse.algolia.com/t/docsearchs-transformdata-function-cannot-remove-hashes-from-result-urls/8487
|
|
53
|
-
function getTransformItems() {
|
|
54
|
-
return `function(hits) {
|
|
55
|
-
hits.map(hit => {
|
|
56
|
-
if (hit.url.indexOf('#page-content') > 0) {
|
|
57
|
-
hit.url = hit.url.replace('#page-content', '');
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
return hits;
|
|
61
|
-
}`
|
|
62
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { initNavigationFullscreen } from './navigation-fullscreen/initNavigationFullscreen'
|
|
2
|
-
import { initMobileNavigation } from './initMobileNavigation'
|
|
3
|
-
import { initPressKit } from './initPressKit'
|
|
4
|
-
|
|
5
|
-
initNavigationFullscreen()
|
|
6
|
-
initMobileNavigation()
|
|
7
|
-
initPressKit()
|
package/renderer/client.ts
DELETED