Skip to content

Commit

Permalink
Ignore and warn about unsupported header fields (#347)
Browse files Browse the repository at this point in the history
Unsupported header fields might mess up the creation of metadata.js (e.g.: next).
Skip unknown header fields and log a warn about them.
  • Loading branch information
aadsm authored and JoelMarcey committed Apr 12, 2018
1 parent 8e2717c commit ad5b8b9
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/server/readMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit ad5b8b9

Please sign in to comment.