Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ability to configure markdown options (#127) #128

Merged
merged 5 commits into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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