Skip to content

Commit 20a1b2c

Browse files
committed
Remove <title> from index.html upon install if ember-page-title is present
1 parent 1dbd839 commit 20a1b2c

File tree

1 file changed

+39
-1
lines changed
  • packages/ember-cli-fastboot/blueprints/ember-cli-fastboot

1 file changed

+39
-1
lines changed

packages/ember-cli-fastboot/blueprints/ember-cli-fastboot/index.js

+39-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
'use strict';
2+
13
/* eslint-env node */
4+
const path = require('path');
25
const recast = require('recast');
3-
const { readFileSync, writeFileSync } = require('fs');
6+
const { readFileSync, writeFileSync, existsSync } = require('fs');
47

58
module.exports = {
69
description: '',
@@ -9,6 +12,11 @@ module.exports = {
912
},
1013

1114
afterInstall() {
15+
this.updateBabelTargets();
16+
this.removeTitleFromIndexHtml();
17+
},
18+
19+
updateBabelTargets() {
1220
let targetsFile = './config/targets.js'
1321

1422
if(this.project.isEmberCLIAddon()) {
@@ -40,5 +48,35 @@ module.exports = {
4048
});
4149

4250
writeFileSync(targetsFile, recast.print(targetsAst, { tabWidth: 2, quote: 'single' }).code);
51+
},
52+
53+
removeTitleFromIndexHtml() {
54+
let isEmberPageTitlePresent = 'ember-page-title' in this.project.dependencies();
55+
56+
if (isEmberPageTitlePresent) {
57+
let indexHtmlPath = this.project.isEmberCLIAddon() ?
58+
path.join(this.project.root, 'tests', 'dummy', 'app', 'index.html') :
59+
path.join(this.project.root, 'app', 'index.html');
60+
61+
if (existsSync(indexHtmlPath)) {
62+
const contents = readFileSync(
63+
indexHtmlPath,
64+
{
65+
encoding: 'utf8'
66+
}
67+
);
68+
69+
const titleMatches = contents.match(/<title>(.*)<\/title>/i);
70+
const title = titleMatches[1] || "Example Title";
71+
writeFileSync(
72+
indexHtmlPath,
73+
contents.replace(/\s*<title>.*<\/title>/gi, ''),
74+
{
75+
encoding: 'utf8'
76+
}
77+
);
78+
this.ui.writeWarnLine(`<title> has been removed from index.html due to ember-page-title being present, please add {{page-title "${title}"}} to application.hbs`);
79+
}
80+
}
4381
}
4482
};

0 commit comments

Comments
 (0)