mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 15:47:23 +02:00
Ignore and warn about unsupported header fields (#347)
Unsupported header fields might mess up the creation of metadata.js (e.g.: next). Skip unknown header fields and log a warn about them.
This commit is contained in:
parent
8e2717cfae
commit
ad5b8b92b4
1 changed files with 19 additions and 1 deletions
|
@ -17,6 +17,16 @@ const siteConfig = require(CWD + '/siteConfig.js');
|
|||
const versionFallback = require('./versionFallback.js');
|
||||
const escapeStringRegexp = require('escape-string-regexp');
|
||||
|
||||
const SupportedHeaderFields = new Set([
|
||||
'id',
|
||||
'title',
|
||||
'author',
|
||||
'authorURL',
|
||||
'authorFBID',
|
||||
'sidebar_label',
|
||||
'original_id',
|
||||
]);
|
||||
|
||||
// Can have a custom docs path. Top level folder still needs to be in directory
|
||||
// at the same level as `website`, not inside `website`.
|
||||
// e.g., docs/whereDocsReallyExist
|
||||
|
@ -119,7 +129,15 @@ function processMetadata(file) {
|
|||
const match = regexSubFolder.exec(file);
|
||||
let language = match ? match[1] : 'en';
|
||||
|
||||
const metadata = result.metadata;
|
||||
const metadata = {};
|
||||
for (const fieldName of Object.keys(result.metadata)) {
|
||||
if (SupportedHeaderFields.has(fieldName)) {
|
||||
metadata[fieldName] = result.metadata[fieldName];
|
||||
} else {
|
||||
console.warn(`Header field "${fieldName}" in ${file} is not supported.`);
|
||||
}
|
||||
}
|
||||
|
||||
const rawContent = result.rawContent;
|
||||
metadata.source = path.basename(file);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue