Merge branch 'main' into chore/vite-3

pull/1136/head
Divyansh Singh 3 years ago committed by GitHub
commit 4e5d2c4f7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -55,6 +55,7 @@ Set up a new project and change these settings using your dashboard:
- **Build Command:** `yarn docs:build` - **Build Command:** `yarn docs:build`
- **Output Directory:** `docs/.vitepress/dist` - **Output Directory:** `docs/.vitepress/dist`
- **Node Version:** `14` (or above, by default it usually will be 14 or 16, but on Cloudflare Pages the default is still 12, so you may need to [change that](https://developers.cloudflare.com/pages/platform/build-configuration/))
::: warning ::: warning
Don't enable options like _Auto Minify_ for HTML code. It will remove comments from output which have meaning to Vue. You may see hydration mismatch errors if they get removed. Don't enable options like _Auto Minify_ for HTML code. It will remove comments from output which have meaning to Vue. You may see hydration mismatch errors if they get removed.

@ -388,6 +388,48 @@ You can also use a [VS Code region](https://code.visualstudio.com/docs/editor/co
<!--lint enable strong-marker--> <!--lint enable strong-marker-->
## Markdown File Inclusion
You can include a markdown file in another markdown file like this:
**Input**
```md
# Docs
## Basics
<!--@include: ./parts/basics.md-->
```
**Part file** (`parts/basics.md`)
```md
Some getting started stuff.
### Configuration
Can be created using `.foorc.json`.
```
**Equivalent code**
```md
# Docs
## Basics
Some getting started stuff.
### Configuration
Can be created using `.foorc.json`.
```
::: warning
Note that this does not throw errors if your file is not present. Hence, when using this feature make sure that the contents are being rendered as expected.
:::
## Advanced Configuration ## Advanced Configuration
VitePress uses [markdown-it](https://github.com/markdown-it/markdown-it) as the Markdown renderer. A lot of the extensions above are implemented via custom plugins. You can further customize the `markdown-it` instance using the `markdown` option in `.vitepress/config.js`: VitePress uses [markdown-it](https://github.com/markdown-it/markdown-it) as the Markdown renderer. A lot of the extensions above are implemented via custom plugins. You can further customize the `markdown-it` instance using the `markdown` option in `.vitepress/config.js`:

@ -207,3 +207,12 @@ Full list of slots available in the default theme layout:
- `home-hero-after` - `home-hero-after`
- `home-features-before` - `home-features-before`
- `home-features-after` - `home-features-after`
- Always:
- `layout-top`
- `layout-bottom`
- `nav-bar-title-before`
- `nav-bar-title-after`
- `nav-bar-content-before`
- `nav-bar-content-after`
- `nav-screen-content-before`
- `nav-screen-content-after`

@ -114,7 +114,7 @@ export default {
### Customize link's "active" state ### Customize link's "active" state
Nav menu items will be highlighted when the current page is under the matching path. if you would like to customize the path to be mathced, define `activeMatch` property and regex as a string value. Nav menu items will be highlighted when the current page is under the matching path. if you would like to customize the path to be matched, define `activeMatch` property and regex as a string value.
```js ```js
export default { export default {

@ -60,9 +60,9 @@ The above will display a team member in card looking element. It should display
<VPTeamMembers size="small" :members="members" /> <VPTeamMembers size="small" :members="members" />
`<VPTeamMembers>` component comes in 2 different sizes, `small` and `medium`. While it boiles down to your preference, usually `small` size should fit better when used in doc page. Also, you may add more properties to each member such as adding "description" or "sponsor" button. Learn more about it in [`<VPTeamMembers>`](#vpteammembers). `<VPTeamMembers>` component comes in 2 different sizes, `small` and `medium`. While it boils down to your preference, usually `small` size should fit better when used in doc page. Also, you may add more properties to each member such as adding "description" or "sponsor" button. Learn more about it in [`<VPTeamMembers>`](#vpteammembers).
Embbeding team members in doc page is good for small size team where having dedicated full team page might be too much, or introducing partial members as a refference to documenation context. Embbeding team members in doc page is good for small size team where having dedicated full team page might be too much, or introducing partial members as a reference to documentation context.
If you have large number of members, or simply would like to have more space to show team members, consider [creating a full team page](#create-a-full-team-page). If you have large number of members, or simply would like to have more space to show team members, consider [creating a full team page](#create-a-full-team-page).
@ -217,7 +217,7 @@ interface TeamMember {
## `<VPTeamPage>` ## `<VPTeamPage>`
The root component when creating a full team page. It only accepts a single slot. It's will style all passed in team related components. The root component when creating a full team page. It only accepts a single slot. It will style all passed in team related components.
## `<VPTeamPageTitle>` ## `<VPTeamPageTitle>`

@ -29,7 +29,14 @@ provide('close-sidebar', closeSidebar)
<slot name="layout-top" /> <slot name="layout-top" />
<VPSkipLink /> <VPSkipLink />
<VPBackdrop class="backdrop" :show="isSidebarOpen" @click="closeSidebar" /> <VPBackdrop class="backdrop" :show="isSidebarOpen" @click="closeSidebar" />
<VPNav /> <VPNav>
<template #nav-bar-title-before><slot name="nav-bar-title-before" /></template>
<template #nav-bar-title-after><slot name="nav-bar-title-after" /></template>
<template #nav-bar-content-before><slot name="nav-bar-content-before" /></template>
<template #nav-bar-content-after><slot name="nav-bar-content-after" /></template>
<template #nav-screen-content-before><slot name="nav-screen-content-before" /></template>
<template #nav-screen-content-after><slot name="nav-screen-content-after" /></template>
</VPNav>
<VPLocalNav :open="isSidebarOpen" @open-menu="openSidebar" /> <VPLocalNav :open="isSidebarOpen" @open-menu="openSidebar" />
<VPSidebar :open="isSidebarOpen" /> <VPSidebar :open="isSidebarOpen" />

@ -1,6 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed } from 'vue' import { computed } from 'vue'
import { normalizeLink } from '../support/utils' import { normalizeLink } from '../support/utils'
import { EXTERNAL_URL_RE } from '../../shared'
const props = defineProps<{ const props = defineProps<{
tag?: string tag?: string
@ -15,7 +16,7 @@ const classes = computed(() => [
props.theme ?? 'brand' props.theme ?? 'brand'
]) ])
const isExternal = computed(() => props.href && /^[a-z]+:/i.test(props.href)) const isExternal = computed(() => props.href && EXTERNAL_URL_RE.test(props.href))
const component = computed(() => { const component = computed(() => {
if (props.tag) { if (props.tag) {

@ -2,13 +2,14 @@
import { computed } from 'vue' import { computed } from 'vue'
import { normalizeLink } from '../support/utils' import { normalizeLink } from '../support/utils'
import VPIconExternalLink from './icons/VPIconExternalLink.vue' import VPIconExternalLink from './icons/VPIconExternalLink.vue'
import { EXTERNAL_URL_RE } from '../../shared'
const props = defineProps<{ const props = defineProps<{
href?: string href?: string
noIcon?: boolean noIcon?: boolean
}>() }>()
const isExternal = computed(() => props.href && /^[a-z]+:/i.test(props.href)) const isExternal = computed(() => props.href && EXTERNAL_URL_RE.test(props.href))
</script> </script>
<template> <template>

@ -13,8 +13,16 @@ provide('close-screen', closeScreen)
<template> <template>
<header class="VPNav" :class="{ 'no-sidebar' : !hasSidebar }"> <header class="VPNav" :class="{ 'no-sidebar' : !hasSidebar }">
<VPNavBar :is-screen-open="isScreenOpen" @toggle-screen="toggleScreen" /> <VPNavBar :is-screen-open="isScreenOpen" @toggle-screen="toggleScreen">
<VPNavScreen :open="isScreenOpen" /> <template #nav-bar-title-before><slot name="nav-bar-title-before" /></template>
<template #nav-bar-title-after><slot name="nav-bar-title-after" /></template>
<template #nav-bar-content-before><slot name="nav-bar-content-before" /></template>
<template #nav-bar-content-after><slot name="nav-bar-content-after" /></template>
</VPNavBar>
<VPNavScreen :open="isScreenOpen">
<template #nav-screen-content-before><slot name="nav-screen-content-before" /></template>
<template #nav-screen-content-after><slot name="nav-screen-content-after" /></template>
</VPNavScreen>
</header> </header>
</template> </template>

@ -23,15 +23,20 @@ const { hasSidebar } = useSidebar()
<template> <template>
<div class="VPNavBar" :class="{ 'has-sidebar' : hasSidebar }"> <div class="VPNavBar" :class="{ 'has-sidebar' : hasSidebar }">
<div class="container"> <div class="container">
<VPNavBarTitle /> <VPNavBarTitle>
<template #nav-bar-title-before><slot name="nav-bar-title-before" /></template>
<template #nav-bar-title-after><slot name="nav-bar-title-after" /></template>
</VPNavBarTitle>
<div class="content"> <div class="content">
<slot name="nav-bar-content-before" />
<VPNavBarSearch class="search" /> <VPNavBarSearch class="search" />
<VPNavBarMenu class="menu" /> <VPNavBarMenu class="menu" />
<VPNavBarTranslations class="translations" /> <VPNavBarTranslations class="translations" />
<VPNavBarAppearance class="appearance" /> <VPNavBarAppearance class="appearance" />
<VPNavBarSocialLinks class="social-links" /> <VPNavBarSocialLinks class="social-links" />
<VPNavBarExtra class="extra" /> <VPNavBarExtra class="extra" />
<slot name="nav-bar-content-after" />
<VPNavBarHamburger <VPNavBarHamburger
class="hamburger" class="hamburger"
:active="isScreenOpen" :active="isScreenOpen"

@ -10,9 +10,11 @@ const { hasSidebar } = useSidebar()
<template> <template>
<div class="VPNavBarTitle" :class="{ 'has-sidebar': hasSidebar }"> <div class="VPNavBarTitle" :class="{ 'has-sidebar': hasSidebar }">
<a class="title" :href="site.base"> <a class="title" :href="site.base">
<slot name="nav-bar-title-before" />
<VPImage class="logo" :image="theme.logo" /> <VPImage class="logo" :image="theme.logo" />
<template v-if="theme.siteTitle">{{ theme.siteTitle }}</template> <template v-if="theme.siteTitle">{{ theme.siteTitle }}</template>
<template v-else-if="theme.siteTitle === undefined">{{ site.title }}</template> <template v-else-if="theme.siteTitle === undefined">{{ site.title }}</template>
<slot name="nav-bar-title-after" />
</a> </a>
</div> </div>
</template> </template>

@ -29,10 +29,12 @@ function unlockBodyScroll() {
> >
<div v-if="open" class="VPNavScreen" ref="screen"> <div v-if="open" class="VPNavScreen" ref="screen">
<div class="container"> <div class="container">
<slot name="nav-screen-content-before" />
<VPNavScreenMenu class="menu" /> <VPNavScreenMenu class="menu" />
<VPNavScreenTranslations class="translations" /> <VPNavScreenTranslations class="translations" />
<VPNavScreenAppearance class="appearance" /> <VPNavScreenAppearance class="appearance" />
<VPNavScreenSocialLinks class="social-links" /> <VPNavScreenSocialLinks class="social-links" />
<slot name="nav-screen-content-after" />
</div> </div>
</div> </div>
</transition> </transition>

@ -1,15 +1,15 @@
import { ref } from 'vue' import { ref } from 'vue'
import { withBase, useData } from 'vitepress' import { withBase, useData } from 'vitepress'
import { EXTERNAL_URL_RE } from '../../shared'
export const HASH_RE = /#.*$/ export const HASH_RE = /#.*$/
export const EXT_RE = /(index)?\.(md|html)$/ export const EXT_RE = /(index)?\.(md|html)$/
export const OUTBOUND_RE = /^[a-z]+:/i
const inBrowser = typeof window !== 'undefined' const inBrowser = typeof window !== 'undefined'
const hashRef = ref(inBrowser ? location.hash : '') const hashRef = ref(inBrowser ? location.hash : '')
export function isExternal(path: string): boolean { export function isExternal(path: string): boolean {
return OUTBOUND_RE.test(path) return EXTERNAL_URL_RE.test(path)
} }
export function throttleAndDebounce(fn: () => void, delay: number): () => void { export function throttleAndDebounce(fn: () => void, delay: number): () => void {

@ -7,9 +7,10 @@ export const imagePlugin = (md: MarkdownIt) => {
const imageRule = md.renderer.rules.image! const imageRule = md.renderer.rules.image!
md.renderer.rules.image = (tokens, idx, options, env, self) => { md.renderer.rules.image = (tokens, idx, options, env, self) => {
const token = tokens[idx] const token = tokens[idx]
const url = token.attrGet('src') let url = token.attrGet('src')
if (url && !EXTERNAL_URL_RE.test(url) && !/^\.?\//.test(url)) { if (url && !EXTERNAL_URL_RE.test(url)) {
token.attrSet('src', './' + url) if (!/^\.?\//.test(url)) url = './' + url
token.attrSet('src', decodeURIComponent(url))
} }
return imageRule(tokens, idx, options, env, self) return imageRule(tokens, idx, options, env, self)
} }

@ -55,11 +55,15 @@ export async function createMarkdownToVueRenderFn(
// resolve includes // resolve includes
let includes: string[] = [] let includes: string[] = []
src = src.replace(includesRE, (_, m1) => { src = src.replace(includesRE, (m, m1) => {
try {
const includePath = path.join(dir, m1) const includePath = path.join(dir, m1)
const content = fs.readFileSync(includePath, 'utf-8') const content = fs.readFileSync(includePath, 'utf-8')
includes.push(slash(includePath)) includes.push(slash(includePath))
return content return content
} catch (error) {
return m // silently ignore error if file is not present
}
}) })
const { content, data: frontmatter } = matter(src) const { content, data: frontmatter } = matter(src)

@ -11,7 +11,7 @@ export type {
CleanUrlsMode CleanUrlsMode
} from '../../types/shared' } from '../../types/shared'
export const EXTERNAL_URL_RE = /^https?:/i export const EXTERNAL_URL_RE = /^[a-z]+:/i
export const APPEARANCE_KEY = 'vitepress-theme-appearance' export const APPEARANCE_KEY = 'vitepress-theme-appearance'
export const inBrowser = typeof window !== 'undefined' export const inBrowser = typeof window !== 'undefined'

Loading…
Cancel
Save