diff --git a/aio/content/file-not-found.md b/aio/content/file-not-found.md
index 719a135b6c..7cd8a516d5 100644
--- a/aio/content/file-not-found.md
+++ b/aio/content/file-not-found.md
@@ -1,3 +1,3 @@
-@title Document not found
+@title
@description
Document not found
\ No newline at end of file
diff --git a/aio/src/app/app.component.spec.ts b/aio/src/app/app.component.spec.ts
index e0b4d11d2a..a95fa12916 100644
--- a/aio/src/app/app.component.spec.ts
+++ b/aio/src/app/app.component.spec.ts
@@ -272,6 +272,14 @@ describe('AppComponent', () => {
fixture.detectChanges();
expect(titleService.setTitle).toHaveBeenCalledWith('Angular - Pipes');
});
+
+ it('should update the document title, with a default value if the document has no title', () => {
+ const titleService = TestBed.get(Title);
+ spyOn(titleService, 'setTitle');
+ locationService.go('file-not-found');
+ fixture.detectChanges();
+ expect(titleService.setTitle).toHaveBeenCalledWith('Angular');
+ });
});
describe('autoScrolling', () => {
@@ -424,12 +432,18 @@ class TestHttp {
"contents": "Test Doc
"
};
+ fileNotFoundDoc = {
+ "title": "",
+ "contents": "Page not found"
+ };
+
// get = jasmine.createSpy('get').and.callFake((url: string) => { ... });
get(url: string) {
const json =
/navigation.json/.test(url) ? this.navJson :
/api/.test(url) ? this.apiDoc :
/pipes/.test(url) ? this.pipesDoc :
+ /file-not-found/.test(url) ? this.fileNotFoundDoc :
this.testDoc;
return of({ json: () => json });
}
diff --git a/aio/src/app/app.component.ts b/aio/src/app/app.component.ts
index 4ae7718f21..7ccb07de7d 100644
--- a/aio/src/app/app.component.ts
+++ b/aio/src/app/app.component.ts
@@ -150,6 +150,10 @@ export class AppComponent implements OnInit {
}
setDocumentTitle(title) {
- this.titleService.setTitle(`Angular - ${title}`);
+ if (title.trim()) {
+ this.titleService.setTitle(`Angular - ${title}`);
+ } else {
+ this.titleService.setTitle('Angular');
+ }
}
}
diff --git a/aio/tools/transforms/angular.io-package/processors/convertToJson.js b/aio/tools/transforms/angular.io-package/processors/convertToJson.js
index 374e1eb176..230f524a3c 100644
--- a/aio/tools/transforms/angular.io-package/processors/convertToJson.js
+++ b/aio/tools/transforms/angular.io-package/processors/convertToJson.js
@@ -8,9 +8,15 @@ module.exports = function convertToJsonProcessor(log, createDocMessage) {
const docTypes = this.docTypes;
docs.forEach((doc) => {
if (docTypes.indexOf(doc.docType) !== -1) {
- let title = doc.title || doc.name;
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>/.exec(contents);
diff --git a/aio/tools/transforms/angular.io-package/processors/convertToJson.spec.js b/aio/tools/transforms/angular.io-package/processors/convertToJson.spec.js
index 534f3506ff..17a073b004 100644
--- a/aio/tools/transforms/angular.io-package/processors/convertToJson.spec.js
+++ b/aio/tools/transforms/angular.io-package/processors/convertToJson.spec.js
@@ -4,7 +4,7 @@ var Dgeni = require('dgeni');
describe('convertToJson processor', () => {
var dgeni, injector, processor, log;
- beforeEach(function() {
+ beforeAll(function() {
dgeni = new Dgeni([testPackage('angular.io-package')]);
injector = dgeni.configureInjector();
processor = injector.get('convertToJsonProcessor');
@@ -34,6 +34,20 @@ describe('convertToJson processor', () => {
expect(JSON.parse(docs[0].renderedContent).title).toEqual('The Name');
});
+ it('should accept an empty title', () => {
+ const docs = [{ docType: 'test-doc', title: '' }];
+ processor.$process(docs);
+ expect(JSON.parse(docs[0].renderedContent).title).toEqual('');
+ expect(log.warn).not.toHaveBeenCalled();
+ });
+
+ it('should accept an empty name if title is not provided', () => {
+ const docs = [{ docType: 'test-doc', name: '' }];
+ processor.$process(docs);
+ expect(JSON.parse(docs[0].renderedContent).title).toEqual('');
+ 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: '' }];
processor.$process(docs);