@brillout/docpress 0.6.19 → 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/components/Note.tsx +1 -1
- 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
|
@@ -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,53 @@
|
|
|
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 { initNavigationFullscreen } from '../navigation/navigation-fullscreen/initNavigationFullscreen'
|
|
9
|
+
import { initMobileNavigation } from '../navigation/initMobileNavigation'
|
|
10
|
+
import { initPressKit } from '../navigation/initPressKit'
|
|
11
|
+
import '../css/index.css'
|
|
12
|
+
import { autoScrollNav } from '../autoScrollNav'
|
|
13
|
+
import { installSectionUrlHashs } from '../installSectionUrlHashs'
|
|
14
|
+
import { addFeatureClickHandlers, addTwitterWidgets } from '../components/FeatureList/FeatureList.client'
|
|
15
|
+
|
|
16
|
+
let root: ReactDOM.Root
|
|
17
|
+
function onRenderClient(pageContext: PageContextClient) {
|
|
18
|
+
const pageContextResolved: PageContextResolved = (pageContext as any).pageContextResolved
|
|
19
|
+
let page = getPageElement(pageContext, pageContextResolved)
|
|
20
|
+
page = <OnRenderDoneHook>{page}</OnRenderDoneHook>
|
|
21
|
+
const container = document.getElementById('page-view')!
|
|
22
|
+
if (pageContext.isHydration) {
|
|
23
|
+
root = ReactDOM.hydrateRoot(container, page)
|
|
24
|
+
} else {
|
|
25
|
+
if (!root) {
|
|
26
|
+
root = ReactDOM.createRoot(container)
|
|
27
|
+
}
|
|
28
|
+
root.render(page)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function onRenderDone() {
|
|
33
|
+
autoScrollNav()
|
|
34
|
+
installSectionUrlHashs()
|
|
35
|
+
initNavigationFullscreen()
|
|
36
|
+
initMobileNavigation()
|
|
37
|
+
initPressKit()
|
|
38
|
+
addFeatureClickHandlers()
|
|
39
|
+
addTwitterWidgets()
|
|
40
|
+
setHydrationIsFinished()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function OnRenderDoneHook({ children }: { children: React.ReactNode }) {
|
|
44
|
+
useEffect(onRenderDone)
|
|
45
|
+
return children
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function setHydrationIsFinished() {
|
|
49
|
+
// Used by:
|
|
50
|
+
// - https://github.com/vikejs/vike/blob/9d67f3dd4bdfb38c835186b8147251e0e3b06657/docs/.testRun.ts#L22
|
|
51
|
+
// - https://github.com/brillout/telefunc/blob/57c942c15b7795cfda96b5106acc9e098aa509aa/docs/.testRun.ts#L26
|
|
52
|
+
;(window as any).__docpress_hydrationFinished = true
|
|
53
|
+
}
|
|
@@ -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.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
|
|
package/vite.config.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { parsePageSections } from './parsePageSections.js'
|
|
|
6
6
|
import rehypePrettyCode from 'rehype-pretty-code'
|
|
7
7
|
import remarkGfm from 'remark-gfm'
|
|
8
8
|
import { transformerNotationDiff } from '@shikijs/transformers'
|
|
9
|
+
import { cjsInterop } from 'vite-plugin-cjs-interop'
|
|
9
10
|
|
|
10
11
|
const root = process.cwd()
|
|
11
12
|
const prettyCode = [rehypePrettyCode, { theme: 'github-light', transformers: [transformerNotationDiff()] }]
|
|
@@ -25,9 +26,13 @@ const config: UserConfig = {
|
|
|
25
26
|
},
|
|
26
27
|
includeAssetsImportedByServer: true,
|
|
27
28
|
}),
|
|
29
|
+
cjsInterop({
|
|
30
|
+
dependencies: ['@docsearch/react'],
|
|
31
|
+
}),
|
|
28
32
|
],
|
|
29
|
-
optimizeDeps: {
|
|
30
|
-
|
|
33
|
+
optimizeDeps: {
|
|
34
|
+
include: ['react-dom/client', '@docsearch/react'],
|
|
35
|
+
},
|
|
31
36
|
ssr: {
|
|
32
37
|
noExternal: ['@brillout/docpress'],
|
|
33
38
|
},
|
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