Skip to content

Commit

Permalink
feat: add ability to configure markdown options (#127) (#128)
Browse files Browse the repository at this point in the history
close #127

Co-authored-by: Kia Ishii <kia.king.08@gmail.com>
  • Loading branch information
ChrisShank and kiaking committed Nov 18, 2020
1 parent d5502d1 commit 463a03a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/node/build/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function bundle(
const root = config.root
const userConfig = await resolveUserConfig(root)
const resolver = createResolver(config.themeDir, userConfig)
const markdownToVue = createMarkdownToVueRenderFn(root)
const markdownToVue = createMarkdownToVueRenderFn(root, userConfig.markdown)

let isClientBuild = true
const pageToHashMap = Object.create(null)
Expand Down
6 changes: 5 additions & 1 deletion src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import globby from 'globby'
import { createResolver, APP_PATH } from './resolver'
import { Resolver } from 'vite'
import { SiteData, HeadConfig, LocaleConfig } from '../../types/shared'
import { MarkdownOptions } from './markdown/markdown'
export { resolveSiteDataByRoute } from './shared/config'

const debug = require('debug')('vitepress:config')
Expand All @@ -18,6 +19,7 @@ export interface UserConfig<ThemeConfig = any> {
themeConfig?: ThemeConfig
locales?: Record<string, LocaleConfig>
alias?: Record<string, string>
markdown?: MarkdownOptions
// TODO locales support etc.
}

Expand All @@ -30,6 +32,7 @@ export interface SiteConfig<ThemeConfig = any> {
tempDir: string
resolver: Resolver
pages: string[]
markdown?: MarkdownOptions
}

const resolve = (root: string, file: string) =>
Expand All @@ -55,7 +58,8 @@ export async function resolveConfig(
configPath: resolve(root, 'config.js'),
outDir: resolve(root, 'dist'),
tempDir: path.resolve(APP_PATH, 'temp'),
resolver: createResolver(themeDir, userConfig)
resolver: createResolver(themeDir, userConfig),
markdown: userConfig.markdown
}

return config
Expand Down
3 changes: 2 additions & 1 deletion src/node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ const debugHmr = require('debug')('vitepress:hmr')

function createVitePressPlugin({
configPath,
markdown,
site: initialSiteData
}: SiteConfig): ServerPlugin {
return ({ app, root, watcher, resolver }) => {
const markdownToVue = createMarkdownToVueRenderFn(root)
const markdownToVue = createMarkdownToVueRenderFn(root, markdown)

// hot reload .md files as .vue files
watcher.on('change', async (file) => {
Expand Down

0 comments on commit 463a03a

Please sign in to comment.