build(aio): refactor dgeni packages
This is to tidy up the `author-packagse`, which currently duplicates a lot of the configuration in the main packages. We need to DRY this up so that we don't fall foul of a change in one being missed in the other.
This commit is contained in:

committed by
Pete Bacon Darwin

parent
7a8bd99ab1
commit
3cad5da5a4
40
aio/tools/transforms/angular-base-package/processors/convertToJson.js
vendored
Normal file
40
aio/tools/transforms/angular-base-package/processors/convertToJson.js
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
module.exports = function convertToJsonProcessor(log, createDocMessage) {
|
||||
|
||||
return {
|
||||
$runAfter: ['checkUnbalancedBackTicks'],
|
||||
$runBefore: ['writeFilesProcessor'],
|
||||
docTypes: [],
|
||||
$process: function(docs) {
|
||||
const docTypes = this.docTypes;
|
||||
docs.forEach((doc) => {
|
||||
if (docTypes.indexOf(doc.docType) !== -1) {
|
||||
let contents = doc.renderedContent || '';
|
||||
|
||||
let title = doc.title;
|
||||
|
||||
// We do allow an empty `title` but resort to `name` if it is not even defined
|
||||
if (title === undefined) {
|
||||
title = doc.name;
|
||||
}
|
||||
|
||||
// If there is no title then try to extract it from the first h1 in the renderedContent
|
||||
if (title === undefined) {
|
||||
const match = /<h1[^>]*>(.+?)<\/h1>/.exec(contents);
|
||||
if (match) {
|
||||
title = match[1];
|
||||
}
|
||||
}
|
||||
|
||||
// If there is still no title then log a warning
|
||||
if (title === undefined) {
|
||||
title = '';
|
||||
log.warn(createDocMessage('Title property expected', doc));
|
||||
}
|
||||
|
||||
doc.renderedContent = JSON.stringify({ id: doc.path, title, contents }, null, 2);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
};
|
Reference in New Issue
Block a user