From e0434bac2f1082880926fd6c77ff486989bd2149 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 7 May 2019 17:22:44 -0700 Subject: [PATCH] Update and standardize html, fix gallery on mobile devices --- web/_tool/peanut_post_build.dart | 41 +++++++++++++++++--------- web/charts/example/web/index.html | 1 + web/filipino_cuisine/web/index.html | 1 + web/gallery/web/frame.html | 1 + web/gallery/web/index.html | 3 +- web/github_dataviz/web/index.html | 1 + web/particle_background/web/index.html | 1 + web/slide_puzzle/web/index.html | 1 + web/spinning_square/web/index.html | 1 + web/timeflow/web/index.html | 1 + web/vision_challenge/web/index.html | 1 + 11 files changed, 38 insertions(+), 15 deletions(-) diff --git a/web/_tool/peanut_post_build.dart b/web/_tool/peanut_post_build.dart index c3892331c..9c14ea3b3 100644 --- a/web/_tool/peanut_post_build.dart +++ b/web/_tool/peanut_post_build.dart @@ -28,7 +28,7 @@ void main(List args) { .listSync() .whereType() .where((f) => p.extension(f.path) == '.html')) { - _writeAnalytics(htmlFile, buildDir); + _updateHtml(htmlFile, buildDir, exampleDir); } } @@ -41,7 +41,6 @@ void main(List args) { _tocTemplate( fileMap.entries.map( (entry) => _Demo( - _prettyName(entry.value), entry.key, entry.value, ), @@ -50,12 +49,20 @@ void main(List args) { flush: true); } -void _writeAnalytics(File htmlFile, String buildDir) { +void _updateHtml(File htmlFile, String buildDir, String exampleDir) { final content = htmlFile.readAsStringSync(); - final newContent = content.replaceFirst('', '\n$_analytics'); final filePath = p.relative(htmlFile.path, from: buildDir); + if (!content.contains(_standardMeta)) { + print('!!! missing standard meta! - $filePath'); + } + + final newContent = content + .replaceFirst('', '\n$_analytics') + .replaceFirst(_emptyTitle, + '${_prettyName(exampleDir)} - Flutter web sample'); + if (newContent == content) { print('!!! Did not replace contents in $filePath'); } else { @@ -65,9 +72,9 @@ void _writeAnalytics(File htmlFile, String buildDir) { } class _Demo { - final String name, pkgDir, buildDir; + final String pkgDir, buildDir; - _Demo(this.name, this.pkgDir, this.buildDir); + _Demo(this.pkgDir, this.buildDir); String get content { final path = p.normalize(p.join(pkgDir, '..', 'README.md')); @@ -98,6 +105,8 @@ class _Demo { return markdownToHtml(readmeContent.substring(0, endIndex - 1)); } + String get name => _prettyName(buildDir); + String get html => '''
@@ -135,12 +144,19 @@ String _indent(String content, int spaces) => const _itemsReplace = r''; +const _emptyTitle = ''; + +const _standardMeta = ''' + + + $_emptyTitle'''; + String _tocTemplate(Iterable<_Demo> items) => ''' ${_indent(_analytics, 2)} - Examples +$_standardMeta -

Flutter for web samples

+

Flutter for web samples

Sample source code
$_itemsReplace @@ -197,4 +208,6 @@ String _tocTemplate(Iterable<_Demo> items) => ''' ''' - .replaceAll(_itemsReplace, _indent(items.map((d) => d.html).join('\n'), 4)); + .replaceFirst( + _itemsReplace, _indent(items.map((d) => d.html).join('\n'), 4)) + .replaceFirst(_emptyTitle, 'Flutter for web samples'); diff --git a/web/charts/example/web/index.html b/web/charts/example/web/index.html index b54ed98d8..1785ebb8b 100644 --- a/web/charts/example/web/index.html +++ b/web/charts/example/web/index.html @@ -2,6 +2,7 @@ + diff --git a/web/filipino_cuisine/web/index.html b/web/filipino_cuisine/web/index.html index b54ed98d8..1785ebb8b 100644 --- a/web/filipino_cuisine/web/index.html +++ b/web/filipino_cuisine/web/index.html @@ -2,6 +2,7 @@ + diff --git a/web/gallery/web/frame.html b/web/gallery/web/frame.html index 29b0cd889..6e2549210 100644 --- a/web/gallery/web/frame.html +++ b/web/gallery/web/frame.html @@ -2,6 +2,7 @@ + diff --git a/web/gallery/web/index.html b/web/gallery/web/index.html index 3cda94763..9e054ef45 100644 --- a/web/gallery/web/index.html +++ b/web/gallery/web/index.html @@ -2,7 +2,8 @@ - Gallery sample - Flutter for web + +