chore: minify template html

chore: purge html comments
This commit is contained in:
Zhicheng Wang 2018-09-23 21:11:20 +08:00
parent 8826561b68
commit 4e87ce8688
3 changed files with 10 additions and 778 deletions

View File

@ -1,11 +1 @@
<aio-shell ng-version="6.0.0"
class="mode-stable sidenav-open page-guide-template-syntax folder-guide view-SideNav aio-notification-hide ">
<ul role="navigation"><!---->
<li class="ng-star-inserted"><a class="nav-link" href="/features" title="特性">特性</a></li>
<li class="ng-star-inserted"><a class="nav-link" href="/docs" title="文档">文档</a></li>
<li class="ng-star-inserted"><a class="nav-link" href="/resources" title="资源">资源</a></li>
<li class="ng-star-inserted"><a class="nav-link" href="/events" title="会议">会议</a></li>
<li class="ng-star-inserted"><a class="nav-link" href="https://blog.angular.io/" title="博客">博客</a></li>
<li class="ng-star-inserted"><a class="nav-link" href="/translations/cn/home" title="关于中文版">关于中文版</a></li>
</ul>
</aio-shell>
<aio-shell ng-version="6.0.0" class="mode-stable sidenav-open page-guide-template-syntax folder-guide view-SideNav aio-notification-hide "><ul role="navigation"><li class="ng-star-inserted"><a class="nav-link" href="/features" title="特性">特性</a></li><li class="ng-star-inserted"><a class="nav-link" href="/docs" title="文档">文档</a></li><li class="ng-star-inserted"><a class="nav-link" href="/resources" title="资源">资源</a></li><li class="ng-star-inserted"><a class="nav-link" href="/events" title="会议">会议</a></li><li class="ng-star-inserted"><a class="nav-link" href="https://blog.angular.io/" title="博客">博客</a></li><li class="ng-star-inserted"><a class="nav-link" href="/translations/cn/home" title="关于中文版">关于中文版</a></li></ul></aio-shell>

File diff suppressed because one or more lines are too long

View File

@ -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(/<!--\s*-->/g, '')
.replace(/<!-- links (to|from) this doc[\s\S]*?-->/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('<title>Angular Docs</title>', `<title>${title} - Angular 官方文档</title>`)
.replace('<aio-page-content-placeholder></aio-page-content-placeholder>', 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, `<aio-shell><h3>API List</h3>${links}</aio-shell>`);
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();