mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-19 20:17:06 +02:00
Update doc metadata to use file name as id fallback and id as title fallback
This commit is contained in:
parent
db7a7394b3
commit
964e9e2108
5 changed files with 56 additions and 27 deletions
18
lib/version.js
Normal file → Executable file
18
lib/version.js
Normal file → Executable 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)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue