1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-09 06:18:49 +00:00

Add samples index (#359)

* add samples_index to web/ directory

Co-authored-by: Thea Flowers <theaflowers@google.com>

* add pub_get.dart script

* build sample index in peanut post build

* re-generate sample index with web demos

* print more details in peanut_post_build.dart

* add images for demos

* run generator

* update README

* add animations and provider shopper as symlinks

* add links to symlinked web demos

* use relative paths

* update cookbook images, urls, and description CSS

* use relative URL for navbar link

* unstage HTML files

* .gitignore generated HTML files

* add margin to toolbar

* rename escape functions

* add and update copyright headers

Co-authored-by: Thea Flowers <theaflowers@google.com>
This commit is contained in:
John Ryan
2020-03-09 16:17:08 -07:00
committed by GitHub
parent efab5b0644
commit 0a5a5109de
183 changed files with 3555 additions and 211 deletions

View File

@@ -0,0 +1,178 @@
// 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
/// Defines the data types for this project.
library data;
import 'package:json_annotation/json_annotation.dart';
import 'package:samples_index/src/util.dart' as util;
part 'data.g.dart';
/// The full list of samples
@JsonSerializable(
// Use anyMap and checked for more useful YAML parsing errors. See
// package:checked_yaml docs for details.
anyMap: true,
checked: true)
class Index {
final List<Sample> samples;
Index(this.samples);
factory Index.fromJson(Map json) => _$IndexFromJson(json);
Map<String, dynamic> toJson() => _$IndexToJson(this);
}
/// A sample to be displayed in the app.
@JsonSerializable(anyMap: true, checked: true)
class Sample {
/// The name of the sample.
final String name;
/// The author of the sample. Typically "Flutter"
final String author;
/// Screenshots of the sample or cookbook article. At least 1 screenshot is
/// required.
final List<Screenshot> screenshots;
/// A link to the source code or cookbook article if type is 'cookbook'.
final String source;
/// A link to this sample running in the browser.
final String web;
/// 3-5 sentences describing the sample.
final String description;
/// The difficulty level. Values are either 'beginner', 'intermediate', or
/// 'advanced'.
final String difficulty;
/// List of widgets or Flutter APIs used by the sample. e.g. "AnimatedBuilder"
/// or "ChangeNotifier".
final List<String> widgets;
/// List of packages or Flutter libraries used by the sample. third-party
/// packages.
final List<String> packages;
/// Arbitrary tags to associate with this sample.
final List<String> tags;
/// Supported platforms. Values are either 'ios', 'android', 'desktop', and
/// 'web'
final List<String> platforms;
/// Links to display on the details page
final List<Link> links;
/// The type of the sample. Supported values are either 'sample' or
/// 'cookbook'.
final String type;
/// The date this sample was created.
final DateTime date;
/// The Flutter channel this sample runs on. Either 'stable', 'dev' or
/// 'master'.
final String channel;
Sample({
this.name,
this.author,
this.screenshots,
this.source,
this.web,
this.description,
this.difficulty,
this.widgets = const [],
this.packages = const [],
this.tags = const [],
this.platforms = const [],
this.links = const [],
this.type,
this.date,
this.channel,
});
factory Sample.fromJson(Map json) => _$SampleFromJson(json);
Map<String, dynamic> toJson() => _$SampleToJson(this);
String get searchAttributes {
var buf = StringBuffer();
buf.write(name.toLowerCase());
buf.write(' ');
for (var tag in tags) {
buf.write('tag:${tag.toLowerCase()} ');
// Allow tags to be searched without the tag: prefix
buf.write('${tag.toLowerCase()} ');
}
for (var platform in platforms) {
buf.write('platform:$platform ');
// Allow platforms to be searched without the tag: prefix
buf.write('$platform ');
}
for (var widget in widgets) {
buf.write('widget:$widget ');
}
for (var package in packages) {
buf.write('package:$package ');
}
buf.write('type:$type ');
return buf.toString().trim();
}
String get filename {
var nameWithoutChars = name.replaceAll(RegExp(r'[^A-Za-z0-9\-\_\ ]'), '');
var nameWithUnderscores = nameWithoutChars.replaceAll(' ', '_');
var snake = util.snakeCase(nameWithUnderscores);
var s = snake.replaceAll('__', '_');
return s;
}
String get shortDescription {
if (description.length < 64) {
return description;
}
return description.substring(0, 64) + '...';
}
}
/// A screenshot of a sample
@JsonSerializable(anyMap: true, checked: true)
class Screenshot {
final String url;
final String alt;
Screenshot(this.url, this.alt);
factory Screenshot.fromJson(Map json) => _$ScreenshotFromJson(json);
Map<String, dynamic> toJson() => _$ScreenshotToJson(this);
}
/// An external link displayed next to a sample
@JsonSerializable(anyMap: true, checked: true)
class Link {
final String text;
final String href;
Link(this.text, this.href);
factory Link.fromJson(Map json) => _$LinkFromJson(json);
Map<String, dynamic> toJson() => _$LinkToJson(this);
}