mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 13:58:47 +00:00
Samples maintenance (#435)
This commit is contained in:
@@ -40,7 +40,7 @@ class CookbookScraper {
|
||||
var description = page.querySelectorAll('main>.container>p').first.text;
|
||||
|
||||
var urlSegments = Uri.parse(url).pathSegments;
|
||||
var category = urlSegments[urlSegments.length-2];
|
||||
var category = urlSegments[urlSegments.length - 2];
|
||||
|
||||
return Sample(
|
||||
name: name,
|
||||
|
||||
@@ -147,7 +147,7 @@ class Sample {
|
||||
var nameWithoutChars = name.replaceAll(RegExp(r'[^A-Za-z0-9\-\_\ ]'), '');
|
||||
var nameWithUnderscores = nameWithoutChars.replaceAll(' ', '_');
|
||||
var snake = util.snakeCase(nameWithUnderscores);
|
||||
var s = snake.replaceAll('__', '_');
|
||||
var s = snake.replaceAll('__', '_');
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@ import 'util.dart' as util;
|
||||
|
||||
String _escapeAttribute(String s) =>
|
||||
HtmlEscape(HtmlEscapeMode.attribute).convert(s);
|
||||
String _escapeElement(String s) => HtmlEscape(HtmlEscapeMode.element).convert(s);
|
||||
String _escapeElement(String s) =>
|
||||
HtmlEscape(HtmlEscapeMode.element).convert(s);
|
||||
|
||||
String description(Sample sample) => '''
|
||||
<!DOCTYPE html>
|
||||
@@ -184,19 +185,24 @@ String _descriptionPage(Sample sample) => '''
|
||||
String _descriptionButtons(Sample sample) {
|
||||
var buf = StringBuffer();
|
||||
if (sample?.web?.isNotEmpty == true) {
|
||||
buf.write('''<button class="mdc-button mdc-button--outlined" onclick="window.location.href = '${sample.web}';"><span class="mdc-button__ripple"></span> Launch App</button>''');
|
||||
buf.write(
|
||||
'''<button class="mdc-button mdc-button--outlined" onclick="window.location.href = '${sample.web}';"><span class="mdc-button__ripple"></span> Launch App</button>''');
|
||||
}
|
||||
|
||||
if (sample.type == 'app' || sample.type == 'sample' || sample.type == 'demo') {
|
||||
buf.write('''<button class="mdc-button mdc-button--outlined" onclick="window.location.href = '${sample.source}';">
|
||||
if (sample.type == 'app' ||
|
||||
sample.type == 'sample' ||
|
||||
sample.type == 'demo') {
|
||||
buf.write(
|
||||
'''<button class="mdc-button mdc-button--outlined" onclick="window.location.href = '${sample.source}';">
|
||||
<div class="mdc-button__ripple"></div>
|
||||
<i class="material-icons mdc-button__icon" aria-hidden="true">code</i>
|
||||
<span class="mdc-button__label">Source Code</span>
|
||||
</button>''');
|
||||
}
|
||||
|
||||
if (sample.type =='cookbook') {
|
||||
buf.write('''<button class="mdc-button mdc-button--outlined" onclick="window.location.href = '${sample.source}';"> <span class="mdc-button__ripple"></span>View Recipe</button>''');
|
||||
if (sample.type == 'cookbook') {
|
||||
buf.write(
|
||||
'''<button class="mdc-button mdc-button--outlined" onclick="window.location.href = '${sample.source}';"> <span class="mdc-button__ripple"></span>View Recipe</button>''');
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
@@ -219,4 +225,4 @@ String _descriptionScreenshots(Sample sample) {
|
||||
|
||||
String _descriptionText(Sample sample) {
|
||||
return '<p>${sample.description}</p>';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,4 +30,4 @@ String _fixCase(String input, String separator) =>
|
||||
}
|
||||
|
||||
return lower;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17,7 +17,7 @@ dependencies:
|
||||
html: ^0.14.0
|
||||
dev_dependencies:
|
||||
grinder: ^0.8.3
|
||||
pedantic: ^1.8.0
|
||||
pedantic: ^1.9.0
|
||||
test: ^1.6.0
|
||||
json_serializable: ^3.2.0
|
||||
build: ^1.2.0
|
||||
|
||||
@@ -62,8 +62,8 @@ Future generate() async {
|
||||
Future scrapeCookbook() async {
|
||||
var driver = await Process.start(
|
||||
'chromedriver', ['--port=4444', '--url-base=wd/hub', '--verbose']);
|
||||
driver.stdout.pipe(stdout);
|
||||
driver.stderr.pipe(stderr);
|
||||
await driver.stdout.pipe(stdout);
|
||||
await driver.stderr.pipe(stderr);
|
||||
var scraper = CookbookScraper();
|
||||
await scraper.init();
|
||||
var links = await scraper.fetchCookbookLinks();
|
||||
|
||||
Reference in New Issue
Block a user