Skip to content

Commit f2874b0

Browse files
committed
Merge pull request #1142 from dart-lang/favicon
add a --favicon flag
2 parents f262be9 + d26cc5e commit f2874b0

File tree

5 files changed

+28
-9
lines changed

5 files changed

+28
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## unreleased
2+
* [enhancement] added a `--favicon` option to specify a favicon to use for the
3+
generated docs
4+
15
## 0.9.3+1
26
* [bug] fix an issue with including duplicated libraries
37

bin/dartdoc.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ main(List<String> arguments) async {
115115
print('');
116116

117117
var generators = await initGenerators(
118-
url, headerFilePaths, footerFilePaths, args['rel-canonical-prefix']);
118+
url, headerFilePaths, footerFilePaths, args['rel-canonical-prefix'],
119+
faviconPath: args['favicon']);
119120

120121
for (var generator in generators) {
121122
generator.onFileCreated.listen(_onProgress);
@@ -204,6 +205,8 @@ ArgParser _createArgsParser() {
204205
'Learn more at https://goo.gl/gktN6F.');
205206
parser.addFlag('include-source',
206207
help: 'Show source code blocks', negatable: true, defaultsTo: true);
208+
parser.addOption('favicon',
209+
help: 'A path to a favicon for the generated docs');
207210
return parser;
208211
}
209212

lib/dartdoc.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,16 @@ final String defaultOutDir = p.join('doc', 'api');
4545

4646
/// Initialize and setup the generators.
4747
Future<List<Generator>> initGenerators(String url, List<String> headerFilePaths,
48-
List<String> footerFilePaths, String relCanonicalPrefix) async {
48+
List<String> footerFilePaths, String relCanonicalPrefix,
49+
{String faviconPath}) async {
4950
return [
5051
await HtmlGenerator.create(
5152
url: url,
5253
headers: headerFilePaths,
5354
footers: footerFilePaths,
5455
relCanonicalPrefix: relCanonicalPrefix,
55-
toolVersion: version)
56+
toolVersion: version,
57+
faviconPath: faviconPath)
5658
];
5759
}
5860

lib/src/html/html_generator.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class HtmlGenerator extends Generator {
3939
final String _relCanonicalPrefix;
4040
final Templates _templates;
4141
final String _toolVersion;
42+
final String faviconPath;
4243

4344
final StreamController<File> _onFileCreated =
4445
new StreamController(sync: true);
@@ -51,23 +52,27 @@ class HtmlGenerator extends Generator {
5152
List<String> headers,
5253
List<String> footers,
5354
String relCanonicalPrefix,
54-
String toolVersion}) async {
55+
String toolVersion,
56+
String faviconPath}) async {
5557
var templates =
5658
await Templates.create(headerPaths: headers, footerPaths: footers);
5759

5860
if (toolVersion == null) {
5961
toolVersion = 'unknown';
6062
}
6163

62-
return new HtmlGenerator._(url, relCanonicalPrefix, templates, toolVersion);
64+
return new HtmlGenerator._(url, relCanonicalPrefix, templates, toolVersion,
65+
faviconPath: faviconPath);
6366
}
6467

6568
HtmlGenerator._(
66-
this._url, this._relCanonicalPrefix, this._templates, this._toolVersion);
69+
this._url, this._relCanonicalPrefix, this._templates, this._toolVersion,
70+
{this.faviconPath});
6771

6872
Future generate(Package package, Directory out) {
6973
return new HtmlGeneratorInstance(_toolVersion, _url, _templates, package,
70-
out, _onFileCreated, _relCanonicalPrefix)
74+
out, _onFileCreated, _relCanonicalPrefix,
75+
faviconPath: faviconPath)
7176
.generate();
7277
}
7378
}

lib/src/html/html_generator_instance.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,25 @@ class HtmlGeneratorInstance implements HtmlOptions {
2424
final StreamController<File> _onFileCreated;
2525
final String relCanonicalPrefix;
2626
final String toolVersion;
27+
final String faviconPath;
2728

2829
HtmlGeneratorInstance(this.toolVersion, this.url, this._templates,
29-
this.package, this.out, this._onFileCreated, this.relCanonicalPrefix);
30+
this.package, this.out, this._onFileCreated, this.relCanonicalPrefix,
31+
{this.faviconPath});
3032

3133
Future generate() async {
3234
if (!out.existsSync()) out.createSync();
3335

3436
if (package != null) {
3537
_generateDocs();
3638
_generateSearchIndex();
37-
// TODO: generate sitemap
3839
}
3940

4041
await _copyResources();
42+
if (faviconPath != null) {
43+
File file = new File(path.join(out.path, 'static-assets', 'favicon.png'));
44+
file.writeAsBytesSync(new File(faviconPath).readAsBytesSync());
45+
}
4146
}
4247

4348
void _generateSearchIndex() {

0 commit comments

Comments
 (0)