mirror of
https://github.com/flutter/samples.git
synced 2025-11-09 06:18:49 +00:00
Update and standardize html, fix gallery on mobile devices
This commit is contained in:
@@ -28,7 +28,7 @@ void main(List<String> args) {
|
|||||||
.listSync()
|
.listSync()
|
||||||
.whereType<File>()
|
.whereType<File>()
|
||||||
.where((f) => p.extension(f.path) == '.html')) {
|
.where((f) => p.extension(f.path) == '.html')) {
|
||||||
_writeAnalytics(htmlFile, buildDir);
|
_updateHtml(htmlFile, buildDir, exampleDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +41,6 @@ void main(List<String> args) {
|
|||||||
_tocTemplate(
|
_tocTemplate(
|
||||||
fileMap.entries.map(
|
fileMap.entries.map(
|
||||||
(entry) => _Demo(
|
(entry) => _Demo(
|
||||||
_prettyName(entry.value),
|
|
||||||
entry.key,
|
entry.key,
|
||||||
entry.value,
|
entry.value,
|
||||||
),
|
),
|
||||||
@@ -50,12 +49,20 @@ void main(List<String> args) {
|
|||||||
flush: true);
|
flush: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _writeAnalytics(File htmlFile, String buildDir) {
|
void _updateHtml(File htmlFile, String buildDir, String exampleDir) {
|
||||||
final content = htmlFile.readAsStringSync();
|
final content = htmlFile.readAsStringSync();
|
||||||
final newContent = content.replaceFirst('<head>', '<head>\n$_analytics');
|
|
||||||
|
|
||||||
final filePath = p.relative(htmlFile.path, from: buildDir);
|
final filePath = p.relative(htmlFile.path, from: buildDir);
|
||||||
|
|
||||||
|
if (!content.contains(_standardMeta)) {
|
||||||
|
print('!!! missing standard meta! - $filePath');
|
||||||
|
}
|
||||||
|
|
||||||
|
final newContent = content
|
||||||
|
.replaceFirst('<head>', '<head>\n$_analytics')
|
||||||
|
.replaceFirst(_emptyTitle,
|
||||||
|
'<title>${_prettyName(exampleDir)} - Flutter web sample</title>');
|
||||||
|
|
||||||
if (newContent == content) {
|
if (newContent == content) {
|
||||||
print('!!! Did not replace contents in $filePath');
|
print('!!! Did not replace contents in $filePath');
|
||||||
} else {
|
} else {
|
||||||
@@ -65,9 +72,9 @@ void _writeAnalytics(File htmlFile, String buildDir) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _Demo {
|
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 {
|
String get content {
|
||||||
final path = p.normalize(p.join(pkgDir, '..', 'README.md'));
|
final path = p.normalize(p.join(pkgDir, '..', 'README.md'));
|
||||||
@@ -98,6 +105,8 @@ class _Demo {
|
|||||||
return markdownToHtml(readmeContent.substring(0, endIndex - 1));
|
return markdownToHtml(readmeContent.substring(0, endIndex - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String get name => _prettyName(buildDir);
|
||||||
|
|
||||||
String get html => '''
|
String get html => '''
|
||||||
<div>
|
<div>
|
||||||
<a href='$buildDir'>
|
<a href='$buildDir'>
|
||||||
@@ -135,12 +144,19 @@ String _indent(String content, int spaces) =>
|
|||||||
|
|
||||||
const _itemsReplace = r'<!-- ITEMS -->';
|
const _itemsReplace = r'<!-- ITEMS -->';
|
||||||
|
|
||||||
|
const _emptyTitle = '<title></title>';
|
||||||
|
|
||||||
|
const _standardMeta = '''
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
$_emptyTitle''';
|
||||||
|
|
||||||
String _tocTemplate(Iterable<_Demo> items) => '''
|
String _tocTemplate(Iterable<_Demo> items) => '''
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
${_indent(_analytics, 2)}
|
${_indent(_analytics, 2)}
|
||||||
<title>Examples</title>
|
$_standardMeta
|
||||||
<meta name="generator" content="https://pub.dartlang.org/packages/peanut">
|
<meta name="generator" content="https://pub.dartlang.org/packages/peanut">
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
@@ -156,7 +172,6 @@ String _tocTemplate(Iterable<_Demo> items) => '''
|
|||||||
}
|
}
|
||||||
#toc {
|
#toc {
|
||||||
text-align: left;
|
text-align: left;
|
||||||
max-width: 1050px;
|
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
align-self: center;
|
align-self: center;
|
||||||
@@ -164,7 +179,6 @@ String _tocTemplate(Iterable<_Demo> items) => '''
|
|||||||
align-content: space-between;
|
align-content: space-between;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
#toc > div {
|
#toc > div {
|
||||||
width: 300px;
|
width: 300px;
|
||||||
padding: 1rem;
|
padding: 1rem;
|
||||||
@@ -172,16 +186,13 @@ String _tocTemplate(Iterable<_Demo> items) => '''
|
|||||||
border: 1px solid rgba(0, 0, 0, 0.125);
|
border: 1px solid rgba(0, 0, 0, 0.125);
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#toc > div img {
|
#toc > div img {
|
||||||
display: block;
|
display: block;
|
||||||
margin: 0 auto 1rem;
|
margin: 0 auto 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.demo-title {
|
.demo-title {
|
||||||
font-size: 1.25rem;
|
font-size: 1.25rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
#toc > div p {
|
#toc > div p {
|
||||||
margin-top: 0.5rem;
|
margin-top: 0.5rem;
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
@@ -189,7 +200,7 @@ String _tocTemplate(Iterable<_Demo> items) => '''
|
|||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h2><a href='https://github.com/flutter/flutter_web'>Flutter for web</a> samples</h2>
|
<h2><a href='https://flutter.dev/web'>Flutter for web</a> samples</h2>
|
||||||
<a href='https://github.com/flutter/samples/tree/master/web'>Sample source code</a>
|
<a href='https://github.com/flutter/samples/tree/master/web'>Sample source code</a>
|
||||||
<div id="toc">
|
<div id="toc">
|
||||||
$_itemsReplace
|
$_itemsReplace
|
||||||
@@ -197,4 +208,6 @@ String _tocTemplate(Iterable<_Demo> items) => '''
|
|||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
'''
|
'''
|
||||||
.replaceAll(_itemsReplace, _indent(items.map((d) => d.html).join('\n'), 4));
|
.replaceFirst(
|
||||||
|
_itemsReplace, _indent(items.map((d) => d.html).join('\n'), 4))
|
||||||
|
.replaceFirst(_emptyTitle, '<title>Flutter for web samples</title>');
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title></title>
|
<title></title>
|
||||||
<script defer src="main.dart.js" type="application/javascript"></script>
|
<script defer src="main.dart.js" type="application/javascript"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title></title>
|
<title></title>
|
||||||
<script defer src="main.dart.js" type="application/javascript"></script>
|
<script defer src="main.dart.js" type="application/javascript"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title></title>
|
<title></title>
|
||||||
<link href="https://fonts.gstatic.com" rel="preconnect" crossorigin>
|
<link href="https://fonts.gstatic.com" rel="preconnect" crossorigin>
|
||||||
<link href="https://fonts.gstatic.com/s/materialicons/v42/flUhRq6tzZclQEJ-Vdg-IuiaDsNcIhQ8tQ.woff2" rel="preload" as="font" crossorigin>
|
<link href="https://fonts.gstatic.com/s/materialicons/v42/flUhRq6tzZclQEJ-Vdg-IuiaDsNcIhQ8tQ.woff2" rel="preload" as="font" crossorigin>
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>Gallery sample - Flutter for web</title>
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<title></title>
|
||||||
<style>
|
<style>
|
||||||
html, body {
|
html, body {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title></title>
|
<title></title>
|
||||||
<script defer src="main.dart.js" type="application/javascript"></script>
|
<script defer src="main.dart.js" type="application/javascript"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title></title>
|
<title></title>
|
||||||
<script defer src="main.dart.js" type="application/javascript"></script>
|
<script defer src="main.dart.js" type="application/javascript"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title></title>
|
<title></title>
|
||||||
<script defer src="main.dart.js" type="application/javascript"></script>
|
<script defer src="main.dart.js" type="application/javascript"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title></title>
|
<title></title>
|
||||||
<script defer src="main.dart.js" type="application/javascript"></script>
|
<script defer src="main.dart.js" type="application/javascript"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title></title>
|
<title></title>
|
||||||
<script defer src="main.dart.js" type="application/javascript"></script>
|
<script defer src="main.dart.js" type="application/javascript"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title></title>
|
<title></title>
|
||||||
<script defer src="main.dart.js" type="application/javascript"></script>
|
<script defer src="main.dart.js" type="application/javascript"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
Reference in New Issue
Block a user