Merge branch 'master' into feature/2021-02-09_port-code-group-code-block_dp

pull/232/head
Derek Pollard 5 years ago committed by GitHub
commit 9f9f1f19b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

1
.gitignore vendored

@ -8,3 +8,4 @@ dist
node_modules
TODOs.md
.idea
.vscode

@ -1,3 +1,19 @@
## [0.12.2](https://github.com/vuejs/vitepress/compare/v0.12.1...v0.12.2) (2021-02-15)
### Bug Fixes
- **theme-default:** avoid ad image distortion on mobile ([4a40e1f](https://github.com/vuejs/vitepress/commit/4a40e1faf477c4e779b78f55ac1604eeb52b2499))
## [0.12.1](https://github.com/vuejs/vitepress/compare/v0.12.0...v0.12.1) (2021-02-15)
### Bug Fixes
- `@` alias for import code snippet being always `undefined` ([#204](https://github.com/vuejs/vitepress/issues/204)) ([2aa8ab2](https://github.com/vuejs/vitepress/commit/2aa8ab26e2fcf87ced27999c0be67798d5b4bb88))
- `base` option not generating correct multi sidebar ([#231](https://github.com/vuejs/vitepress/issues/231)) ([#234](https://github.com/vuejs/vitepress/issues/234)) ([a613df4](https://github.com/vuejs/vitepress/commit/a613df46e8cd7709dd2ad0f411ff52aa431850b6))
- ads display causing layout break in mobile view ([#230](https://github.com/vuejs/vitepress/issues/230)) ([7ceaf34](https://github.com/vuejs/vitepress/commit/7ceaf344d20f8a51c0452eed264e07b47d104043))
- home action link not being reactive ([#195](https://github.com/vuejs/vitepress/issues/195)) ([#212](https://github.com/vuejs/vitepress/issues/212)) ([5678dc3](https://github.com/vuejs/vitepress/commit/5678dc3a255c90309d5d7d9b609f3dc7ec7f9d00))
- nav home title not having locale based link ([#195](https://github.com/vuejs/vitepress/issues/195)) ([#233](https://github.com/vuejs/vitepress/issues/233)) ([6538c8e](https://github.com/vuejs/vitepress/commit/6538c8e70aac60823fd2374e36cb502420184b44))
# [0.12.0](https://github.com/vuejs/vitepress/compare/v0.11.5...v0.12.0) (2021-02-09)
### Bug Fixes

@ -1,6 +1,6 @@
{
"name": "vitepress",
"version": "0.12.0",
"version": "0.12.2",
"description": "Vite & Vue powered static site generator",
"main": "dist/node/index.js",
"typings": "types/index.d.ts",
@ -87,8 +87,7 @@
"polka": "^0.5.2",
"prismjs": "^1.23.0",
"sirv": "^1.0.11",
"slash": "^3.0.0",
"vite": "2.0.0-beta.50",
"vite": "^2.0.0-beta.70",
"vue": "^3.0.5"
},
"devDependencies": {
@ -113,7 +112,7 @@
"rollup": "^2.38.5",
"semver": "^7.3.2",
"ts-jest": "^26.5.1",
"typescript": "^4.1.3",
"typescript": "^4.1.4",
"yorkie": "^2.0.0"
}
}

@ -135,7 +135,9 @@ const showSidebar = computed(() => {
const { themeConfig } = siteRouteData.value
return !isSideBarEmpty(getSideBarConfig(themeConfig.sidebar, route.path))
return !isSideBarEmpty(
getSideBarConfig(themeConfig.sidebar, route.data.relativePath)
)
})
const toggleSidebar = (to?: boolean) => {

@ -59,7 +59,7 @@ onMounted(() => {
.carbon-ads :deep(.carbon-img) {
float: left;
margin-right: 0.75rem;
max-width: 100px;
max-width: 110px;
border: 1px solid var(--c-divider);
}
@ -75,6 +75,7 @@ onMounted(() => {
.carbon-ads :deep(.carbon-img img) {
display: block;
width: 100%;
height: auto;
}
@media (min-width: 420px) {

@ -1,8 +1,8 @@
<template>
<a
class="nav-bar-title"
:href="$site.base"
:aria-label="`${$site.title}, back to home`"
:href="$withBase($localePath)"
:aria-label="`${$siteByRoute.title}, back to home`"
>
<img
v-if="$themeConfig.logo"

@ -9,16 +9,18 @@
</template>
<script setup lang="ts">
import { defineProps } from 'vue'
import { defineProps, toRefs } from 'vue'
import type { DefaultTheme } from '../config'
import { useNavLink } from '../composables/navLink'
import OutboundLink from './icons/OutboundLink.vue'
const { item } = defineProps<{
const props = defineProps<{
item: DefaultTheme.NavItemWithLink
}>()
const { props: linkProps, isExternal } = useNavLink(item)
const propsRefs = toRefs(props)
const { props: linkProps, isExternal } = useNavLink(propsRefs.item)
</script>
<style scoped>

@ -7,16 +7,18 @@
</template>
<script setup lang="ts">
import { defineProps } from 'vue'
import { defineProps, toRefs } from 'vue'
import type { DefaultTheme } from '../config'
import { useNavLink } from '../composables/navLink'
import OutboundLink from './icons/OutboundLink.vue'
const { item } = defineProps<{
item: DefaultTheme.NavItemWithLink
const props = defineProps<{
item: DefaultTheme.NavItemWithLink,
}>()
const { props: linkProps, isExternal } = useNavLink(item)
const propsRefs = toRefs(props)
const { props: linkProps, isExternal } = useNavLink(propsRefs.item)
</script>
<style scoped>

@ -18,7 +18,7 @@ export const SideBarLink: FunctionalComponent<{
const text = props.item.text
const link = resolveLink(site.value.base, props.item.link)
const children = (props.item as DefaultTheme.SideBarGroup).children
const active = isActive(route, link)
const active = isActive(route, props.item.link)
const childItems = createChildren(active, children, headers)
return h('li', { class: 'sidebar-link' }, [

@ -1,23 +1,23 @@
import { computed } from 'vue'
import { computed, Ref } from 'vue'
import { useRoute } from 'vitepress'
import type { DefaultTheme } from '../config'
import { isExternal as isExternalCheck } from '../utils'
import { useUrl } from '../composables/url'
export function useNavLink(item: DefaultTheme.NavItemWithLink) {
export function useNavLink(item: Ref<DefaultTheme.NavItemWithLink>) {
const route = useRoute()
const { withBase } = useUrl()
const isExternal = isExternalCheck(item.link)
const isExternal = isExternalCheck(item.value.link)
const props = computed(() => {
const routePath = normalizePath(route.path)
const routePath = normalizePath(`/${route.data.relativePath}`)
let active = false
if (item.activeMatch) {
active = new RegExp(item.activeMatch).test(routePath)
if (item.value.activeMatch) {
active = new RegExp(item.value.activeMatch).test(routePath)
} else {
const itemPath = normalizePath(withBase(item.link))
const itemPath = normalizePath(withBase(item.value.link))
active =
itemPath === '/'
? itemPath === routePath
@ -29,10 +29,10 @@ export function useNavLink(item: DefaultTheme.NavItemWithLink) {
active,
isExternal
},
href: isExternal ? item.link : withBase(item.link),
target: item.target || isExternal ? `_blank` : null,
rel: item.rel || isExternal ? `noopener noreferrer` : null,
'aria-label': item.ariaLabel
href: isExternal ? item.value.link : withBase(item.value.link),
target: item.value.target || isExternal ? `_blank` : null,
rel: item.value.rel || isExternal ? `noopener noreferrer` : null,
'aria-label': item.value.ariaLabel
}
})

@ -30,7 +30,7 @@ export function useSideBar() {
// now, there's no sidebar setting at frontmatter; let's see the configs
const themeSidebar = getSideBarConfig(
site.value.themeConfig.sidebar,
route.path
route.data.relativePath
)
if (themeSidebar === false) {

@ -22,7 +22,7 @@ export function isActive(route: Route, path?: string): boolean {
return false
}
const routePath = normalize(route.path)
const routePath = normalize(`/${route.data.relativePath}`)
const pagePath = normalize(path)
return routePath === pagePath

@ -1,6 +1,6 @@
import ora from 'ora'
import path from 'path'
import slash from 'slash'
import { slash } from '../utils/slash'
import { APP_PATH } from '../alias'
import { SiteConfig } from '../config'
import { RollupOutput } from 'rollup'

@ -42,6 +42,7 @@ export interface MarkdownRenderer {
}
export const createMarkdownRenderer = (
root: string,
options: MarkdownOptions = {}
): MarkdownRenderer => {
const md = MarkdownIt({
@ -55,7 +56,7 @@ export const createMarkdownRenderer = (
md.use(componentPlugin)
.use(highlightLinePlugin)
.use(preWrapperPlugin)
.use(snippetPlugin)
.use(snippetPlugin, root)
.use(hoistPlugin)
.use(containerPlugin)
.use(extractHeaderPlugin)

@ -5,7 +5,8 @@ import LRUCache from 'lru-cache'
import { createMarkdownRenderer, MarkdownOptions } from './markdown/markdown'
import { deeplyParseHeader } from './utils/parseHeader'
import { PageData, HeadConfig } from '../../types/shared'
import slash from 'slash'
import { slash } from './utils/slash'
import chalk from 'chalk'
const debug = require('debug')('vitepress:md')
const cache = new LRUCache<string, MarkdownCompileResult>({ max: 1024 })
@ -13,13 +14,16 @@ const cache = new LRUCache<string, MarkdownCompileResult>({ max: 1024 })
interface MarkdownCompileResult {
vueSrc: string
pageData: PageData
deadLinks: string[]
}
export function createMarkdownToVueRenderFn(
root: string,
options: MarkdownOptions = {}
options: MarkdownOptions = {},
pages: string[]
) {
const md = createMarkdownRenderer(options)
const md = createMarkdownRenderer(root, options)
pages = pages.map((p) => slash(p.replace(/\.md$/, '')))
return (src: string, file: string): MarkdownCompileResult => {
const relativePath = slash(path.relative(root, file))
@ -40,7 +44,31 @@ export function createMarkdownToVueRenderFn(
.replace(/import\.meta/g, 'import.<wbr/>meta')
.replace(/process\.env/g, 'process.<wbr/>env')
// TODO validate data.links?
// validate data.links
const deadLinks = []
if (data.links) {
const dir = path.dirname(file)
for (let url of data.links) {
url = url.replace(/[?#].*$/, '').replace(/\.(html|md)$/, '')
if (url.endsWith('/')) url += `index`
const resolved = slash(
url.startsWith('/')
? url.slice(1)
: path.relative(root, path.resolve(dir, url))
)
if (!pages.includes(resolved)) {
console.warn(
chalk.yellow(
`\n(!) Found dead link ${chalk.cyan(
url
)} in file ${chalk.white.dim(file)}`
)
)
deadLinks.push(url)
}
}
}
const pageData: PageData = {
title: inferTitle(frontmatter, content),
description: inferDescription(frontmatter),
@ -59,7 +87,8 @@ export function createMarkdownToVueRenderFn(
const result = {
vueSrc,
pageData
pageData,
deadLinks
}
cache.set(src, result)
return result

@ -4,7 +4,7 @@ import { SiteConfig, resolveSiteData } from './config'
import { createMarkdownToVueRenderFn } from './markdownToVue'
import { APP_PATH, SITE_DATA_REQUEST_PATH } from './alias'
import createVuePlugin from '@vitejs/plugin-vue'
import slash from 'slash'
import { slash } from './utils/slash'
import { OutputAsset, OutputChunk } from 'rollup'
const hashRE = /\.(\w+)\.js$/
@ -24,11 +24,11 @@ const isPageChunk = (
export function createVitePressPlugin(
root: string,
{ configPath, alias, markdown, site, vueOptions }: SiteConfig,
{ configPath, alias, markdown, site, vueOptions, pages }: SiteConfig,
ssr = false,
pageToHashMap?: Record<string, string>
): Plugin[] {
const markdownToVue = createMarkdownToVueRenderFn(root, markdown)
const markdownToVue = createMarkdownToVueRenderFn(root, markdown, pages)
const vuePlugin = createVuePlugin({
include: [/\.vue$/, /\.md$/],
@ -36,13 +36,16 @@ export function createVitePressPlugin(
})
let siteData = site
let hasDeadLinks = false
const vitePressPlugin: Plugin = {
name: 'vitepress',
config() {
return {
alias,
resolve: {
alias
},
define: {
__CARBON__: !!site.themeConfig.carbonAds?.carbon,
__BSA__: !!site.themeConfig.carbonAds?.custom,
@ -69,7 +72,17 @@ export function createVitePressPlugin(
transform(code, id) {
if (id.endsWith('.md')) {
// transform .md files into vueSrc so plugin-vue can handle it
return markdownToVue(code, id).vueSrc
const { vueSrc, deadLinks } = markdownToVue(code, id)
if (deadLinks.length) {
hasDeadLinks = true
}
return vueSrc
}
},
renderStart() {
if (hasDeadLinks) {
throw new Error(`One or more pages contain dead links.`)
}
},

@ -0,0 +1,3 @@
export function slash(p: string): string {
return p.replace(/\\/g, '/')
}

@ -2586,11 +2586,6 @@ fsevents@^2.1.2:
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.2.1.tgz#1fb02ded2036a8ac288d507a65962bd87b97628d"
integrity sha512-bTLYHSeC0UH/EFXS9KqWnXuOl/wHK5Z/d+ghd5AsFMYN7wIGkUCOJyzy88+wJKkZPGON8u4Z9f6U4FdgURE9qA==
fsevents@~2.1.2:
version "2.1.3"
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.1.3.tgz#fb738703ae8d2f9fe900c33836ddebee8b97f23e"
integrity sha512-Auw9a4AxqWpa9GUfj370BMPzzyncfBABW8Mab7BGWBYDj4Isgq+cDKtx0i6u9jcX9pQDnswsaaOTgTmA5pEjuQ==
fsevents@~2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.1.tgz#b209ab14c61012636c8863507edf7fb68cc54e9f"
@ -5222,13 +5217,6 @@ rimraf@^3.0.0, rimraf@^3.0.2:
dependencies:
glob "^7.1.3"
rollup@^2.35.1:
version "2.35.1"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-2.35.1.tgz#e6bc8d10893556a638066f89e8c97f422d03968c"
integrity sha512-q5KxEyWpprAIcainhVy6HfRttD9kutQpHbeqDTWnqAFNJotiojetK6uqmcydNMymBEtC4I8bCYR+J3mTMqeaUA==
optionalDependencies:
fsevents "~2.1.2"
rollup@^2.38.5:
version "2.38.5"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-2.38.5.tgz#be41ad4fe0c103a8794377afceb5f22b8f603d6a"
@ -5996,10 +5984,10 @@ typedarray-to-buffer@^3.1.5:
dependencies:
is-typedarray "^1.0.0"
typescript@^4.1.3:
version "4.1.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.1.3.tgz#519d582bd94cba0cf8934c7d8e8467e473f53bb7"
integrity sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg==
typescript@^4.1.4:
version "4.1.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.1.4.tgz#f058636e2f4f83f94ddaae07b20fd5e14598432f"
integrity sha512-+Uru0t8qIRgjuCpiSPpfGuhHecMllk5Zsazj5LZvVsEStEjmIRRBZe+jHjGQvsgS7M1wONy2PQXd67EMyV6acg==
uc.micro@^1.0.1, uc.micro@^1.0.5:
version "1.0.6"
@ -6102,17 +6090,17 @@ verror@1.10.0:
core-util-is "1.0.2"
extsprintf "^1.2.0"
vite@2.0.0-beta.50:
version "2.0.0-beta.50"
resolved "https://registry.yarnpkg.com/vite/-/vite-2.0.0-beta.50.tgz#04e66d009470ca90ab8a4a43687e899b670a0f25"
integrity sha512-zzMgrWJK92/aQ1rxvc+0QKeOCdOP4m2EPGwK2HKhlifQVnSdpYQzQkWLzaGh1GQAp61W+Su8cu6cWINpFgNrfQ==
vite@^2.0.0-beta.70:
version "2.0.0"
resolved "https://registry.yarnpkg.com/vite/-/vite-2.0.0.tgz#156f35eadaa7947629aa8a24eb23129b07116ee3"
integrity sha512-rNli5g0DaQ6+btlRqkmaR06neWaJGApmt40gocqrYDNi2XoEXYQgKiHSWzMeUgc1Cdva2HduqazaE+RaKjBpdQ==
dependencies:
esbuild "^0.8.34"
postcss "^8.2.1"
resolve "^1.19.0"
rollup "^2.35.1"
rollup "^2.38.5"
optionalDependencies:
fsevents "~2.1.2"
fsevents "~2.3.1"
vue@^3.0.5:
version "3.0.5"

Loading…
Cancel
Save