From ffe0c40ebc42d7769b5378775cdffcab52d3cf11 Mon Sep 17 00:00:00 2001 From: Guanghui Cheng Date: Tue, 22 Feb 2022 10:04:26 +0800 Subject: [PATCH 01/12] fix(client router): tolerant invalid hash selector typo (#506) --- src/client/app/router.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/app/router.ts b/src/client/app/router.ts index 49f191a08ddd..f7c2a3973af3 100644 --- a/src/client/app/router.ts +++ b/src/client/app/router.ts @@ -198,7 +198,7 @@ function scrollTo(el: HTMLElement, hash: string, smooth = false) { let target: Element | null = null try { - target = el.classList.contains('.header-anchor') + target = el.classList.contains('header-anchor') ? el : document.querySelector(decodeURIComponent(hash)) } catch (e) { From 804954cf4d5417b1abcba9854ed5f064348292c5 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Tue, 22 Feb 2022 07:52:13 +0530 Subject: [PATCH 02/12] fix: append base to links (#502) fix #252 --- src/node/markdown/markdown.ts | 17 +++++++++++------ src/node/markdown/plugins/link.ts | 8 +++++++- src/node/markdownToVue.ts | 3 ++- src/node/plugin.ts | 1 + 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/node/markdown/markdown.ts b/src/node/markdown/markdown.ts index 1fdb926814ae..c9d68b9ec862 100644 --- a/src/node/markdown/markdown.ts +++ b/src/node/markdown/markdown.ts @@ -49,7 +49,8 @@ export type { Header } export const createMarkdownRenderer = ( srcDir: string, - options: MarkdownOptions = {} + options: MarkdownOptions = {}, + base: string ): MarkdownRenderer => { const md = MarkdownIt({ html: true, @@ -66,11 +67,15 @@ export const createMarkdownRenderer = ( .use(hoistPlugin) .use(containerPlugin) .use(headingPlugin) - .use(linkPlugin, { - target: '_blank', - rel: 'noopener noreferrer', - ...options.externalLinks - }) + .use( + linkPlugin, + { + target: '_blank', + rel: 'noopener noreferrer', + ...options.externalLinks + }, + base + ) // 3rd party plugins .use(attrs, options.attrs) .use(anchor, { diff --git a/src/node/markdown/plugins/link.ts b/src/node/markdown/plugins/link.ts index e44c043a14d6..d1448bc803e5 100644 --- a/src/node/markdown/plugins/link.ts +++ b/src/node/markdown/plugins/link.ts @@ -11,7 +11,8 @@ const indexRE = /(^|.*\/)index.md(#?.*)$/i export const linkPlugin = ( md: MarkdownIt, - externalAttrs: Record + externalAttrs: Record, + base: string ) => { md.renderer.rules.link_open = (tokens, idx, options, env, self) => { const token = tokens[idx] @@ -76,6 +77,11 @@ export const linkPlugin = ( // export it for existence check pushLink(url.replace(/\.html$/, '')) + // append base to internal (non-relative) urls + if (url.startsWith('/')) { + url = `${base}${url}`.replace(/\/+/g, '/') + } + // markdown-it encodes the uri hrefAttr[1] = decodeURI(url) } diff --git a/src/node/markdownToVue.ts b/src/node/markdownToVue.ts index 436192f0a518..29db746129ad 100644 --- a/src/node/markdownToVue.ts +++ b/src/node/markdownToVue.ts @@ -27,9 +27,10 @@ export function createMarkdownToVueRenderFn( pages: string[], userDefines: Record | undefined, isBuild = false, + base: string, includeLastUpdatedData = false ) { - const md = createMarkdownRenderer(srcDir, options) + const md = createMarkdownRenderer(srcDir, options, base) pages = pages.map((p) => slash(p.replace(/\.md$/, ''))) const userDefineRegex = userDefines diff --git a/src/node/plugin.ts b/src/node/plugin.ts index ee70ecc53b8d..7f6e6f33c311 100644 --- a/src/node/plugin.ts +++ b/src/node/plugin.ts @@ -78,6 +78,7 @@ export function createVitePressPlugin( pages, config.define, config.command === 'build', + config.base, siteConfig.lastUpdated ) }, From 34d1542f466e2eed28b1be7153d1c3461d84528f Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Tue, 22 Feb 2022 07:55:44 +0530 Subject: [PATCH 03/12] fix: don't add .html to urls of non-html files (#515) fix #265 --- src/node/markdown/plugins/link.ts | 6 ++++-- src/node/markdownToVue.ts | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/node/markdown/plugins/link.ts b/src/node/markdown/plugins/link.ts index d1448bc803e5..e88e425ccaef 100644 --- a/src/node/markdown/plugins/link.ts +++ b/src/node/markdown/plugins/link.ts @@ -33,7 +33,9 @@ export const linkPlugin = ( // internal anchor links !url.startsWith('#') && // mail links - !url.startsWith('mailto:') + !url.startsWith('mailto:') && + // links to files (other than html/md) + !/\.(?!html|md)\w+($|\?)/i.test(url) ) { normalizeHref(hrefAttr) } @@ -56,7 +58,7 @@ export const linkPlugin = ( const [, path, hash] = indexMatch url = path + hash } else { - let cleanUrl = url.replace(/\#.*$/, '').replace(/\?.*$/, '') + let cleanUrl = url.replace(/[?#].*$/, '') // .md -> .html if (cleanUrl.endsWith('.md')) { cleanUrl = cleanUrl.replace(/\.md$/, '.html') diff --git a/src/node/markdownToVue.ts b/src/node/markdownToVue.ts index 29db746129ad..22b9eb38f37f 100644 --- a/src/node/markdownToVue.ts +++ b/src/node/markdownToVue.ts @@ -107,6 +107,8 @@ export function createMarkdownToVueRenderFn( if (data.links) { const dir = path.dirname(file) for (let url of data.links) { + if (/\.(?!html|md)\w+($|\?)/i.test(url)) continue + if (url.replace(EXTERNAL_URL_RE, '').startsWith('//localhost:')) { recordDeadLink(url) continue From 9270477fa59545978dc2732ac0a8091bed39625f Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Tue, 22 Feb 2022 07:56:16 +0530 Subject: [PATCH 04/12] fix: normalize relative img src (#514) fix #450 --- src/node/markdown/markdown.ts | 2 ++ src/node/markdown/plugins/image.ts | 15 +++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 src/node/markdown/plugins/image.ts diff --git a/src/node/markdown/markdown.ts b/src/node/markdown/markdown.ts index c9d68b9ec862..46cbff35bc20 100644 --- a/src/node/markdown/markdown.ts +++ b/src/node/markdown/markdown.ts @@ -11,6 +11,7 @@ import { hoistPlugin } from './plugins/hoist' import { preWrapperPlugin } from './plugins/preWrapper' import { linkPlugin } from './plugins/link' import { headingPlugin } from './plugins/headings' +import { imagePlugin } from './plugins/image' import { Header } from '../shared' import anchor from 'markdown-it-anchor' import attrs from 'markdown-it-attrs' @@ -67,6 +68,7 @@ export const createMarkdownRenderer = ( .use(hoistPlugin) .use(containerPlugin) .use(headingPlugin) + .use(imagePlugin) .use( linkPlugin, { diff --git a/src/node/markdown/plugins/image.ts b/src/node/markdown/plugins/image.ts new file mode 100644 index 000000000000..641a04c71c99 --- /dev/null +++ b/src/node/markdown/plugins/image.ts @@ -0,0 +1,15 @@ +// markdown-it plugin for normalizing image source + +import MarkdownIt from 'markdown-it' +import { EXTERNAL_URL_RE } from '../../shared' + +export const imagePlugin = (md: MarkdownIt) => { + md.renderer.rules.image = (tokens, idx, options, env, self) => { + const token = tokens[idx] + const url = token.attrGet('src') + if (url && !EXTERNAL_URL_RE.test(url) && !/^\.?\//.test(url)) { + token.attrSet('src', './' + url) + } + return self.renderToken(tokens, idx, options) + } +} From 779b78902fc7b1f9e7806751c0ca1e229a2161ce Mon Sep 17 00:00:00 2001 From: Fabian Winkler Date: Tue, 22 Feb 2022 03:27:22 +0100 Subject: [PATCH 05/12] fix: avoid minimizing non-javascript inline scripts (#517) fix #538 fix #540 --- src/node/build/render.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/node/build/render.ts b/src/node/build/render.ts index e5e226e376e6..88fef6433670 100644 --- a/src/node/build/render.ts +++ b/src/node/build/render.ts @@ -182,7 +182,10 @@ function renderHead(head: HeadConfig[]): Promise { head.map(async ([tag, attrs = {}, innerHTML = '']) => { const openTag = `<${tag}${renderAttrs(attrs)}>` if (tag !== 'link' && tag !== 'meta') { - if (tag === 'script') { + if ( + tag === 'script' && + (attrs.type === undefined || attrs.type.includes('javascript')) + ) { innerHTML = ( await transformWithEsbuild(innerHTML, 'inline-script.js', { minify: true From 33a59cd0295202ef136730ef2403a6295fb5a0c8 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Tue, 22 Feb 2022 07:59:22 +0530 Subject: [PATCH 06/12] docs: update links (#523) * docs: update links * docs: fix 3xx urls * chore: fix typo --- .github/ISSUE_TEMPLATE/bug_report.yml | 6 +++--- .github/ISSUE_TEMPLATE/feature_request.yml | 8 ++++---- .github/commit-convention.md | 10 +++++----- .github/contributing.md | 4 ++-- .github/workflows/test.yml | 2 +- README.md | 8 ++++---- docs/components/ComponentInHeader.vue | 2 +- docs/config/algolia-search.md | 4 ++-- docs/config/basics.md | 2 +- docs/config/homepage.md | 1 - docs/guide/api.md | 6 +++--- docs/guide/assets.md | 2 +- docs/guide/configuration.md | 2 +- docs/guide/deploy.md | 18 +++++++++--------- docs/guide/differences-from-vuepress.md | 7 ++++--- docs/guide/frontmatter.md | 1 - docs/guide/global-component.md | 3 +-- docs/guide/markdown.md | 10 +++++++--- docs/guide/theming.md | 8 +++----- docs/guide/using-vue.md | 12 ++++++------ docs/index.md | 2 +- .../components/AlgoliaSearchBox.vue | 19 ++++++------------- src/node/markdown/plugins/containers.ts | 4 +++- src/node/serve/serve.ts | 2 +- 24 files changed, 69 insertions(+), 74 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 513e0e08b562..f3bb8f2c10a0 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -1,6 +1,6 @@ name: "\U0001F41E Bug report" description: Create a report to help us improve -labels: ["bug: pending triage"] +labels: ['bug: pending triage'] body: - type: markdown attributes: @@ -52,9 +52,9 @@ body: label: Validations description: Before submitting the issue, please make sure you do the following options: - - label: Follow our [Code of Conduct](https://vuejs.org/coc) + - label: Follow our [Code of Conduct](https://vuejs.org/about/coc.html) required: true - - label: Read the [docs](https://vitepress.vuejs.org/). + - label: Read the [docs](https://vitepress.vuejs.org). required: true - label: Check that there isn't already an issue that reports the same bug to avoid creating a duplicate. required: true diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml index 78e74d534d22..0750eb7620c0 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.yml +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -35,11 +35,11 @@ body: label: Validations description: Before submitting the issue, please make sure you do the following options: - - label: Follow our [Code of Conduct](https://vuejs.org/coc) + - label: Follow our [Code of Conduct](https://vuejs.org/about/coc.html) required: true - - label: Read the [docs](https://vitepress.vuejs.org/). + - label: Read the [docs](https://vitepress.vuejs.org). required: true - - label: Read the [Contributing Guidelines](https://github.com/vuejs/vitepress/blob/master/.github/contributing.md). + - label: Read the [Contributing Guidelines](https://github.com/vuejs/vitepress/blob/main/.github/contributing.md). required: true - - label: Check that there isn't already an issue that reports the same bug to avoid creating a duplicate. + - label: Check that there isn't already an issue that asks for the same feature to avoid creating a duplicate. required: true diff --git a/.github/commit-convention.md b/.github/commit-convention.md index 40b187d6acfc..e90c02e4421d 100644 --- a/.github/commit-convention.md +++ b/.github/commit-convention.md @@ -6,7 +6,7 @@ Messages must be matched by the following regex: -``` js +```js /^(revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip)(\(.+\))?: .{1,50}/ ``` @@ -44,7 +44,7 @@ This reverts commit 667ecc1654a317a13331b17617d973392f415f02. ### Full Message Format -A commit message consists of a **header**, **body** and **footer**. The header has a **type**, **scope** and **subject**: +A commit message consists of a **header**, **body** and **footer**. The header has a **type**, **scope** and **subject**: ``` (): @@ -74,9 +74,9 @@ The scope could be anything specifying the place of the commit change. For examp The subject contains a succinct description of the change: -* use the imperative, present tense: "change" not "changed" nor "changes" -* don't capitalize the first letter -* no dot (.) at the end +- use the imperative, present tense: "change" not "changed" nor "changes" +- don't capitalize the first letter +- no dot (.) at the end ### Body diff --git a/.github/contributing.md b/.github/contributing.md index 021398493cbb..3d01e44fc02d 100644 --- a/.github/contributing.md +++ b/.github/contributing.md @@ -19,11 +19,11 @@ Hi! We're really excited that you are interested in contributing to VitePress. B - It's OK to have multiple small commits as you work on the PR - GitHub can automatically squash them before merging. -- Commit messages must follow the [commit message convention](./commit-convention.md) so that changelogs can be automatically generated. +- Commit messages must follow the [commit message convention](./commit-convention) so that changelogs can be automatically generated. ## Development Setup -You will need [pnpm](https://pnpm.io/) +You will need [pnpm](https://pnpm.io) After cloning the repo, run: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 43b3309ed26e..3445704c73f7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,7 +21,7 @@ jobs: uses: actions/setup-node@v2 with: node-version: ${{ matrix.node_version }} - cache: "pnpm" + cache: 'pnpm' - name: Install deps run: pnpm install diff --git a/README.md b/README.md index 25db53e63f09..0e7062816503 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ --- -VitePress is [VuePress](http://vuepress.vuejs.org/)' spiritual successor, built on top of [vite](https://github.com/vuejs/vite). +VitePress is [VuePress](https://vuepress.vuejs.org)' spiritual successor, built on top of [vite](https://github.com/vitejs/vite). ## Documentation @@ -13,14 +13,14 @@ To check out docs, visit [vitepress.vuejs.org](https://vitepress.vuejs.org). ## Changelog -Detailed changes for each release are documented in the [CHANGELOG](https://github.com/vuejs/vitepress/blob/master/CHANGELOG.md). +Detailed changes for each release are documented in the [CHANGELOG](./CHANGELOG). ## Contribution -Please make sure to read the [Contributing Guide](./.github/contributing.md) before making a pull request. +Please make sure to read the [Contributing Guide](./.github/contributing) before making a pull request. ## License -[MIT](https://opensource.org/licenses/MIT) +[MIT](./LICENSE) Copyright (c) 2019-present, Yuxi (Evan) You diff --git a/docs/components/ComponentInHeader.vue b/docs/components/ComponentInHeader.vue index 3999e16ada42..bbccc8ef2eab 100644 --- a/docs/components/ComponentInHeader.vue +++ b/docs/components/ComponentInHeader.vue @@ -1,3 +1,3 @@ \ No newline at end of file + diff --git a/docs/config/algolia-search.md b/docs/config/algolia-search.md index 3ee35eb145ad..28e4e5fd8191 100644 --- a/docs/config/algolia-search.md +++ b/docs/config/algolia-search.md @@ -1,6 +1,6 @@ # Theme Config: Algolia Search -The `themeConfig.algolia` option allows you to use [Algolia DocSearch](https://docsearch.algolia.com/). To enable it, you need to provide at least apiKey and indexName: +The `themeConfig.algolia` option allows you to use [Algolia DocSearch](https://docsearch.algolia.com). To enable it, you need to provide at least apiKey and indexName: ```js module.exports = { @@ -13,7 +13,7 @@ module.exports = { } ``` -For more options, check out [Algolia DocSearch's documentation](https://docsearch.algolia.com/docs/behavior). You can pass any extra option alongside other options, e.g. passing `searchParameters`: +For more options, check out [Algolia DocSearch's documentation](https://docsearch.algolia.com/docs/api/). You can pass any extra option alongside other options, e.g. passing `searchParameters`: ```js module.exports = { diff --git a/docs/config/basics.md b/docs/config/basics.md index 56b2268c8121..5955ecb59f33 100644 --- a/docs/config/basics.md +++ b/docs/config/basics.md @@ -1,7 +1,7 @@ # App Config: Basics ::: tip -The config reference is incomplete since the config format may still receive further changes. For a complete reference of the current available options, refer to [config.ts](https://github.com/vuejs/vitepress/blob/master/src/node/config.ts#L15). +The config reference is incomplete since the config format may still receive further changes. For a complete reference of the current available options, refer to [config.ts](https://github.com/vuejs/vitepress/blob/45b65ce8b63bd54f345bfc3383eb2416b6769dc9/src/node/config.ts#L30-L65). ::: ## base diff --git a/docs/config/homepage.md b/docs/config/homepage.md index 35f77da03d56..0abaad7b7e63 100644 --- a/docs/config/homepage.md +++ b/docs/config/homepage.md @@ -20,5 +20,4 @@ features: details: VitePress generates pre-rendered static HTML for each page, and runs as an SPA once a page is loaded. footer: MIT Licensed | Copyright © 2019-present Evan You --- - ``` diff --git a/docs/guide/api.md b/docs/guide/api.md index 924b0272874e..5db50b8c52bc 100644 --- a/docs/guide/api.md +++ b/docs/guide/api.md @@ -4,7 +4,7 @@ The following methods are globally importable from `vitepress` and are typically used in custom theme Vue components. However, they are also usable inside `.md` pages because markdown files are compiled into Vue single-file components. -Methods that start with `use*` indicates that it is a [Vue 3 Composition API](https://v3.vuejs.org/guide/composition-api-introduction.html) function that can only be used inside `setup()` or `