Skip to content

Commit

Permalink
fix($core): use directory name to compute slug if filename is readme …
Browse files Browse the repository at this point in the history
…or index (close: #1443) (#1535)
  • Loading branch information
znck authored and ulivz committed Apr 13, 2019
1 parent fb324d5 commit 9efc678
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions packages/@vuepress/core/lib/node/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,19 @@ module.exports = class Page {
*/

get slug () {
return slugify(this.strippedFilename)
const strippedFilename = this.strippedFilename

if (/^(index|readme)$/i.test(strippedFilename)) {
const strippedFilename = this.stripFilename(
path.basename(path.dirname(this._filePath || this.regularPath))
)

if (strippedFilename) {
return slugify(strippedFilename)
}
}

return slugify(strippedFilename)
}

/**
Expand All @@ -179,8 +191,7 @@ module.exports = class Page {
*/

get strippedFilename () {
const match = this.filename.match(DATE_RE)
return match ? match[3] : this.filename
return this.stripFilename(this.filename)
}

/**
Expand All @@ -194,6 +205,22 @@ module.exports = class Page {
return inferDate(this.frontmatter, this.filename)
}

/**
* stripped file name.
*
* If filename was yyyy-MM-dd-[title], the date prefix will be stripped.
* If filename was yyyy-MM-[title], the date prefix will be stripped.
*
* @param {string} fileName
* @returns {string}
* @private
*/
stripFilename(fileName) {
const match = fileName.match(DATE_RE)

return match ? match[3] : fileName
}

/**
* Convert page's metadata to JSON, note that all fields beginning
* with an underscore will not be serialized.
Expand Down

0 comments on commit 9efc678

Please sign in to comment.