Update doc metadata to use file name as id fallback and id as title fallback

This commit is contained in:
Frank Li 2017-08-10 14:51:34 -07:00
parent db7a7394b3
commit 964e9e2108
5 changed files with 56 additions and 27 deletions

18
lib/version.js Normal file → Executable file
View file

@ -20,7 +20,7 @@ const versionFallback = require("./server/versionFallback.js");
const CWD = process.cwd();
let versions;
if (fs.existsSync(CWD + "/versions.json")) {
versions = require(CWD + "/versions.json");
versions = require(CWD + "/versions.json");
} else {
versions = [];
}
@ -37,14 +37,18 @@ program
if (typeof version === "undefined") {
console.error(
`${chalk.yellow("No version number specified!")}\nPass the version you wish to create as an argument.\nEx: 1.0.0`
`${chalk.yellow(
"No version number specified!"
)}\nPass the version you wish to create as an argument.\nEx: 1.0.0`
);
process.exit(1);
}
if (versions.includes(version)) {
console.error(
`${chalk.yellow("This version already exists!")}\nSpecify a new version to create that does not already exist.`
`${chalk.yellow(
"This version already exists!"
)}\nSpecify a new version to create that does not already exist.`
);
process.exit(1);
}
@ -74,7 +78,13 @@ files.forEach(file => {
let metadata = res.metadata;
let rawContent = res.rawContent;
if (!metadata.id) {
return;
metadata.id = path.basename(file, path.extname(file));
}
if (metadata.id.includes("/") || metadata.id.includes(".")) {
throw new Error('Document id cannot include "/" or ".".');
}
if (!metadata.title) {
metadata.title = metadata.id;
}
if (!versionFallback.diffLatestDoc(file, metadata.id)) {