diff --git a/aio/tools/transforms/angular-base-package/processors/convertToJson.js b/aio/tools/transforms/angular-base-package/processors/convertToJson.js
index 1506306065..932f6e69d2 100644
--- a/aio/tools/transforms/angular-base-package/processors/convertToJson.js
+++ b/aio/tools/transforms/angular-base-package/processors/convertToJson.js
@@ -12,17 +12,13 @@ module.exports = function convertToJsonProcessor(log, createDocMessage) {
let title = doc.title;
- // We do allow an empty `title` but resort to `name` if it is not even defined
+ // We do allow an empty `title` but if it is `undefined` we resort to `vFile.title` and then `name`
if (title === undefined) {
- title = doc.name;
+ title = (doc.vFile && doc.vFile.title);
}
- // If there is no title then try to extract it from the first h1 in the renderedContent
if (title === undefined) {
- const match = /
]*>(.+?)<\/h1>/.exec(contents);
- if (match) {
- title = match[1];
- }
+ title = doc.name;
}
// If there is still no title then log a warning
diff --git a/aio/tools/transforms/angular-base-package/processors/convertToJson.spec.js b/aio/tools/transforms/angular-base-package/processors/convertToJson.spec.js
index 043267ae10..355097cda0 100644
--- a/aio/tools/transforms/angular-base-package/processors/convertToJson.spec.js
+++ b/aio/tools/transforms/angular-base-package/processors/convertToJson.spec.js
@@ -50,8 +50,12 @@ describe('convertToJson processor', () => {
expect(log.warn).not.toHaveBeenCalled();
});
- it('should get the title from the first `h1` if no title nor name is specified', () => {
- const docs = [{ docType: 'test-doc', renderedContent: '' }];
+ it('should get the title from the title extracted from the h1 in the rendered content if no title property is specified', () => {
+ const docs = [{
+ docType: 'test-doc',
+ vFile: { title: 'Some title' },
+ renderedContent: ''
+ }];
processor.$process(docs);
expect(JSON.parse(docs[0].renderedContent).contents).toEqual('');
expect(JSON.parse(docs[0].renderedContent).title).toEqual('Some title');