|
|
@ -1,5 +1,5 @@
|
|
|
|
import path from 'path'
|
|
|
|
import path from 'path'
|
|
|
|
import { Plugin } from 'vite'
|
|
|
|
import { Plugin, ResolvedConfig } from 'vite'
|
|
|
|
import { SiteConfig, resolveSiteData } from './config'
|
|
|
|
import { SiteConfig, resolveSiteData } from './config'
|
|
|
|
import { createMarkdownToVueRenderFn } from './markdownToVue'
|
|
|
|
import { createMarkdownToVueRenderFn } from './markdownToVue'
|
|
|
|
import { APP_PATH, SITE_DATA_REQUEST_PATH } from './alias'
|
|
|
|
import { APP_PATH, SITE_DATA_REQUEST_PATH } from './alias'
|
|
|
@ -37,10 +37,15 @@ export function createVitePressPlugin(
|
|
|
|
|
|
|
|
|
|
|
|
let siteData = site
|
|
|
|
let siteData = site
|
|
|
|
let hasDeadLinks = false
|
|
|
|
let hasDeadLinks = false
|
|
|
|
|
|
|
|
let config: ResolvedConfig
|
|
|
|
|
|
|
|
|
|
|
|
const vitePressPlugin: Plugin = {
|
|
|
|
const vitePressPlugin: Plugin = {
|
|
|
|
name: 'vitepress',
|
|
|
|
name: 'vitepress',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
configResolved(resolvedConfig) {
|
|
|
|
|
|
|
|
config = resolvedConfig
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
config() {
|
|
|
|
config() {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
resolve: {
|
|
|
|
resolve: {
|
|
|
@ -72,7 +77,7 @@ export function createVitePressPlugin(
|
|
|
|
transform(code, id) {
|
|
|
|
transform(code, id) {
|
|
|
|
if (id.endsWith('.md')) {
|
|
|
|
if (id.endsWith('.md')) {
|
|
|
|
// transform .md files into vueSrc so plugin-vue can handle it
|
|
|
|
// transform .md files into vueSrc so plugin-vue can handle it
|
|
|
|
const { vueSrc, deadLinks } = markdownToVue(code, id)
|
|
|
|
const { vueSrc, deadLinks } = markdownToVue(code, id, config.publicDir)
|
|
|
|
if (deadLinks.length) {
|
|
|
|
if (deadLinks.length) {
|
|
|
|
hasDeadLinks = true
|
|
|
|
hasDeadLinks = true
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -176,7 +181,11 @@ export function createVitePressPlugin(
|
|
|
|
// hot reload .md files as .vue files
|
|
|
|
// hot reload .md files as .vue files
|
|
|
|
if (file.endsWith('.md')) {
|
|
|
|
if (file.endsWith('.md')) {
|
|
|
|
const content = await read()
|
|
|
|
const content = await read()
|
|
|
|
const { pageData, vueSrc } = markdownToVue(content, file)
|
|
|
|
const { pageData, vueSrc } = markdownToVue(
|
|
|
|
|
|
|
|
content,
|
|
|
|
|
|
|
|
file,
|
|
|
|
|
|
|
|
config.publicDir
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// notify the client to update page data
|
|
|
|
// notify the client to update page data
|
|
|
|
server.ws.send({
|
|
|
|
server.ws.send({
|
|
|
|