@brillout/docpress 0.0.45
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/cli.mjs +2 -0
- package/dist/cli/chunk-KZROB63P.js +8 -0
- package/dist/cli/configFile.js +6 -0
- package/dist/cli/devServer.js +31 -0
- package/dist/cli/index.js +37 -0
- package/index.ts +2 -0
- package/mdx.d.ts +6 -0
- package/package.json +73 -0
- package/readme.md +3 -0
- package/src/MobileHeader.tsx +68 -0
- package/src/PageLayout.css +32 -0
- package/src/PageLayout.tsx +43 -0
- package/src/algolia/DocSearch.css +29 -0
- package/src/algolia/DocSearch.ts +37 -0
- package/src/autoScrollNav.ts +22 -0
- package/src/components/ContactUs.tsx +19 -0
- package/src/components/DocLink.tsx +108 -0
- package/src/components/EditPageNote.tsx +18 -0
- package/src/components/HorizontalLine.tsx +20 -0
- package/src/components/ImportMeta.tsx +11 -0
- package/src/components/Info.tsx +12 -0
- package/src/components/Link.tsx +18 -0
- package/src/components/Note.tsx +31 -0
- package/src/components/P.css +8 -0
- package/src/components/P.tsx +8 -0
- package/src/components/ReadingRecommendation.tsx +53 -0
- package/src/components/RepoLink.tsx +24 -0
- package/src/components/Sponsors/companyLogos/ccoli-logo.svg +1 -0
- package/src/components/Sponsors/companyLogos/ccoli-text.svg +1 -0
- package/src/components/Sponsors/companyLogos/ccoli.svg +9 -0
- package/src/components/Sponsors/companyLogos/contra.svg +1 -0
- package/src/components/Sponsors/companyLogos/mfqs.svg +1 -0
- package/src/components/Sponsors/label.draft.svg +108 -0
- package/src/components/Sponsors/label.svg +5 -0
- package/src/components/Sponsors/medalBronze.svg +65 -0
- package/src/components/Sponsors/medalGold.svg +65 -0
- package/src/components/Sponsors/medalSilver.svg +65 -0
- package/src/components/Sponsors.tsx +240 -0
- package/src/components/TextContactUs.tsx +15 -0
- package/src/components/features/FeatureList.css +117 -0
- package/src/components/features/FeatureList.tsx +114 -0
- package/src/components/features/chevron.svg +7 -0
- package/src/components/features/initFeatureList.ts +61 -0
- package/src/components/index.ts +14 -0
- package/src/config/Config.ts +30 -0
- package/src/config/getConfig.ts +18 -0
- package/src/config/resolveConfig/resolveHeading.ts +0 -0
- package/src/config/resolvePageContext.ts +156 -0
- package/src/css/Inter-Var.ttf +0 -0
- package/src/css/button.css +7 -0
- package/src/css/code/block.css +36 -0
- package/src/css/code/inline.css +27 -0
- package/src/css/code.css +20 -0
- package/src/css/colorize-on-hover.css +29 -0
- package/src/css/font.css +19 -0
- package/src/css/heading.css +25 -0
- package/src/css/index.css +10 -0
- package/src/css/link.css +17 -0
- package/src/css/note.css +26 -0
- package/src/css/reset.css +12 -0
- package/src/css/table.css +14 -0
- package/src/css/tooltip.css +11 -0
- package/src/headings.ts +206 -0
- package/src/icons/changelog.svg +2 -0
- package/src/icons/discord.svg +10 -0
- package/src/icons/github.svg +74 -0
- package/src/icons/heart.svg +1 -0
- package/src/icons/twitter.svg +16 -0
- package/src/index.ts +3 -0
- package/src/installSectionUrlHashs.ts +50 -0
- package/src/navigation/Navigation-highlight.css +41 -0
- package/src/navigation/Navigation-items.css +122 -0
- package/src/navigation/Navigation-layout.css +119 -0
- package/src/navigation/Navigation.client.old.ts +303 -0
- package/src/navigation/Navigation.client.ts +19 -0
- package/src/navigation/Navigation.css +8 -0
- package/src/navigation/Navigation.tsx +228 -0
- package/src/navigation/NavigationHeader.tsx +97 -0
- package/src/navigation/navigation-fullscreen/NavigationFullscreenButton.css +32 -0
- package/src/navigation/navigation-fullscreen/NavigationFullscreenButton.tsx +44 -0
- package/src/navigation/navigation-fullscreen/chevron.svg +1 -0
- package/src/navigation/navigation-fullscreen/close.svg +4 -0
- package/src/navigation/navigation-fullscreen/initNavigationFullscreen.ts +115 -0
- package/src/parseEmojis.ts +33 -0
- package/src/renderer/_default.page.client.ts +7 -0
- package/src/renderer/_default.page.server.tsx +69 -0
- package/src/renderer/usePageContext.tsx +25 -0
- package/src/types.ts +2 -0
- package/src/utils/Emoji/Emoji.ts +216 -0
- package/src/utils/Emoji/assets.ts +9 -0
- package/src/utils/Emoji/compass.svg +1 -0
- package/src/utils/Emoji/engine.png +0 -0
- package/src/utils/Emoji/index.ts +1 -0
- package/src/utils/Emoji/mechanical-arm.svg +1 -0
- package/src/utils/Emoji/mountain.svg +1 -0
- package/src/utils/Emoji/road-fork.svg +17 -0
- package/src/utils/Emoji/shield.svg +1 -0
- package/src/utils/Emoji/typescript.svg +1 -0
- package/src/utils/assert.ts +39 -0
- package/src/utils/determineSectionUrlHash.ts +35 -0
- package/src/utils/filter.ts +12 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/isBrowser.ts +5 -0
- package/src/utils/jsxToTextContent.ts +11 -0
- package/src/utils/objectAssign.ts +6 -0
- package/vite.config/markdownHeadings.ts +128 -0
- package/vite.config.ts +42 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
|
3
|
+
<svg width="487.56" height="484.09" version="1.1" viewBox="0 0 487.56 484.09" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
|
4
|
+
<metadata>
|
|
5
|
+
<rdf:RDF>
|
|
6
|
+
<cc:Work rdf:about="">
|
|
7
|
+
<dc:format>image/svg+xml</dc:format>
|
|
8
|
+
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
|
|
9
|
+
<dc:title/>
|
|
10
|
+
</cc:Work>
|
|
11
|
+
</rdf:RDF>
|
|
12
|
+
</metadata>
|
|
13
|
+
<path d="m482.68 248.19c1.2439-1.5861 1.2085-1.6214-0.37756-0.37756-1.6658 1.3064-2.1955 2.1276-1.3724 2.1276 0.20765 0 0.99515-0.7875 1.75-1.75z"/>
|
|
14
|
+
<path d="m486.68 244.19c1.2439-1.5861 1.2085-1.6214-0.37756-0.37756-1.6658 1.3064-2.1955 2.1276-1.3724 2.1276 0.20765 0 0.99515-0.7875 1.75-1.75z"/>
|
|
15
|
+
<path d="m247.42 474.17c2.8185-1.2899 25.113-23.215 75.476-74.228 39.312-39.819 87.237-88.253 106.5-107.63 39.149-39.385 41.06-41.824 40.23-51.353-0.26767-3.0733-1.2636-7.1233-2.2131-9s-17.761-19.607-37.36-39.401c-19.598-19.794-52.958-53.542-74.133-74.997-96.779-98.055-104.54-105.75-108.5-107.6-5.1002-2.3843-11.892-2.3865-17-0.0055-3.9548 1.8434-8.8989 6.7455-104.48 103.59-20.085 20.351-53.896 54.551-75.135 76s-39.375 40.485-40.303 42.302c-3.7569 7.3558-3.0617 16.444 1.7574 22.976 1.2591 1.7066 35.089 36.317 75.177 76.911 132.68 134.35 138.77 140.43 142.99 142.39 5.0756 2.3728 11.867 2.3885 17 0.0393z" fill="#fcb714" stroke="#000" stroke-width="23.679"/>
|
|
16
|
+
<path d="m219.09 282.89c-4.0367-13.001-11.907-25.342-22.59-35.421-7.839-7.396-22.642-17.061-23.783-15.528-0.17973 0.24149-1.7743 7.1558-3.5435 15.365l-3.2168 14.926-3.5852-3.2694c-48.105-43.867-69.248-63.877-68.356-64.69 1.6551-1.5099 91.839-29.402 92.601-28.64 0.36214 0.36213-0.92831 7.6875-2.8676 16.279-1.9393 8.5912-3.3666 15.676-3.1718 15.744 6.9672 2.4303 26.283 13.741 33.175 19.426 8.4568 6.9756 21.03 20.689 24.466 26.685 1.2973 2.2636 1.5974 2.1875 3.8469-0.97471 12.275-17.255 27.561-30.663 44.569-39.093 6.5682-3.2556 12.102-5.9748 12.296-6.0428 0.19483-0.0679-1.2325-7.1527-3.1718-15.744-1.9394-8.5911-3.2235-15.923-2.8537-16.293 0.77891-0.77893 90.923 27.131 92.607 28.672 0.89233 0.81692-52.476 51.326-68.304 64.644l-3.6976 3.1113-3.1964-14.833c-1.758-8.1582-3.3615-15.049-3.5632-15.312-0.20177-0.26354-4.0381 1.4776-8.5252 3.8692-15.965 8.5093-32.067 28.563-37.842 47.129-3.6379 22.651-2.3162 36.651-3.7002 79.93l-0.37063 33.564h-33.168c-1.6004-73.949-0.48835-86.769-4.0563-113.5z" stroke-width="1.3841"/>
|
|
17
|
+
</svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 128 128"><path d="M16.77 19.75c-1 0-1.7.8-1.7 1.8v.1c-1.5 25.91 3.03 59.27 24.01 83.52c12.1 14.7 23.91 18.53 24.51 18.73c0 0 .28.09.54.09s.57-.1.57-.1c.5-.2 12.48-4.02 24.49-18.72c19.91-24.21 24.01-58.82 24.01-83.52v-.1c0-1-.8-1.8-1.7-1.8c-.3 0-29.11-1-46.01-15.3c-.7-.6-1.7-.6-2.4 0c-17.11 14.2-46.02 15.2-46.32 15.3z" fill="#b0bec5"/><path d="M111.49 19.75c-.3 0-29.11-1-46.01-15.3c-.4-.35-.83-.45-1.24-.45h-.11v120c.27-.01.62-.11.62-.12c.6-.25 12.44-4 24.44-18.7c19.91-24.21 24.01-58.82 24.01-83.52v-.1c0-1.01-.8-1.81-1.71-1.81z" fill="#84b0c1"/><path d="M26.33 28.31c-.82 0-1.02 1.02-1.02 1.74v.1c0 19.72 3.06 47.4 19 66.71c9.6 11.75 19 14.81 19.41 14.91l.41.1l.41-.1c.41-.1 9.81-3.17 19.41-14.91c15.94-19.31 19-46.89 19-66.71v-.1c0-.82-.41-1.43-1.23-1.43h.1c-.2 0-23.19-.82-36.67-12.16c-1.19-.98-1.94-.2-1.94-.2C49.63 27.6 26.64 28.31 26.33 28.31z" fill="#2f7889"/><path d="M29.18 30.07c-.76 0-.94.96-.94 1.64v.1c0 18.57 2.83 44.65 17.57 62.84c8.88 11.07 17.57 13.95 17.95 14.05l.38.1l.38-.1c.38-.1 9.07-2.98 17.95-14.05c14.73-18.19 17.57-44.17 17.57-62.84v-.1c0-.77-.38-1.35-1.13-1.35H99c-.19 0-21.44-.77-33.91-11.45c-.94-.95-1.79-.19-1.79-.19C50.72 29.4 29.47 30.07 29.18 30.07z" fill="#c9e3e6"/><path d="M98.89 30.36h.09c-.19 0-21.44-.77-33.91-11.45c-.34-.34-.66-.46-.94-.47v90.35l.38-.1c.38-.1 9.07-2.98 17.95-14.05c14.73-18.19 17.57-44.17 17.57-62.84v-.1c-.01-.76-.38-1.34-1.14-1.34z" fill="#b0bec5"/><g><circle cx="70.63" cy="14.44" r="1.93" fill="#37474f"/><circle cx="82.21" cy="19.67" r="1.93" fill="#37474f"/><circle cx="95.01" cy="23.21" r="1.93" fill="#37474f"/><circle cx="108.15" cy="25.14" r="1.93" fill="#37474f"/><circle cx="108.57" cy="36.94" r="1.93" fill="#37474f"/><circle cx="107.02" cy="50.76" r="1.93" fill="#37474f"/><circle cx="64.08" cy="118.11" r="1.93" fill="#37474f"/><circle cx="75.4" cy="112.71" r="1.93" fill="#37474f"/><circle cx="85.74" cy="102.71" r="1.93" fill="#37474f"/><circle cx="93.81" cy="91.27" r="1.93" fill="#37474f"/><circle cx="99.67" cy="79" r="1.93" fill="#37474f"/><circle cx="104.27" cy="64.65" r="1.93" fill="#37474f"/><circle cx="70.15" cy="13.8" r="1.93" fill="#b9e4ea"/><circle cx="81.73" cy="19.03" r="1.93" fill="#b9e4ea"/><circle cx="94.53" cy="22.57" r="1.93" fill="#b9e4ea"/><circle cx="107.66" cy="24.5" r="1.93" fill="#b9e4ea"/><circle cx="108.09" cy="36.3" r="1.93" fill="#b9e4ea"/><circle cx="106.53" cy="50.12" r="1.93" fill="#b9e4ea"/><circle cx="63.6" cy="117.47" r="1.93" fill="#eee"/><circle cx="74.92" cy="112.07" r="1.93" fill="#b9e4ea"/><circle cx="85.26" cy="102.07" r="1.93" fill="#b9e4ea"/><circle cx="93.33" cy="90.63" r="1.93" fill="#b9e4ea"/><circle cx="99.19" cy="78.36" r="1.93" fill="#b9e4ea"/><circle cx="103.79" cy="64.01" r="1.93" fill="#b9e4ea"/><circle cx="57.97" cy="14.44" r="1.93" fill="#2f7889"/><circle cx="46.39" cy="19.67" r="1.93" fill="#2f7889"/><circle cx="33.59" cy="23.21" r="1.93" fill="#2f7889"/><circle cx="20.45" cy="25.14" r="1.93" fill="#2f7889"/><circle cx="20.02" cy="36.94" r="1.93" fill="#2f7889"/><circle cx="21.58" cy="50.76" r="1.93" fill="#2f7889"/><circle cx="53.19" cy="112.71" r="1.93" fill="#2f7889"/><circle cx="42.86" cy="102.71" r="1.93" fill="#2f7889"/><circle cx="34.79" cy="91.27" r="1.93" fill="#2f7889"/><circle cx="28.92" cy="79" r="1.93" fill="#2f7889"/><circle cx="24.33" cy="64.65" r="1.93" fill="#2f7889"/><circle cx="57.54" cy="13.8" r="1.93" fill="#eee"/><circle cx="45.95" cy="19.03" r="1.93" fill="#eee"/><circle cx="33.16" cy="22.57" r="1.93" fill="#eee"/><circle cx="20.02" cy="24.5" r="1.93" fill="#eee"/><circle cx="19.59" cy="36.3" r="1.93" fill="#eee"/><circle cx="21.15" cy="50.12" r="1.93" fill="#eee"/><circle cx="52.76" cy="112.07" r="1.93" fill="#eee"/><circle cx="42.42" cy="102.07" r="1.93" fill="#eee"/><circle cx="34.36" cy="90.63" r="1.93" fill="#eee"/><circle cx="28.49" cy="78.36" r="1.93" fill="#eee"/><circle cx="23.89" cy="64.01" r="1.93" fill="#eee"/></g></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg fill="none" height="512" viewBox="0 0 512 512" width="512" xmlns="http://www.w3.org/2000/svg"><rect fill="#3178c6" height="512" rx="50" width="512"/><rect fill="#3178c6" height="512" rx="50" width="512"/><path clip-rule="evenodd" d="m316.939 407.424v50.061c8.138 4.172 17.763 7.3 28.875 9.386s22.823 3.129 35.135 3.129c11.999 0 23.397-1.147 34.196-3.442 10.799-2.294 20.268-6.075 28.406-11.342 8.138-5.266 14.581-12.15 19.328-20.65s7.121-19.007 7.121-31.522c0-9.074-1.356-17.026-4.069-23.857s-6.625-12.906-11.738-18.225c-5.112-5.319-11.242-10.091-18.389-14.315s-15.207-8.213-24.18-11.967c-6.573-2.712-12.468-5.345-17.685-7.9-5.217-2.556-9.651-5.163-13.303-7.822-3.652-2.66-6.469-5.476-8.451-8.448-1.982-2.973-2.974-6.336-2.974-10.091 0-3.441.887-6.544 2.661-9.308s4.278-5.136 7.512-7.118c3.235-1.981 7.199-3.52 11.894-4.615 4.696-1.095 9.912-1.642 15.651-1.642 4.173 0 8.581.313 13.224.938 4.643.626 9.312 1.591 14.008 2.894 4.695 1.304 9.259 2.947 13.694 4.928 4.434 1.982 8.529 4.276 12.285 6.884v-46.776c-7.616-2.92-15.937-5.084-24.962-6.492s-19.381-2.112-31.066-2.112c-11.895 0-23.163 1.278-33.805 3.833s-20.006 6.544-28.093 11.967c-8.086 5.424-14.476 12.333-19.171 20.729-4.695 8.395-7.043 18.433-7.043 30.114 0 14.914 4.304 27.638 12.912 38.172 8.607 10.533 21.675 19.45 39.204 26.751 6.886 2.816 13.303 5.579 19.25 8.291s11.086 5.528 15.415 8.448c4.33 2.92 7.747 6.101 10.252 9.543 2.504 3.441 3.756 7.352 3.756 11.733 0 3.233-.783 6.231-2.348 8.995s-3.939 5.162-7.121 7.196-7.147 3.624-11.894 4.771c-4.748 1.148-10.303 1.721-16.668 1.721-10.851 0-21.597-1.903-32.24-5.71-10.642-3.806-20.502-9.516-29.579-17.13zm-84.159-123.342h64.22v-41.082h-179v41.082h63.906v182.918h50.874z" fill="#fff" fill-rule="evenodd"/></svg>
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export { assert }
|
|
2
|
+
export { assertUsage }
|
|
3
|
+
|
|
4
|
+
function assert(condition: unknown, debugInfo?: unknown): asserts condition {
|
|
5
|
+
if (condition) {
|
|
6
|
+
return
|
|
7
|
+
}
|
|
8
|
+
const hasDebugInfo = debugInfo !== undefined
|
|
9
|
+
if (hasDebugInfo) {
|
|
10
|
+
console.log(debugInfo)
|
|
11
|
+
if (typeof debugInfo === 'object') {
|
|
12
|
+
debugInfo = JSON.stringify(debugInfo)
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
let errMsg = '[DocPress] Bug. Contact DocPress maintainer.'
|
|
16
|
+
if (hasDebugInfo) {
|
|
17
|
+
errMsg += ' Debug info: ' + String(debugInfo)
|
|
18
|
+
}
|
|
19
|
+
const err = new Error(errMsg)
|
|
20
|
+
if (isBrowserAndDev()) {
|
|
21
|
+
alert(err.stack)
|
|
22
|
+
}
|
|
23
|
+
throw err
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function assertUsage(condition: unknown, msg: string): asserts condition {
|
|
27
|
+
if (condition) {
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
const err = new Error('[DocPress][Wrong Usage] ' + msg)
|
|
31
|
+
if (isBrowserAndDev()) {
|
|
32
|
+
alert(err.stack)
|
|
33
|
+
}
|
|
34
|
+
throw err
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function isBrowserAndDev() {
|
|
38
|
+
return typeof window !== 'undefined' && window?.location?.port !== ''
|
|
39
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { assert } from './assert'
|
|
2
|
+
|
|
3
|
+
export { determineSectionUrlHash }
|
|
4
|
+
export { determineSectionTitle }
|
|
5
|
+
|
|
6
|
+
function determineSectionUrlHash(title: string): string {
|
|
7
|
+
const urlHash = title
|
|
8
|
+
.toLowerCase()
|
|
9
|
+
.split(/[^a-z0-9]+/)
|
|
10
|
+
.filter(Boolean)
|
|
11
|
+
.join('-')
|
|
12
|
+
return urlHash
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function determineSectionTitle(urlWithHash: string, titleNormalCase: boolean): string {
|
|
16
|
+
assert(urlWithHash.includes('#'), { urlWithHash })
|
|
17
|
+
const urlHash = urlWithHash.split('#')[1]
|
|
18
|
+
const title = urlHash
|
|
19
|
+
.split('-')
|
|
20
|
+
.map((word, i) => {
|
|
21
|
+
if (i === 0) {
|
|
22
|
+
return capitalizeFirstLetter(word)
|
|
23
|
+
}
|
|
24
|
+
if (!titleNormalCase && word.length >= 4) {
|
|
25
|
+
return capitalizeFirstLetter(word)
|
|
26
|
+
}
|
|
27
|
+
return word
|
|
28
|
+
})
|
|
29
|
+
.join(' ')
|
|
30
|
+
return title
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function capitalizeFirstLetter(word: string): string {
|
|
34
|
+
return word[0].toUpperCase() + word.slice(1)
|
|
35
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { filter }
|
|
2
|
+
|
|
3
|
+
// https://stackoverflow.com/questions/66341757/typescript-how-to-filter-the-object
|
|
4
|
+
function filter<T extends object>(obj: T, predicate: <K extends keyof T>(value: T[K], key: K) => boolean): T {
|
|
5
|
+
const result: { [K in keyof T]?: T[K] } = {}
|
|
6
|
+
;(Object.keys(obj) as Array<keyof T>).forEach((name) => {
|
|
7
|
+
if (predicate(obj[name], name)) {
|
|
8
|
+
result[name] = obj[name]
|
|
9
|
+
}
|
|
10
|
+
})
|
|
11
|
+
return result as T
|
|
12
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { assert } from './assert'
|
|
2
|
+
|
|
3
|
+
export { jsxToTextContent }
|
|
4
|
+
|
|
5
|
+
// https://stackoverflow.com/questions/34204975/react-is-there-something-similar-to-node-textcontent/60564620#60564620
|
|
6
|
+
function jsxToTextContent(node: JSX.Element | string): string {
|
|
7
|
+
if (['string', 'number'].includes(typeof node)) return String(node)
|
|
8
|
+
if (node instanceof Array) return node.map(jsxToTextContent).join('')
|
|
9
|
+
if (typeof node === 'object' && node) return jsxToTextContent(node.props.children)
|
|
10
|
+
assert(false)
|
|
11
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { assert, determineSectionUrlHash } from '../src/utils'
|
|
2
|
+
|
|
3
|
+
export { MarkdownHeading }
|
|
4
|
+
export { markdownHeadings }
|
|
5
|
+
|
|
6
|
+
type MarkdownHeading = {
|
|
7
|
+
title: string
|
|
8
|
+
id: string
|
|
9
|
+
headingLevel: number
|
|
10
|
+
titleAddendum?: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function markdownHeadings() {
|
|
14
|
+
return {
|
|
15
|
+
name: 'mdx-headings',
|
|
16
|
+
enforce: 'pre',
|
|
17
|
+
transform: async (code: string, id: string) => {
|
|
18
|
+
if (!id.includes('.page.') || !id.endsWith('.mdx')) {
|
|
19
|
+
return
|
|
20
|
+
}
|
|
21
|
+
const codeNew = transform(code)
|
|
22
|
+
return codeNew
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function transform(code: string) {
|
|
28
|
+
const headings: MarkdownHeading[] = []
|
|
29
|
+
let isCodeBlock = false
|
|
30
|
+
let codeNew = code
|
|
31
|
+
.split('\n')
|
|
32
|
+
.map((line) => {
|
|
33
|
+
// Skip code blocks, e.g.
|
|
34
|
+
// ~~~md
|
|
35
|
+
// # Markdown Example
|
|
36
|
+
// Bla
|
|
37
|
+
// ~~~
|
|
38
|
+
if (line.startsWith('~~~') || line.startsWith('```')) {
|
|
39
|
+
isCodeBlock = !isCodeBlock
|
|
40
|
+
return line
|
|
41
|
+
}
|
|
42
|
+
if (isCodeBlock) {
|
|
43
|
+
return line
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (line.startsWith('#')) {
|
|
47
|
+
const { id, headingLevel, title, headingHtml } = parseMarkdownHeading(line)
|
|
48
|
+
headings.push({ id, headingLevel, title })
|
|
49
|
+
return headingHtml
|
|
50
|
+
}
|
|
51
|
+
if (line.startsWith('<h')) {
|
|
52
|
+
assert(false, { line })
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return line
|
|
56
|
+
})
|
|
57
|
+
.join('\n')
|
|
58
|
+
const headingsExportCode = `export const headings = [${headings
|
|
59
|
+
.map((heading) => JSON.stringify(heading))
|
|
60
|
+
.join(', ')}];`
|
|
61
|
+
codeNew += `\n\n${headingsExportCode}\n`
|
|
62
|
+
return codeNew
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function parseMarkdownHeading(line: string): MarkdownHeading & { headingHtml: string } {
|
|
66
|
+
const [lineBegin, ...lineWords] = line.split(' ')
|
|
67
|
+
assert(lineBegin.split('#').join('') === '', { line, lineWords })
|
|
68
|
+
const headingLevel = lineBegin.length
|
|
69
|
+
|
|
70
|
+
const titleMdx = lineWords.join(' ')
|
|
71
|
+
assert(!titleMdx.startsWith(' '), { line, lineWords })
|
|
72
|
+
assert(titleMdx, { line, lineWords })
|
|
73
|
+
|
|
74
|
+
const id = determineSectionUrlHash(titleMdx)
|
|
75
|
+
const title = titleMdx
|
|
76
|
+
|
|
77
|
+
const headingHtml = `<h${headingLevel} id="${id}">${parseTitle(title)}</h${headingLevel}>`
|
|
78
|
+
|
|
79
|
+
const heading = { headingLevel, title, id, headingHtml }
|
|
80
|
+
return heading
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function parseTitle(titleMarkdown: string): string {
|
|
84
|
+
type Part = { nodeType: 'text' | 'code'; content: string }
|
|
85
|
+
const parts: Part[] = []
|
|
86
|
+
let current: Part | undefined
|
|
87
|
+
titleMarkdown.split('').forEach((letter) => {
|
|
88
|
+
if (letter === '`') {
|
|
89
|
+
if (current?.nodeType === 'code') {
|
|
90
|
+
// </code>
|
|
91
|
+
parts.push(current)
|
|
92
|
+
current = undefined
|
|
93
|
+
} else {
|
|
94
|
+
// <code>
|
|
95
|
+
if (current) {
|
|
96
|
+
parts.push(current)
|
|
97
|
+
}
|
|
98
|
+
current = { nodeType: 'code', content: '' }
|
|
99
|
+
}
|
|
100
|
+
} else {
|
|
101
|
+
if (!current) {
|
|
102
|
+
current = { nodeType: 'text', content: '' }
|
|
103
|
+
}
|
|
104
|
+
current.content += letter
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
if (current) {
|
|
108
|
+
parts.push(current)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const titleHtml = parts
|
|
112
|
+
.map((part) => {
|
|
113
|
+
if (part.nodeType === 'code') {
|
|
114
|
+
return `<code>${serializeText(part.content)}</code>`
|
|
115
|
+
} else {
|
|
116
|
+
assert(part.nodeType === 'text', { parts })
|
|
117
|
+
return serializeText(part.content)
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
.join('')
|
|
121
|
+
|
|
122
|
+
return titleHtml
|
|
123
|
+
|
|
124
|
+
function serializeText(text: string) {
|
|
125
|
+
const textEscaped = text.split("'").join("\\'")
|
|
126
|
+
return `{'${textEscaped}'}`
|
|
127
|
+
}
|
|
128
|
+
}
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import mdx from '@mdx-js/rollup'
|
|
2
|
+
import react from '@vitejs/plugin-react'
|
|
3
|
+
import ssr from 'vite-plugin-ssr/plugin'
|
|
4
|
+
import { UserConfig } from 'vite'
|
|
5
|
+
import { markdownHeadings } from './vite.config/markdownHeadings'
|
|
6
|
+
import rehypePrettyCode from 'rehype-pretty-code'
|
|
7
|
+
import remarkGfm from 'remark-gfm'
|
|
8
|
+
|
|
9
|
+
const root = process.cwd()
|
|
10
|
+
const prettyCode = [rehypePrettyCode, { theme: 'github-light' }]
|
|
11
|
+
const rehypePlugins: any = [prettyCode]
|
|
12
|
+
const remarkPlugins = [remarkGfm]
|
|
13
|
+
|
|
14
|
+
const config: UserConfig = {
|
|
15
|
+
root,
|
|
16
|
+
plugins: [
|
|
17
|
+
react({
|
|
18
|
+
jsxRuntime: 'classic'
|
|
19
|
+
}),
|
|
20
|
+
markdownHeadings(),
|
|
21
|
+
mdx({ rehypePlugins, remarkPlugins }),
|
|
22
|
+
ssr({
|
|
23
|
+
prerender: {
|
|
24
|
+
noExtraDir: true
|
|
25
|
+
},
|
|
26
|
+
pageFiles: {
|
|
27
|
+
include: ['docpress']
|
|
28
|
+
},
|
|
29
|
+
includeCSS: ['docpress'],
|
|
30
|
+
includeAssetsImportedByServer: true
|
|
31
|
+
})
|
|
32
|
+
],
|
|
33
|
+
// TODO: remove `react`?
|
|
34
|
+
optimizeDeps: { include: ['@mdx-js/react', 'react', 'react-dom'] },
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
ssr: {
|
|
37
|
+
noExternal: ['docpress']
|
|
38
|
+
},
|
|
39
|
+
clearScreen: false
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export default config
|