From 4e87ce8688cf2aa586010a43443d3a898e91f888 Mon Sep 17 00:00:00 2001 From: Zhicheng Wang Date: Sun, 23 Sep 2018 21:11:20 +0800 Subject: [PATCH] chore: minify template html chore: purge html comments --- .../translator/assets/aio-shell-index.html | 12 +- .../translator/assets/aio-shell-template.html | 765 +----------------- aio/tools/translator/bin/ssr.ts | 11 +- 3 files changed, 10 insertions(+), 778 deletions(-) diff --git a/aio/tools/translator/assets/aio-shell-index.html b/aio/tools/translator/assets/aio-shell-index.html index 7aecd705e6..5d94927cdc 100644 --- a/aio/tools/translator/assets/aio-shell-index.html +++ b/aio/tools/translator/assets/aio-shell-index.html @@ -1,11 +1 @@ - - - + diff --git a/aio/tools/translator/assets/aio-shell-template.html b/aio/tools/translator/assets/aio-shell-template.html index fccdc98b58..31ddd4b7d8 100644 --- a/aio/tools/translator/assets/aio-shell-template.html +++ b/aio/tools/translator/assets/aio-shell-template.html @@ -1,764 +1 @@ - -
- - - - - Version 6 of Angular Now Available! Learn More - - - - - - Home - - - - - -
-
-
- -
-
- - - - - - - - - - - - - - - - - -
-
-
- - - - - - -
-
- -
-
-
-
-
-
- - - -
-
- - - - -
- -
+
Version 6 of Angular Now Available! Learn More Home
\ No newline at end of file diff --git a/aio/tools/translator/bin/ssr.ts b/aio/tools/translator/bin/ssr.ts index c26f27c794..e1d6c1e3ac 100644 --- a/aio/tools/translator/bin/ssr.ts +++ b/aio/tools/translator/bin/ssr.ts @@ -9,6 +9,11 @@ const indexTemplate = fs.readFileSync('./dist/index.html', 'utf-8'); const aioShellTemplate = fs.readFileSync(__dirname + '/../assets/aio-shell-template.html'); const pageTemplate = indexTemplate.replace(rootElementPattern, `${aioShellTemplate}`); +function purge(text: string): string { + return text.replace(//g, '') + .replace(//g, ''); +} + function composePage(url) { const { title, contents } = JSON.parse(fs.readFileSync(`./dist/generated/docs/${url}.json`, 'utf-8')); @@ -20,7 +25,7 @@ function composePage(url) { .replace('Angular Docs', `${title} - Angular 官方文档`) .replace('', ssrContent); mkdirp.sync(path.dirname(`./dist/${url}`)); - fs.writeFileSync(`./dist/${url}.html`, pageContent, 'utf-8'); + fs.writeFileSync(`./dist/${url}.html`, purge(pageContent), 'utf-8'); } function buildGuidePages(): void { @@ -40,14 +45,14 @@ function buildApiPages(): void { const apiListContent = fs.readFileSync('./dist/api.html', 'utf-8') .replace(rootElementPattern, `

API List

${links}
`); - fs.writeFileSync(`./dist/api.html`, apiListContent, 'utf-8'); + fs.writeFileSync(`./dist/api.html`, purge(apiListContent), 'utf-8'); } function buildIndexPage(): void { const indexTemplate = fs.readFileSync('./dist/index.html', 'utf-8'); const aioShellIndex = fs.readFileSync(__dirname + '/../assets/aio-shell-index.html'); const content = indexTemplate.replace(rootElementPattern, `${aioShellIndex}`); - fs.writeFileSync(`./dist/index.html`, content, 'utf-8'); + fs.writeFileSync(`./dist/index.html`, purge(content), 'utf-8'); } buildGuidePages();