Simplify samples index and remove cookbook recipes (#2102)
Remove the cookbook recipes from the samples index in a step to eventually remove it as a whole. The cookbook recipe listings in the index haven't been updated in a long time, the support for updating them doesn't work, and this isn't generally how people are finding cookbook recipes. This has the added benefit of reducing repo size quite a bit due to the large images.pull/2103/head
@ -1,3 +0,0 @@
|
||||
## 1.0.0
|
||||
|
||||
- Initial version, created by Stagehand
|
@ -1,86 +0,0 @@
|
||||
// Copyright 2020 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:html/parser.dart' show parse;
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:samples_index/src/data.dart';
|
||||
|
||||
/// Utilities for generating cookbook article data
|
||||
import 'package:webdriver/async_io.dart';
|
||||
|
||||
class CookbookScraper {
|
||||
late WebDriver _driver;
|
||||
|
||||
Future<void> init() async {
|
||||
_driver = await createDriver(desired: <String, dynamic>{});
|
||||
}
|
||||
|
||||
Future<void> dispose() async {
|
||||
await _driver.quit();
|
||||
}
|
||||
|
||||
Future<List<String>> fetchCookbookLinks() async {
|
||||
var flutterUrl = 'https://flutter.dev';
|
||||
var url = Uri.parse('$flutterUrl/docs/cookbook');
|
||||
await _driver.get(url);
|
||||
var pageContent = await _driver.pageSource;
|
||||
var page = parse(pageContent);
|
||||
var links = page.querySelectorAll('main>.container>ul>li>a');
|
||||
return links.map((e) => '$flutterUrl${e.attributes["href"]}').toList();
|
||||
}
|
||||
|
||||
Future<Sample> getMetadata(String url) async {
|
||||
await _driver.get(Uri.parse(url));
|
||||
var pageContent = await _driver.pageSource;
|
||||
var page = parse(pageContent);
|
||||
var search = 'main>.container>header>h1';
|
||||
var h1 = page.querySelector(search);
|
||||
if (h1 == null) {
|
||||
throw ('Could not find match for $search on page $url');
|
||||
}
|
||||
var name = h1.text;
|
||||
var description = page.querySelectorAll('main>.container>p').first.text;
|
||||
|
||||
var urlSegments = Uri.parse(url).pathSegments;
|
||||
var category = urlSegments[urlSegments.length - 2];
|
||||
|
||||
return Sample(
|
||||
name: name,
|
||||
description: description,
|
||||
author: 'Flutter',
|
||||
type: 'cookbook',
|
||||
screenshots: [Screenshot(screenshotPath(url), 'Cookbook article')],
|
||||
tags: ['cookbook', category],
|
||||
source: url,
|
||||
difficulty: 'advanced',
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> takeScreenshot(String url) async {
|
||||
var screenshot = await _driver.captureScreenshotAsList();
|
||||
var file = File('web/${screenshotPath(url)}');
|
||||
await file.create(recursive: true);
|
||||
await file.writeAsBytes(screenshot);
|
||||
}
|
||||
}
|
||||
|
||||
String screenshotPath(String url) {
|
||||
var filename = parseFileName(url);
|
||||
return 'images/cookbook/$filename.png';
|
||||
}
|
||||
|
||||
/// Parses a filename from a cookbook link. E.g.
|
||||
/// `https://flutter.dev/docs/cookbook/navigation/returning-data.html` changes
|
||||
/// to `returning_data.png`
|
||||
String parseFileName(String link) {
|
||||
var p = path.basename(link);
|
||||
var dot = p.indexOf('.');
|
||||
var detailName = p.substring(0, dot);
|
||||
// var categoryName = path.split(link);
|
||||
var components = path.split(link);
|
||||
var categoryName = components[components.length - 2];
|
||||
return '$categoryName-$detailName';
|
||||
}
|
Before Width: | Height: | Size: 706 KiB |
Before Width: | Height: | Size: 498 KiB |
Before Width: | Height: | Size: 408 KiB |
Before Width: | Height: | Size: 432 KiB |
Before Width: | Height: | Size: 429 KiB |
Before Width: | Height: | Size: 583 KiB |
Before Width: | Height: | Size: 646 KiB |
Before Width: | Height: | Size: 462 KiB |
Before Width: | Height: | Size: 552 KiB |
Before Width: | Height: | Size: 438 KiB |
Before Width: | Height: | Size: 445 KiB |
Before Width: | Height: | Size: 428 KiB |
Before Width: | Height: | Size: 443 KiB |
Before Width: | Height: | Size: 435 KiB |
Before Width: | Height: | Size: 377 KiB |
Before Width: | Height: | Size: 418 KiB |
Before Width: | Height: | Size: 584 KiB |
Before Width: | Height: | Size: 592 KiB |
Before Width: | Height: | Size: 638 KiB |
Before Width: | Height: | Size: 555 KiB |
Before Width: | Height: | Size: 602 KiB |
Before Width: | Height: | Size: 613 KiB |
Before Width: | Height: | Size: 731 KiB |
Before Width: | Height: | Size: 648 KiB |
Before Width: | Height: | Size: 597 KiB |
Before Width: | Height: | Size: 468 KiB |
Before Width: | Height: | Size: 397 KiB |
Before Width: | Height: | Size: 475 KiB |
Before Width: | Height: | Size: 389 KiB |
Before Width: | Height: | Size: 439 KiB |
Before Width: | Height: | Size: 411 KiB |
Before Width: | Height: | Size: 389 KiB |
Before Width: | Height: | Size: 374 KiB |
Before Width: | Height: | Size: 538 KiB |
Before Width: | Height: | Size: 550 KiB |
Before Width: | Height: | Size: 608 KiB |
Before Width: | Height: | Size: 461 KiB |
Before Width: | Height: | Size: 404 KiB |
Before Width: | Height: | Size: 406 KiB |
Before Width: | Height: | Size: 372 KiB |
Before Width: | Height: | Size: 444 KiB |
Before Width: | Height: | Size: 479 KiB |
Before Width: | Height: | Size: 436 KiB |
Before Width: | Height: | Size: 688 KiB |
Before Width: | Height: | Size: 582 KiB |
Before Width: | Height: | Size: 341 KiB |
Before Width: | Height: | Size: 471 KiB |
Before Width: | Height: | Size: 405 KiB |
Before Width: | Height: | Size: 349 KiB |
Before Width: | Height: | Size: 401 KiB |
Before Width: | Height: | Size: 402 KiB |
Before Width: | Height: | Size: 555 KiB |
Before Width: | Height: | Size: 496 KiB |
Before Width: | Height: | Size: 600 KiB |
Before Width: | Height: | Size: 644 KiB |
Before Width: | Height: | Size: 619 KiB |
Before Width: | Height: | Size: 669 KiB |
Before Width: | Height: | Size: 612 KiB |
Before Width: | Height: | Size: 416 KiB |
Before Width: | Height: | Size: 436 KiB |
Before Width: | Height: | Size: 480 KiB |
Before Width: | Height: | Size: 432 KiB |
Before Width: | Height: | Size: 497 KiB |
Before Width: | Height: | Size: 457 KiB |
Before Width: | Height: | Size: 532 KiB |
Before Width: | Height: | Size: 392 KiB |
Before Width: | Height: | Size: 470 KiB |
Before Width: | Height: | Size: 372 KiB |
Before Width: | Height: | Size: 444 KiB |
Before Width: | Height: | Size: 425 KiB |
Before Width: | Height: | Size: 449 KiB |
Before Width: | Height: | Size: 464 KiB |
Before Width: | Height: | Size: 598 KiB |
Before Width: | Height: | Size: 602 KiB |
Before Width: | Height: | Size: 590 KiB |
Before Width: | Height: | Size: 626 KiB |
Before Width: | Height: | Size: 644 KiB |
Before Width: | Height: | Size: 424 KiB |
Before Width: | Height: | Size: 415 KiB |
Before Width: | Height: | Size: 479 KiB |
Before Width: | Height: | Size: 590 KiB |
Before Width: | Height: | Size: 604 KiB |
Before Width: | Height: | Size: 616 KiB |
Before Width: | Height: | Size: 474 KiB |
Before Width: | Height: | Size: 460 KiB |
Before Width: | Height: | Size: 718 KiB |
Before Width: | Height: | Size: 656 KiB |