Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// render pages
logger.wait('Rendering static HTML...')
const pagePaths = []
for (const page of ctx.pages) {
pagePaths.push(await renderPage(page))
}
readline.clearLine(process.stdout, 0)
readline.cursorTo(process.stdout, 0)
await ctx.pluginAPI.options.generated.apply(pagePaths)
// DONE.
const relativeDir = path.relative(cwd, outDir)
logger.success(`Generated static files in ${chalk.cyan(relativeDir)}.`)
const { duration } = performance.stop()
logger.developer(`It took a total of ${chalk.cyan(`${duration}ms`)} to run the ${chalk.cyan('vuepress build')}.`)
console.log()
// --- helpers ---
function compile (config) {
return new Promise((resolve, reject) => {
webpack(config, (err, stats) => {
if (err) {
return reject(err)
}
if (stats.hasErrors()) {
stats.toJson().errors.forEach(err => {
console.error(err)
// render pages
logger.wait('Rendering static HTML...')
const pagePaths = []
for (const page of this.context.pages) {
pagePaths.push(await this.renderPage(page))
}
readline.clearLine(process.stdout, 0)
readline.cursorTo(process.stdout, 0)
await this.context.pluginAPI.applyAsyncOption('generated', pagePaths)
// DONE.
const relativeDir = path.relative(this.context.cwd, this.outDir)
logger.success(`Generated static files in ${chalk.cyan(relativeDir)}.`)
const { duration } = performance.stop()
logger.developer(`It took a total of ${chalk.cyan(`${duration}ms`)} to run the ${chalk.cyan('vuepress build')}.`)
console.log()
}
for (const page of options.pages) {
await renderPage(page)
}
// if the user does not have a custom 404.md, generate the theme's default
if (!options.pages.some(p => p.path === '/404.html')) {
await renderPage({ path: '/404.html' })
}
readline.clearLine(process.stdout, 0)
readline.cursorTo(process.stdout, 0)
await options.pluginAPI.options.generated.apply()
// DONE.
const relativeDir = path.relative(process.cwd(), outDir)
logger.success(`\n${chalk.green('Success!')} Generated static files in ${chalk.cyan(relativeDir)}.\n`)
// --- helpers ---
function compile (config) {
return new Promise((resolve, reject) => {
webpack(config, (err, stats) => {
if (err) {
return reject(err)
}
if (stats.hasErrors()) {
stats.toJson().errors.forEach(err => {
console.error(err)
})
reject(new Error(`Failed to compile with errors.`))
return
this._permalink = permalink
this.frontmatter = frontmatter
this._permalinkPattern = permalinkPattern
this._extractHeaders = extractHeaders
this._context = context
if (relative) {
this.regularPath = encodeURI(fileToPath(relative))
} else if (_path) {
this.regularPath = encodeURI(_path)
} else if (permalink) {
this.regularPath = encodeURI(permalink)
}
if (filePath) {
this.relativePath = path.relative(context.sourceDir, filePath).replace(/\\/g, '/')
}
this.key = 'v-' + hash(`${this._filePath}${this.regularPath}`)
// Using regularPath first, would be override by permalink later.
this.path = this.regularPath
}
async resolvePages () {
// resolve pageFiles
const patterns = this.siteConfig.patterns ? this.siteConfig.patterns : ['**/*.md', '**/*.vue']
patterns.push('!.vuepress', '!node_modules')
if (this.siteConfig.dest) {
// #654 exclude dest folder when dest dir was set in
// sourceDir but not in '.vuepress'
const outDirRelative = path.relative(this.sourceDir, this.outDir)
if (!outDirRelative.includes('..')) {
patterns.push('!' + outDirRelative)
}
}
const pageFiles = sort(await globby(patterns, { cwd: this.sourceDir }))
await Promise.all(pageFiles.map(async (relative) => {
const filePath = path.resolve(this.sourceDir, relative)
await this.addPage({ filePath, relative })
}))
}
}
// ---------------------------------------------------------------------
const feed = feeds[ key ];
if ( ! feed.enable || ! feed.file_name )
{
continue;
}
// ---------------------------------------------------------------------
const content = this.feed_generator[ key ]();
const file = PATH.resolve( outDir, feed.file_name );
const relative = PATH.relative( cwd, file );
await FSE.outputFile( file, content );
LIB.LOG.success(`${key} feed file generated and saved to ${CHALK.cyan( relative )}`);
// ---------------------------------------------------------------------
out.push( file );
}
// -----------------------------------------------------------------------
return out;
} catch ( err ) {
headers,
frontmatterData: frontmatter.data,
inferredTitle
})
}
// the render method has been augmented to allow plugins to
// register data during render
const {
html,
data: { hoistedTags, links },
dataBlockString
} = markdown.render(content, {
loader,
frontmatter: frontmatter.data,
relativePath: path.relative(sourceDir, file).replace(/\\/g, '/')
})
// check if relative links are valid
links && links.forEach(link => {
link = decodeURIComponent(link)
const shortname = link
.replace(/#.*$/, '')
.replace(/\.html$/, '.md')
const filename = shortname
.replace(/\/$/, '/README.md')
.replace(/^\//, sourceDir + '/')
const altname = shortname
.replace(/\/$/, '/index.md')
.on('fileChanged', ({ type, target }) => {
console.log(`Reload due to ${chalk.red(type)} ${chalk.cyan(path.relative(this.sourceDir, target))}`)
this.process()
})
.createServer()
filter: src => {
const relative = path.relative(sourceDir, src)
if (EXCLUDED_FILES.includes(relative)) {
return false
}
if (relative) {
logger.debug('Copied', chalk.cyan(relative))
}
return true
}
})