diff options
author | Johan Preynat <johan.preynat@gmail.com> | 2016-04-29 14:35:56 +0200 |
---|---|---|
committer | Johan Preynat <johan.preynat@gmail.com> | 2016-04-29 14:38:12 +0200 |
commit | 94199af7b293b9c6f82a2e1c341587adee5b0792 (patch) | |
tree | 44de86b051017c509c35320e127fd95e99ceefef | |
parent | b8d7a00f58401d827ef06b76f4a9f189b89c7606 (diff) | |
download | gitbook-94199af7b293b9c6f82a2e1c341587adee5b0792.zip gitbook-94199af7b293b9c6f82a2e1c341587adee5b0792.tar.gz gitbook-94199af7b293b9c6f82a2e1c341587adee5b0792.tar.bz2 |
Add location.areIdenticalPaths(p1,p2) to effectively compare two paths
-rw-r--r-- | lib/parse/parseSummary.js | 4 | ||||
-rw-r--r-- | lib/utils/location.js | 13 |
2 files changed, 16 insertions, 1 deletions
diff --git a/lib/parse/parseSummary.js b/lib/parse/parseSummary.js index 2c6186f..72bf224 100644 --- a/lib/parse/parseSummary.js +++ b/lib/parse/parseSummary.js @@ -1,6 +1,7 @@ var parseStructureFile = require('./parseStructureFile'); var Summary = require('../models/summary'); var SummaryModifier = require('../modifiers').Summary; +var location = require('../utils/location'); /** Parse summary in a book, the summary can only be parsed @@ -28,8 +29,9 @@ function parseSummary(book) { // Insert readme as first entry var firstArticle = summary.getFirstArticle(); + if (readmeFile.exists() && - (!firstArticle || firstArticle.getRef() !== readmeFile.getPath())) { + (!firstArticle || !location.areIdenticalPaths(firstArticle.getRef(), readmeFile.getPath()))) { summary = SummaryModifier.unshiftArticle(summary, { title: 'Introduction', ref: readmeFile.getPath() diff --git a/lib/utils/location.js b/lib/utils/location.js index 94d9b2a..84a71ad 100644 --- a/lib/utils/location.js +++ b/lib/utils/location.js @@ -83,7 +83,20 @@ function relativeForFile(baseFile, file) { return relative(path.dirname(baseFile), file); } +/** + Compare two paths, return true if they are identical + ('README.md', './README.md') -> true + + @param {String} p1: first path + @param {String} p2: second path + @return {Boolean} +*/ +function areIdenticalPaths(p1, p2) { + return normalize(p1) === normalize(p2); +} + module.exports = { + areIdenticalPaths: areIdenticalPaths, isExternal: isExternal, isRelative: isRelative, isAnchor: isAnchor, |