pull/1593/head
Xavi Lee 4 years ago
commit 66c93c9b41

@ -1,3 +1,24 @@
# [1.0.0-alpha.49](https://github.com/vuejs/vitepress/compare/v1.0.0-alpha.48...v1.0.0-alpha.49) (2023-02-28)
### Bug Fixes
* disable fuzzy link recognition by default ([2450710](https://github.com/vuejs/vitepress/commit/24507105b18362210632543b8a72893832b5940a))
* dyamic routes w/ srcDir + relative imports ([b075ee5](https://github.com/vuejs/vitepress/commit/b075ee5be6785e671b19ded066c22a1d506ec508))
* hmr on deps change of data loaders ([5913ebc](https://github.com/vuejs/vitepress/commit/5913ebc34f810e84b4ad482aa835e1a4e8beb404))
* normalize all paths in config ([8e8fcd9](https://github.com/vuejs/vitepress/commit/8e8fcd9caa4194787c5fc81ad10d17cf82638b8f))
* **theme:** "copy code" button not readable on hover state ([#819](https://github.com/vuejs/vitepress/issues/819)) ([#1892](https://github.com/vuejs/vitepress/issues/1892)) ([#1998](https://github.com/vuejs/vitepress/issues/1998)) ([c2de4ca](https://github.com/vuejs/vitepress/commit/c2de4caa345bdeda5252a8fc00cfcdbcc18d5d2d))
* **theme:** tip custom container has wrong bg color for `<code>` block ([d9a2e6e](https://github.com/vuejs/vitepress/commit/d9a2e6e8978f614d70f347be81b9b3b9df03d7a1))
* update route configs on file add / delete ([bccce98](https://github.com/vuejs/vitepress/commit/bccce98c62d1ea405c55a6f72bab6f2ce27e2e65))
### Features
* dynamic routes ([24fa862](https://github.com/vuejs/vitepress/commit/24fa862c39d1b5c2ea6da6faf08cfe95e07f5d2f))
* **theme:** enhance readability of custom containers ([#1824](https://github.com/vuejs/vitepress/issues/1824)) ([#1989](https://github.com/vuejs/vitepress/issues/1989)) ([472b6ec](https://github.com/vuejs/vitepress/commit/472b6ecf5e404bccc751bcf93b868ac30f43f22b))
# [1.0.0-alpha.48](https://github.com/vuejs/vitepress/compare/v1.0.0-alpha.47...v1.0.0-alpha.48) (2023-02-26)

@ -38,6 +38,19 @@ const sidebar: DefaultTheme.Config['sidebar'] = {
link: '/multi-sidebar/'
}
]
},
{
text: 'Dynamic Routes',
items: [
{
text: 'Foo',
link: '/dynamic-routes/foo'
},
{
text: 'Bar',
link: '/dynamic-routes/bar'
}
]
}
],
'/multi-sidebar/': [

@ -0,0 +1,8 @@
<script setup>
import { useData } from 'vitepress'
const { page } = useData()
</script>
<!-- @content -->
<pre class="params">{{ page.params }}</pre>

@ -0,0 +1,8 @@
export default {
async paths() {
return [
{ params: { id: 'foo' }, content: `# Foo` },
{ params: { id: 'bar' }, content: `# Bar` }
]
}
}

@ -0,0 +1,11 @@
describe('dynamic routes', () => {
test('render correct content', async () => {
await goto('/dynamic-routes/foo')
expect(await page.textContent('h1')).toMatch('Foo')
expect(await page.textContent('pre.params')).toMatch('"id": "foo"')
await goto('/dynamic-routes/bar')
expect(await page.textContent('h1')).toMatch('Bar')
expect(await page.textContent('pre.params')).toMatch('"id": "bar"')
})
})

@ -13,7 +13,8 @@ describe('test multi sidebar sort root', () => {
'Frontmatter',
'& <Text Literals &> code',
'Static Data',
'Multi Sidebar Test'
'Multi Sidebar Test',
'Dynamic Routes'
])
})
})

@ -22,6 +22,6 @@ export default {
In the above example, the site will have the title of `VitePress`, and `Just playing around.` as the description meta tag.
Learn everything about VitePress features at [Theme: Introduction](./theme-introduction) to find how to configure specific features within this config file.
Learn everything about VitePress features at [Theme: Introduction](./customization-intro) to find how to configure specific features within this config file.
You may also find all configuration references at [Config Reference](../config/introduction).

@ -136,6 +136,6 @@ To enable those navigations, we must add some configurations to the site. Head t
If you would like to know more about what you can do within the page, for example, writing markdown contents, or using Vue Component, check out the "Writing" section of the docs. [Markdown guide](./markdown) would be a great starting point.
If you want to know how to customize how the site looks (Theme), and find out the features VitePress's default theme provides, visit [Theme: Introduction](./theme-introduction).
If you want to know how to customize how the site looks (Theme), and find out the features VitePress's default theme provides, visit [Theme: Introduction](./customization-intro).
When your documentation site starts to take shape, be sure to read the [deployment guide](./deploying).

@ -75,7 +75,7 @@ However, VitePress won't redirect `/` to `/en/` by default. You'll need to confi
/* /en/:splat 302
```
**Pro tip:** If using the above approach, you can use `nf_lang` cookie to persist user's language choice. A very basic way to do this is register a watcher inside the [setup](./theme-introduction#using-a-custom-theme) function of custom theme:
**Pro tip:** If using the above approach, you can use `nf_lang` cookie to persist user's language choice. A very basic way to do this is register a watcher inside the [setup](./customization-intro#using-a-custom-theme) function of custom theme:
```ts
// docs/.vitepress/theme/index.ts

@ -1,6 +1,6 @@
{
"name": "vitepress",
"version": "1.0.0-alpha.48",
"version": "1.0.0-alpha.49",
"description": "Vite & Vue powered static site generator",
"type": "module",
"packageManager": "pnpm@7.28.0",

@ -55,6 +55,7 @@ provide('hero-image-slot-exists', heroImageSlotExists)
<VPContent>
<template #home-hero-before><slot name="home-hero-before" /></template>
<template #home-hero-info><slot name="home-hero-info" /></template>
<template #home-hero-image><slot name="home-hero-image" /></template>
<template #home-hero-after><slot name="home-hero-after" /></template>
<template #home-features-before><slot name="home-features-before" /></template>

@ -29,6 +29,7 @@ const NotFound = inject('NotFound')
<VPHome v-else-if="frontmatter.layout === 'home'">
<template #home-hero-before><slot name="home-hero-before" /></template>
<template #home-hero-info><slot name="home-hero-info" /></template>
<template #home-hero-image><slot name="home-hero-image" /></template>
<template #home-hero-after><slot name="home-hero-after" /></template>
<template #home-features-before><slot name="home-features-before" /></template>

@ -25,11 +25,13 @@ const heroImageSlotExists = inject('hero-image-slot-exists') as Ref<boolean>
<div class="VPHero" :class="{ 'has-image': image || heroImageSlotExists }">
<div class="container">
<div class="main">
<h1 v-if="name" class="name">
<span class="clip">{{ name }}</span>
</h1>
<p v-if="text" class="text">{{ text }}</p>
<p v-if="tagline" class="tagline">{{ tagline }}</p>
<slot name="home-hero-info">
<h1 v-if="name" class="name">
<span class="clip">{{ name }}</span>
</h1>
<p v-if="text" class="text">{{ text }}</p>
<p v-if="tagline" class="tagline">{{ tagline }}</p>
</slot>
<div v-if="actions" class="actions">
<div v-for="action in actions" :key="action.link" class="action">

@ -7,6 +7,7 @@ import VPHomeFeatures from './VPHomeFeatures.vue'
<div class="VPHome">
<slot name="home-hero-before" />
<VPHomeHero>
<template #home-hero-info><slot name="home-hero-info" /></template>
<template #home-hero-image><slot name="home-hero-image" /></template>
</VPHomeHero>
<slot name="home-hero-after" />

@ -15,6 +15,7 @@ const { frontmatter: fm } = useData()
:image="fm.hero.image"
:actions="fm.hero.actions"
>
<template #home-hero-info><slot name="home-hero-info" /></template>
<template #home-hero-image><slot name="home-hero-image" /></template>
</VPHero>
</template>

@ -41,6 +41,7 @@ defineProps<{
font-size: 14px;
font-weight: 600;
color: var(--vp-c-text-2);
white-space: nowrap;
transition: color 0.25s;
}
</style>

@ -219,6 +219,9 @@ export async function resolveConfig(
command: 'serve' | 'build' = 'serve',
mode = 'development'
): Promise<SiteConfig> {
// normalize root into absolute path
root = normalizePath(path.resolve(root))
const [userConfig, configPath, configDeps] = await resolveUserConfig(
root,
command,
@ -232,12 +235,12 @@ export async function resolveConfig(
allowClearScreen: userConfig.vite?.clearScreen
})
const site = await resolveSiteData(root, userConfig)
const srcDir = path.resolve(root, userConfig.srcDir || '.')
const srcDir = normalizePath(path.resolve(root, userConfig.srcDir || '.'))
const outDir = userConfig.outDir
? path.resolve(root, userConfig.outDir)
? normalizePath(path.resolve(root, userConfig.outDir))
: resolve(root, 'dist')
const cacheDir = userConfig.cacheDir
? path.resolve(root, userConfig.cacheDir)
? normalizePath(path.resolve(root, userConfig.cacheDir))
: resolve(root, 'cache')
// resolve theme path

@ -57,7 +57,7 @@ export const dynamicRoutesPlugin = async (
resolveId(id) {
if (!id.endsWith('.md')) return
const normalizedId = id.startsWith(config.root)
const normalizedId = id.startsWith(config.srcDir)
? id
: normalizePath(path.resolve(config.srcDir, id.replace(/^\//, '')))
const matched = config.dynamicRoutes.routes.find(
@ -129,7 +129,7 @@ export async function resolveDynamicRoutes(
if (!fs.existsSync(pathsFile)) {
console.warn(
c.yellow(
`missing paths file for dynamic route ${route}: ` +
`Missing paths file for dynamic route ${route}: ` +
`a corresponding ${jsPathsFile} or ${pathsFile} is needed.`
)
)
@ -144,7 +144,12 @@ export async function resolveDynamicRoutes(
mod = (await loadConfigFromFile({} as any, pathsFile)) as RouteModule
routeModuleCache.set(pathsFile, mod)
} catch (e) {
console.warn(`invalid paths file export in ${pathsFile}.`)
console.warn(
c.yellow(
`Invalid paths file export in ${pathsFile}. ` +
`Expects default export of an object with a "paths" property.`
)
)
continue
}
}
@ -161,8 +166,18 @@ export async function resolveDynamicRoutes(
routeFileToModulesMap[normalizePath(path.resolve(dep))] = matchedModuleIds
}
const loader = mod!.config.paths
if (!loader) {
console.warn(
c.yellow(
`Invalid paths file export in ${pathsFile}. ` +
`Missing "paths" property from default export.`
)
)
continue
}
const resolveRoute = async (): Promise<ResolvedRouteConfig[]> => {
const loader = mod!.config.paths
const paths = await (typeof loader === 'function' ? loader() : loader)
return paths.map((userConfig) => {
const resolvedPath = route.replace(

Loading…
Cancel
Save