Merge branch 'main' into feat/code-copy-button-label-i18n

pull/3854/head
Divyansh Singh 1 year ago committed by GitHub
commit cf507ae5c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -104,19 +104,20 @@
"dependencies": { "dependencies": {
"@docsearch/css": "^3.6.0", "@docsearch/css": "^3.6.0",
"@docsearch/js": "^3.6.0", "@docsearch/js": "^3.6.0",
"@shikijs/core": "^1.3.0", "@shikijs/core": "^1.4.0",
"@shikijs/transformers": "^1.3.0", "@shikijs/transformers": "^1.4.0",
"@types/markdown-it": "^14.0.1", "@types/markdown-it": "^14.1.1",
"@vitejs/plugin-vue": "^5.0.4", "@vitejs/plugin-vue": "^5.0.4",
"@vue/devtools-api": "^7.0.27", "@vue/devtools-api": "^7.0.27",
"@vue/shared": "^3.4.26",
"@vueuse/core": "^10.9.0", "@vueuse/core": "^10.9.0",
"@vueuse/integrations": "^10.9.0", "@vueuse/integrations": "^10.9.0",
"focus-trap": "^7.5.4", "focus-trap": "^7.5.4",
"mark.js": "8.11.1", "mark.js": "8.11.1",
"minisearch": "^6.3.0", "minisearch": "^6.3.0",
"shiki": "^1.3.0", "shiki": "^1.4.0",
"vite": "^5.2.10", "vite": "^5.2.11",
"vue": "^3.4.25" "vue": "^3.4.26"
}, },
"devDependencies": { "devDependencies": {
"@clack/prompts": "^0.7.0", "@clack/prompts": "^0.7.0",
@ -141,13 +142,12 @@
"@types/mark.js": "^8.11.12", "@types/mark.js": "^8.11.12",
"@types/markdown-it-attrs": "^4.1.3", "@types/markdown-it-attrs": "^4.1.3",
"@types/markdown-it-container": "^2.0.10", "@types/markdown-it-container": "^2.0.10",
"@types/markdown-it-emoji": "^2.0.5", "@types/markdown-it-emoji": "^3.0.1",
"@types/micromatch": "^4.0.7", "@types/micromatch": "^4.0.7",
"@types/minimist": "^1.2.5", "@types/minimist": "^1.2.5",
"@types/node": "^20.12.7", "@types/node": "^20.12.8",
"@types/postcss-prefix-selector": "^1.16.3", "@types/postcss-prefix-selector": "^1.16.3",
"@types/prompts": "^2.4.9", "@types/prompts": "^2.4.9",
"@vue/shared": "^3.4.25",
"chokidar": "^3.6.0", "chokidar": "^3.6.0",
"conventional-changelog-cli": "^4.1.0", "conventional-changelog-cli": "^4.1.0",
"cross-spawn": "^7.0.3", "cross-spawn": "^7.0.3",
@ -161,7 +161,7 @@
"gray-matter": "^4.0.3", "gray-matter": "^4.0.3",
"lint-staged": "^15.2.2", "lint-staged": "^15.2.2",
"lodash.template": "^4.5.0", "lodash.template": "^4.5.0",
"lru-cache": "^10.2.1", "lru-cache": "^10.2.2",
"markdown-it": "^14.1.0", "markdown-it": "^14.1.0",
"markdown-it-anchor": "^8.6.7", "markdown-it-anchor": "^8.6.7",
"markdown-it-attrs": "^4.1.6", "markdown-it-attrs": "^4.1.6",
@ -184,7 +184,7 @@
"prompts": "^2.4.2", "prompts": "^2.4.2",
"punycode": "^2.3.1", "punycode": "^2.3.1",
"rimraf": "^5.0.5", "rimraf": "^5.0.5",
"rollup": "^4.17.0", "rollup": "^4.17.2",
"rollup-plugin-dts": "^6.1.0", "rollup-plugin-dts": "^6.1.0",
"rollup-plugin-esbuild": "^6.1.1", "rollup-plugin-esbuild": "^6.1.1",
"semver": "^7.6.0", "semver": "^7.6.0",
@ -194,8 +194,8 @@
"sort-package-json": "^2.10.0", "sort-package-json": "^2.10.0",
"supports-color": "^9.4.0", "supports-color": "^9.4.0",
"typescript": "^5.4.5", "typescript": "^5.4.5",
"vitest": "^1.5.2", "vitest": "^1.5.3",
"vue-tsc": "^2.0.14", "vue-tsc": "2.0.14",
"wait-on": "^7.2.0" "wait-on": "^7.2.0"
}, },
"peerDependencies": { "peerDependencies": {
@ -223,8 +223,8 @@
"ora>string-width": "^5" "ora>string-width": "^5"
}, },
"patchedDependencies": { "patchedDependencies": {
"@types/markdown-it@14.0.1": "patches/@types__markdown-it@14.0.1.patch", "markdown-it-anchor@8.6.7": "patches/markdown-it-anchor@8.6.7.patch",
"markdown-it-anchor@8.6.7": "patches/markdown-it-anchor@8.6.7.patch" "rollup-plugin-dts@6.1.0": "patches/rollup-plugin-dts@6.1.0.patch"
} }
} }
} }

@ -1,13 +0,0 @@
diff --git a/package.json b/package.json
index 3b3cdfc4427a1a64fdd3b37604a7174e4646e423..afaea16b115554fcf15a905642562e881ece7ca6 100644
--- a/package.json
+++ b/package.json
@@ -27,7 +27,7 @@
}
],
"main": "",
- "types": "index.d.ts",
+ "types": "index.d.mts",
"exports": {
".": {
"import": "./index.d.mts",

@ -0,0 +1,13 @@
diff --git a/dist/rollup-plugin-dts.mjs b/dist/rollup-plugin-dts.mjs
index 4a9412285c48c37d03340a086c771f8e61fd82ac..c73cba3bf47550f69011366e37d2ae974f0c9fc0 100644
--- a/dist/rollup-plugin-dts.mjs
+++ b/dist/rollup-plugin-dts.mjs
@@ -675,6 +675,8 @@ function preProcess({ sourceFile }) {
const nextToken = children[idx + 1];
const isPunctuation = nextToken.kind >= ts.SyntaxKind.FirstPunctuation && nextToken.kind <= ts.SyntaxKind.LastPunctuation;
if (isPunctuation) {
+ const addSpace = code.slice(token.getEnd(), nextToken.getStart()) != " ";
+ code.appendLeft(nextToken.getStart(), `${addSpace ? " " : ""}${defaultExport}`);
code.appendLeft(nextToken.getStart(), defaultExport);
}
else {

File diff suppressed because it is too large Load Diff

@ -11,15 +11,15 @@ import replace from '@rollup/plugin-replace'
import alias from '@rollup/plugin-alias' import alias from '@rollup/plugin-alias'
import dts from 'rollup-plugin-dts' import dts from 'rollup-plugin-dts'
const ROOT = fileURLToPath(import.meta.url)
const r = (p: string) => resolve(ROOT, '..', p)
const require = createRequire(import.meta.url) const require = createRequire(import.meta.url)
const pkg = require('./package.json') const pkg = require(r('package.json'))
const DEV = !!process.env.DEV const DEV = !!process.env.DEV
const PROD = !DEV const PROD = !DEV
const ROOT = fileURLToPath(import.meta.url)
const r = (p: string) => resolve(ROOT, '..', p)
const external = [ const external = [
...Object.keys(pkg.dependencies), ...Object.keys(pkg.dependencies),
...Object.keys(pkg.peerDependencies), ...Object.keys(pkg.peerDependencies),
@ -29,11 +29,7 @@ const external = [
] ]
const plugins = [ const plugins = [
alias({ alias({ entries: { 'readable-stream': 'stream' } }),
entries: {
'readable-stream': 'stream'
}
}),
replace({ replace({
// polyfill broken browser check from bundled deps // polyfill broken browser check from bundled deps
'navigator.userAgentData': 'undefined', 'navigator.userAgentData': 'undefined',
@ -69,21 +65,34 @@ const typesExternal = [
'fast-glob' 'fast-glob'
] ]
const dtsNode = dts({
respectExternal: true,
tsconfig: r('src/node/tsconfig.json')
})
const originalResolveId = dtsNode.resolveId
dtsNode.resolveId = async function (source, importer) {
const res = await (originalResolveId as Function).call(this, source, importer)
if (res?.id) res.id = await fs.realpath(res.id)
return res
}
const nodeTypes: RollupOptions = { const nodeTypes: RollupOptions = {
input: r('src/node/index.ts'), input: r('src/node/index.ts'),
output: { output: {
format: 'esm', format: 'esm',
file: 'dist/node/index.d.ts' file: r('dist/node/index.d.ts')
}, },
external: typesExternal, external: typesExternal,
plugins: [dts({ respectExternal: true })] plugins: [dtsNode]
} }
const clientTypes: RollupOptions = { const clientTypes: RollupOptions = {
input: r('dist/client-types/index.d.ts'), input: r('dist/client-types/index.d.ts'),
output: { output: {
format: 'esm', format: 'esm',
file: 'dist/client/index.d.ts' file: r('dist/client/index.d.ts')
}, },
external: typesExternal, external: typesExternal,
plugins: [ plugins: [
@ -99,10 +108,4 @@ const clientTypes: RollupOptions = {
] ]
} }
const config = defineConfig([]) export default defineConfig([esmBuild, nodeTypes, clientTypes])
config.push(esmBuild)
config.push(nodeTypes)
config.push(clientTypes)
export default config

@ -156,7 +156,13 @@ export function createRouter(
latestPendingPath = null latestPendingPath = null
route.path = inBrowser ? pendingPath : withBase(pendingPath) route.path = inBrowser ? pendingPath : withBase(pendingPath)
route.component = fallbackComponent ? markRaw(fallbackComponent) : null route.component = fallbackComponent ? markRaw(fallbackComponent) : null
route.data = notFoundPageData const relativePath = inBrowser
? pendingPath
.replace(/(^|\/)$/, '$1index')
.replace(/(\.html)?$/, '.md')
.replace(/^\//, '')
: '404.md'
route.data = { ...notFoundPageData, relativePath }
} }
} }
} }

@ -1,55 +1,31 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed, onMounted, ref } from 'vue'
import { withBase } from 'vitepress' import { withBase } from 'vitepress'
import { useData } from './composables/data' import { useData } from './composables/data'
import { useLangs } from './composables/langs' import { useLangs } from './composables/langs'
const { site } = useData() const { theme } = useData()
const { localeLinks } = useLangs({ removeCurrent: false }) const { currentLang } = useLangs()
const locale = ref({
link: '/',
index: 'root'
})
onMounted(() => {
const path = window.location.pathname
.replace(site.value.base, '')
.replace(/(^.*?\/).*$/, '/$1')
if (localeLinks.value.length) {
locale.value =
localeLinks.value.find(({ link }) => link.startsWith(path)) ||
localeLinks.value[0]
}
})
const notFound = computed(() => ({
code: 404,
title: 'PAGE NOT FOUND',
quote:
"But if you don't change your direction, and if you keep looking, you may end up where you are heading.",
linkLabel: 'go to home',
linkText: 'Take me home',
...(locale.value.index === 'root'
? site.value.themeConfig?.notFound
: site.value.locales?.[locale.value.index]?.themeConfig?.notFound)
}))
</script> </script>
<template> <template>
<div class="NotFound"> <div class="NotFound">
<p class="code">{{ notFound.code }}</p> <p class="code">{{ theme.notFound?.code ?? '404' }}</p>
<h1 class="title">{{ notFound.title }}</h1> <h1 class="title">{{ theme.notFound?.title ?? 'PAGE NOT FOUND' }}</h1>
<div class="divider" /> <div class="divider" />
<blockquote class="quote">{{ notFound.quote }}</blockquote> <blockquote class="quote">
{{
theme.notFound?.quote ??
"But if you don't change your direction, and if you keep looking, you may end up where you are heading."
}}
</blockquote>
<div class="action"> <div class="action">
<a <a
class="link" class="link"
:href="withBase(locale.link)" :href="withBase(currentLang.link)"
:aria-label="notFound.linkLabel" :aria-label="theme.notFound?.linkLabel ?? 'go to home'"
> >
{{ notFound.linkText }} {{ theme.notFound?.linkText ?? 'Take me home' }}
</a> </a>
</div> </div>
</div> </div>

@ -2,13 +2,9 @@ import { computed } from 'vue'
import { ensureStartingSlash } from '../support/utils' import { ensureStartingSlash } from '../support/utils'
import { useData } from './data' import { useData } from './data'
export function useLangs({ export function useLangs({ correspondingLink = false } = {}) {
removeCurrent = true,
correspondingLink = false
} = {}) {
const { site, localeIndex, page, theme, hash } = useData() const { site, localeIndex, page, theme, hash } = useData()
const currentLang = computed(() => ({ const currentLang = computed(() => ({
index: localeIndex.value,
label: site.value.locales[localeIndex.value]?.label, label: site.value.locales[localeIndex.value]?.label,
link: link:
site.value.locales[localeIndex.value]?.link || site.value.locales[localeIndex.value]?.link ||
@ -17,10 +13,9 @@ export function useLangs({
const localeLinks = computed(() => const localeLinks = computed(() =>
Object.entries(site.value.locales).flatMap(([key, value]) => Object.entries(site.value.locales).flatMap(([key, value]) =>
removeCurrent && currentLang.value.label === value.label currentLang.value.label === value.label
? [] ? []
: { : {
index: key,
text: value.label, text: value.label,
link: link:
normalizeLink( normalizeLink(

@ -3,11 +3,8 @@
"compilerOptions": { "compilerOptions": {
"baseUrl": ".", "baseUrl": ".",
"outDir": "../../dist/client", "outDir": "../../dist/client",
"moduleResolution": "bundler",
"declaration": true, "declaration": true,
"declarationDir": "../../dist/client-types", "declarationDir": "../../dist/client-types",
"jsx": "preserve",
"lib": ["esnext", "dom", "dom.iterable"],
"types": ["vite/client"], "types": ["vite/client"],
"paths": { "paths": {
"vitepress": ["index.ts"], "vitepress": ["index.ts"],

@ -180,7 +180,7 @@ export async function renderPage(
${await renderHead(head)} ${await renderHead(head)}
</head> </head>
<body>${teleports?.body || ''} <body>${teleports?.body || ''}
<div id="app">${content}</div> <div id="app">${page === '404.md' ? '' : content}</div>
${metadataScript.inHead ? '' : metadataScript.html} ${metadataScript.inHead ? '' : metadataScript.html}
${inlinedScript} ${inlinedScript}
</body> </body>

@ -18,7 +18,6 @@ import type { Options } from 'markdown-it'
import MarkdownIt from 'markdown-it' import MarkdownIt from 'markdown-it'
import anchorPlugin from 'markdown-it-anchor' import anchorPlugin from 'markdown-it-anchor'
import attrsPlugin from 'markdown-it-attrs' import attrsPlugin from 'markdown-it-attrs'
// @ts-expect-error: types of markdown-it-emoji are not up-to-date
import { full as emojiPlugin } from 'markdown-it-emoji' import { full as emojiPlugin } from 'markdown-it-emoji'
import type { import type {
BuiltinTheme, BuiltinTheme,

@ -1,10 +1,8 @@
{ {
"extends": "../../tsconfig.json", "extends": "../../tsconfig.json",
"compilerOptions": { "compilerOptions": {
"target": "es2022",
"baseUrl": ".", "baseUrl": ".",
"outDir": "../../dist/node", "outDir": "../../dist/node",
"module": "esnext",
"types": ["node"], "types": ["node"],
"sourceMap": true "sourceMap": true
}, },

@ -24,7 +24,7 @@ const INDEX_OR_EXT_RE = /(?:(^|\/)index)?\.(?:md|html)$/
export const inBrowser = typeof document !== 'undefined' export const inBrowser = typeof document !== 'undefined'
export const notFoundPageData: PageData = { export const notFoundPageData: PageData = {
relativePath: '', relativePath: '404.md',
filePath: '', filePath: '',
title: '404', title: '404',
description: 'Not Found', description: 'Not Found',

@ -2,7 +2,7 @@
"compilerOptions": { "compilerOptions": {
"module": "esnext", "module": "esnext",
"target": "esnext", "target": "esnext",
"moduleResolution": "node", "moduleResolution": "bundler",
"esModuleInterop": true, "esModuleInterop": true,
"strict": true, "strict": true,
"skipLibCheck": true, "skipLibCheck": true,

6
types/shared.d.ts vendored

@ -7,7 +7,11 @@ export type Awaitable<T> = T | PromiseLike<T>
export interface PageData { export interface PageData {
relativePath: string relativePath: string
filePath: string // differs from relativePath in case of path rewrites /**
* differs from relativePath in case of path rewrites
* empty string if the page is virtual (e.g. 404 page)
*/
filePath: string
title: string title: string
titleTemplate?: string | boolean titleTemplate?: string | boolean
description: string description: string

Loading…
Cancel
Save