提交 2c930c90 编写于 作者: Z zyxd 提交者: ULIVZ

feat($core): infer page's date via directory name (#1553)

上级 09709540
......@@ -146,6 +146,17 @@ module.exports = class Page {
this.buildPermalink()
}
/**
* name of page's parent directory.
*
* @returns {string}
* @api public
*/
get dirname () {
return path.basename(path.dirname(this._filePath || this.regularPath))
}
/**
* file name of page's source markdown file, or the last cut of regularPath.
*
......@@ -202,7 +213,7 @@ module.exports = class Page {
*/
get date () {
return inferDate(this.frontmatter, this.filename)
return inferDate(this.frontmatter, this.filename, this.dirname)
}
/**
......
......@@ -54,13 +54,16 @@ exports.applyUserWebpackConfig = function (userConfig, config, isServer) {
const DATE_RE = /(\d{4}-\d{1,2}(-\d{1,2})?)-(.*)/
exports.DATE_RE = DATE_RE
exports.inferDate = function (frontmatter = {}, filename) {
exports.inferDate = function (frontmatter = {}, filename, dirname) {
let matches
if (frontmatter.date) {
return frontmatter.date
} else if (filename && (matches = filename.match(DATE_RE))) {
return matches[1]
} else if (dirname && (matches = dirname.match(DATE_RE))) {
return matches[1]
} else {
return null
}
const match = filename.match(DATE_RE)
if (match) {
return match[1]
}
return null
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册