Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Commit bcc48f3

Browse files
markgohofilipesilva
authored andcommitted
feat(@angular/pwa): add content for when javascript is not available
1 parent f0ee2c8 commit bcc48f3

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

packages/angular/pwa/pwa/index.ts

+21-7
Original file line numberDiff line numberDiff line change
@@ -66,27 +66,41 @@ function updateIndexFile(options: PwaOptions): Rule {
6666
const lines = content.split('\n');
6767
let closingHeadTagLineIndex = -1;
6868
let closingHeadTagLine = '';
69-
lines.forEach((line, index) => {
69+
let closingBodyTagLineIndex = -1;
70+
let closingBodyTagLine = '';
71+
lines.forEach((line: string, index: number) => {
7072
if (/<\/head>/.test(line) && closingHeadTagLineIndex === -1) {
7173
closingHeadTagLine = line;
7274
closingHeadTagLineIndex = index;
7375
}
76+
77+
if (/<\/body>/.test(line) && closingBodyTagLineIndex === -1) {
78+
closingBodyTagLine = line;
79+
closingBodyTagLineIndex = index;
80+
}
7481
});
7582

76-
const indent = getIndent(closingHeadTagLine) + ' ';
77-
const itemsToAdd = [
83+
const headTagIndent = getIndent(closingHeadTagLine) + ' ';
84+
const itemsToAddToHead = [
7885
'<link rel="manifest" href="manifest.json">',
7986
'<meta name="theme-color" content="#1976d2">',
8087
];
8188

82-
const textToInsert = itemsToAdd
83-
.map(text => indent + text)
89+
const textToInsertIntoHead = itemsToAddToHead
90+
.map(text => headTagIndent + text)
8491
.join('\n');
8592

93+
const bodyTagIndent = getIndent(closingBodyTagLine) + ' ';
94+
const itemsToAddToBody = '<noscript>Please enable Javascript to continue using this application.</noscript>'
95+
96+
const textToInsertIntoBody = bodyTagIndent + itemsToAddToBody;
97+
8698
const updatedIndex = [
8799
...lines.slice(0, closingHeadTagLineIndex),
88-
textToInsert,
89-
...lines.slice(closingHeadTagLineIndex),
100+
textToInsertIntoHead,
101+
...lines.slice(closingHeadTagLineIndex, closingBodyTagLineIndex),
102+
textToInsertIntoBody,
103+
...lines.slice(closingBodyTagLineIndex),
90104
].join('\n');
91105

92106
host.overwrite(path, updatedIndex);

packages/angular/pwa/pwa/index_spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ describe('PWA Schematic', () => {
9393

9494
expect(content).toMatch(/<link rel="manifest" href="manifest.json">/);
9595
expect(content).toMatch(/<meta name="theme-color" content="#1976d2">/);
96+
expect(content).toMatch(/<noscript>Please enable Javascript to continue using this application.<\/noscript>/);
9697
});
9798

9899
it('should update the build and test assets configuration', () => {

0 commit comments

Comments
 (0)