mirror of
https://github.com/wahyd4/vuepress.git
synced 2026-08-11 22:36:59 +10:00
67 lines
1.3 KiB
JavaScript
67 lines
1.3 KiB
JavaScript
'use strict'
|
|
|
|
/**
|
|
* Normalize head tag config.
|
|
*
|
|
* @param {string|array} tag
|
|
* @returns {object}
|
|
*/
|
|
|
|
exports.normalizeHeadTag = function (tag) {
|
|
if (typeof tag === 'string') {
|
|
tag = [tag]
|
|
}
|
|
const tagName = tag[0]
|
|
return {
|
|
tagName,
|
|
attributes: tag[1] || {},
|
|
innerHTML: tag[2] || '',
|
|
closeTag: !(tagName === 'meta' || tagName === 'link')
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Use webpack-merge to merge user's config into default config.
|
|
*
|
|
* @param {object} userConfig
|
|
* @param {object} config
|
|
* @param {boolean} isServer
|
|
* @returns {object}
|
|
*/
|
|
|
|
exports.applyUserWebpackConfig = function (userConfig, config, isServer) {
|
|
const merge = require('webpack-merge')
|
|
if (typeof userConfig === 'object') {
|
|
return merge(config, userConfig)
|
|
}
|
|
if (typeof userConfig === 'function') {
|
|
const res = userConfig(config, isServer)
|
|
if (res && typeof res === 'object') {
|
|
return merge(config, res)
|
|
}
|
|
}
|
|
return config
|
|
}
|
|
|
|
/**
|
|
* Infer date.
|
|
*
|
|
* @param {object} frontmatter
|
|
* @param {string} filename
|
|
* @returns {null|string}
|
|
*/
|
|
|
|
const DATE_RE = /(\d{4}-\d{1,2}(-\d{1,2})?)-(.*)/
|
|
exports.DATE_RE = DATE_RE
|
|
|
|
exports.inferDate = function (frontmatter = {}, filename) {
|
|
if (frontmatter.date) {
|
|
return frontmatter.date
|
|
}
|
|
const match = filename.match(DATE_RE)
|
|
if (match) {
|
|
return match[1]
|
|
}
|
|
return null
|
|
}
|