Adds favicon to Dash/Zeal docset, adds OpenSearch metadata. (#25178)

This sets the favicon for the offline Dash/Zeal docs.

Also, sets up the OpenSearch Description metadata file so that people can create custom search shortcuts for the API docs site.

Fixes #6412
This commit is contained in:
Greg Spencer 2018-12-11 09:53:33 -08:00 committed by GitHub
parent b080a476c8
commit 625a37b86a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 10 deletions

View file

@ -47,6 +47,7 @@ function create_docset() {
echo "Building Flutter docset."
rm -rf flutter.docset
(dashing build --source ./doc --config ./dashing.json > /tmp/dashing.log 2>&1 || (tail -100 /tmp/dashing.log; false)) && \
cp ./doc/flutter/static-assets/favicon.png ./flutter.docset/icon.png && \
tar cf flutter.docset.tar.gz --use-compress-program="gzip --best" flutter.docset
}
@ -62,7 +63,7 @@ function move_offline_into_place() {
if [[ "$CIRRUS_BRANCH" == "stable" ]]; then
echo -e "<entry>\n <version>${FLUTTER_VERSION}</version>\n <url>https://docs.flutter.io/offline/flutter.docset.tar.gz</url>\n</entry>" > doc/offline/flutter.xml
else
echo -e "<entry>\n <version>${FLUTTER_VERSION}</version>\n <url>https://master-docs-flutter-io.firebaseapp.com/offline/flutter.docset.tar.gz</url>\n</entry>" > doc/offline/flutter.xml
echo -e "<entry>\n <version>${FLUTTER_VERSION}</version>\n <url>https://master-docs.flutter.io/offline/flutter.docset.tar.gz</url>\n</entry>" > doc/offline/flutter.xml
fi
mv flutter.docset.tar.gz doc/offline/flutter.docset.tar.gz
du -sh doc/offline/flutter.docset.tar.gz
@ -123,7 +124,7 @@ cp "$FLUTTER_ROOT/dev/docs/google2ed1af765c529f57.html" "$FLUTTER_ROOT/dev/docs/
if [[ -n "$CIRRUS_CI" && -z "$CIRRUS_PR" ]]; then
echo "This is not a pull request; considering whether to upload docs... (branch=$CIRRUS_BRANCH)"
if [[ "$CIRRUS_BRANCH" == "master" ]]; then
echo "Updating $CIRRUS_BRANCH docs: https://master-docs-flutter-io.firebaseapp.com/"
echo "Updating $CIRRUS_BRANCH docs: https://master-docs.flutter.io/"
# Disable search indexing on the master staging site so searches get only
# the stable site.
echo -e "User-agent: *\nDisallow: /" > "$FLUTTER_ROOT/dev/docs/doc/robots.txt"

View file

@ -0,0 +1,14 @@
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">
<ShortName>Flutter API</ShortName>
<Description>
Welcome to the Flutter API reference documentation search.
Flutter is Googles mobile UI framework for crafting high-quality native interfaces on iOS and Android in record time.
Flutter works with existing code, is used by developers and organizations around the world, and is free and open source.
The API reference herein covers all libraries that are exported by the Flutter SDK.
</Description>
<InputEncoding>UTF-8</InputEncoding>
<Image width="32" height="32" type="image/x-icon">/flutter/static-assets/favicon.png</Image>
<Url type="text/html" method="get" template="{SITE_URL}?search={searchTerms}"/>
</OpenSearchDescription>

1
dev/docs/opensearch.html Normal file
View file

@ -0,0 +1 @@
<link rel="search" type="application/opensearchdescription+xml" title="Flutter API" href="/opensearch.xml"/>

View file

@ -100,6 +100,7 @@ Future<void> main(List<String> arguments) async {
createFooter('$kDocsRoot/lib/footer.html');
copyAssets();
createSearchMetadata('$kDocsRoot/lib/opensearch.xml', '$kDocsRoot/doc/opensearch.xml');
cleanOutSnippets();
final List<String> dartdocBaseArgs = <String>['global', 'run'];
@ -134,6 +135,7 @@ Future<void> main(List<String> arguments) async {
'--header', 'analytics.html',
'--header', 'survey.html',
'--header', 'snippets.html',
'--header', 'opensearch.html',
'--footer-text', 'lib/footer.html',
'--exclude-packages',
<String>[
@ -231,20 +233,25 @@ ArgParser _createArgsParser() {
final RegExp gitBranchRegexp = RegExp(r'^## (.*)');
String getBranchName() {
final ProcessResult gitResult = Process.runSync('git', <String>['status', '-b', '--porcelain']);
if (gitResult.exitCode != 0)
throw 'git status exit with non-zero exit code: ${gitResult.exitCode}';
final Match gitBranchMatch = gitBranchRegexp.firstMatch(
gitResult.stdout.trim().split('\n').first);
return gitBranchMatch == null ? '' : gitBranchMatch.group(1).split('...').first;
}
void createFooter(String footerPath) {
const int kGitRevisionLength = 10;
ProcessResult gitResult = Process.runSync('git', <String>['rev-parse', 'HEAD']);
final ProcessResult gitResult = Process.runSync('git', <String>['rev-parse', 'HEAD']);
if (gitResult.exitCode != 0)
throw 'git rev-parse exit with non-zero exit code: ${gitResult.exitCode}';
String gitRevision = gitResult.stdout.trim();
gitResult = Process.runSync('git', <String>['status', '-b', '--porcelain']);
if (gitResult.exitCode != 0)
throw 'git status exit with non-zero exit code: ${gitResult.exitCode}';
final Match gitBranchMatch = gitBranchRegexp.firstMatch(
gitResult.stdout.trim().split('\n').first);
final String gitBranchOut = gitBranchMatch == null ? '' : '• </span class="no-break">${gitBranchMatch.group(1).split('...').first}</span>';
final String gitBranch = getBranchName();
final String gitBranchOut = gitBranch.isEmpty ? '' : '• </span class="no-break">$gitBranch</span>';
gitRevision = gitRevision.length > kGitRevisionLength ? gitRevision.substring(0, kGitRevisionLength) : gitRevision;
@ -256,6 +263,21 @@ void createFooter(String footerPath) {
gitBranchOut].join(' '));
}
/// Generates an OpenSearch XML description that can be used to add a custom
/// search for Flutter API docs to the browser. Unfortunately, it has to know
/// the URL to which site to search, so we customize it here based upon the
/// branch name.
void createSearchMetadata(String templatePath, String metadataPath) {
final String template = File(templatePath).readAsStringSync();
final String branch = getBranchName();
final String metadata = template.replaceAll(
'{SITE_URL}',
branch == 'stable' ? 'https://docs.flutter.io/' : 'https://master-docs.flutter.io/',
);
Directory(path.dirname(metadataPath)).create(recursive: true);
File(metadataPath).writeAsStringSync(metadata);
}
/// Recursively copies `srcDir` to `destDir`, invoking [onFileCopied], if
/// specified, for each source/destination file pair.
///
@ -292,7 +314,8 @@ void copyAssets() {
(File src, File dest) => print('Copied ${src.path} to ${dest.path}'));
}
/// Clean out any existing snippets so that we don't publish old files from
/// previous runs accidentally.
void cleanOutSnippets() {
final Directory snippetsDir = Directory(path.join(kPublishRoot, 'snippets'));
if (snippetsDir.existsSync()) {