Better error when parsing headerLinks.doc fields (#337)

Closes #309
This commit is contained in:
Joel Marcey 2017-12-20 19:47:13 -08:00 committed by GitHub
parent 4637de9a52
commit 250395a96a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -133,17 +133,25 @@ class HeaderNav extends React.Component {
: ''; : '';
const id = langPart + versionPart + link.doc; const id = langPart + versionPart + link.doc;
if (!Metadata[id]) { if (!Metadata[id]) {
if (id != link.doc) { let errorStr =
throw new Error( "Processing the following `doc` field in `headerLinks` within `siteConfig.js`: '" +
"It looks like you've enabled language support, but haven't provided translated files. The document with id: '" + link.doc +
id + "'";
"' doesn't exist." if (id === link.doc) {
); errorStr +=
' It looks like there is no document with that id that exists in your docs directory. Please double check the spelling of your `doc` field and the `id` fields of your docs.';
} else {
errorStr +=
'. Check the spelling of your `doc` field. If that seems sane, and a document in your docs folder exists with that `id` value, \nthen this is likely a bug in Docusaurus.' +
' Docusaurus thinks one or both of translations (currently set to: ' +
env.translation.enabled +
') or versioning (currently set to: ' +
env.versioning.enabled +
") is enabled when maybe they should not be. \nThus my internal id for this doc is: '" +
id +
"'. Please file an issue for this possible bug on GitHub.";
} }
throw new Error( throw new Error(errorStr);
'A headerLink is specified with a document that does not exist. No document exists with id: ' +
link.doc
);
} }
href = this.props.config.baseUrl + Metadata[id].permalink; href = this.props.config.baseUrl + Metadata[id].permalink;
} else if (link.page) { } else if (link.page) {