Skip to content

Commit aaea637

Browse files
authored
Use _category name_ in the URL, instead of the _category displayName_. (#4031)
Also clarify documentation, to make it a bit more obvious that a category has two names: * _category name_, the thing we reference in source code, * _display name_, the thing we display in HTML. I imagine that the _category name_ lends itself better to be used in a URL (probably using underscore). And the _display name_ is probably something using whitespaces (which don't work nearly as well in a URL). Also correct `name` -> `displayName` in README. -------------- I don't know if we should make _redirect pages_ for the old URLs. It's perhaps overkill, since the category feature isn't used by most packages. Does `api.dart.dev` or `api.flutter.dev` have topic pages?
1 parent 0388c64 commit aaea637

File tree

6 files changed

+29
-21
lines changed

6 files changed

+29
-21
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 8.3.4-wip
2+
* The URL for category pages now uses _category name_ instead of
3+
_category `displayName`_.
4+
15
## 8.3.3
26

37
* Require Dart 3.6 or later.

README.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,21 +109,21 @@ its children that have the `@nodoc` tag in the documentation comment.
109109

110110
### dartdoc_options.yaml
111111

112-
Creating a file named dartdoc_options.yaml at the top of your package can change how Dartdoc
112+
Creating a file named `dartdoc_options.yaml` at the top of your package can change how Dartdoc
113113
generates docs.
114114

115115
An example (not necessarily recommended settings):
116116

117117
```yaml
118118
dartdoc:
119119
categories:
120-
"First Category":
120+
awesome:
121121
markdown: doc/First.md
122-
name: Awesome
123-
"Second Category":
122+
displayName: Awesome
123+
great:
124124
markdown: doc/Second.md
125-
name: Great
126-
categoryOrder: ["First Category", "Second Category"]
125+
displayName: Great
126+
categoryOrder: [awesome, great]
127127
includeExternal: ['bin/unusually_located_library.dart']
128128
nodoc: ['lib/sekret/*.dart']
129129
linkTo:
@@ -137,17 +137,20 @@ dartdoc:
137137
- tool-error
138138
```
139139
140-
#### dartdoc_options.yaml fields
140+
#### `dartdoc_options.yaml` fields
141141

142142
In general, **paths are relative** to the directory of the `dartdoc_options.yaml` file in which the option
143143
is defined, and should be specified as POSIX paths. Dartdoc will convert POSIX paths automatically on Windows.
144144
Unrecognized options will be ignored. Supported options:
145145

146-
* **categories**: More details for each category/topic. For topics you'd like to document, specify
147-
the markdown file with `markdown:` to use for the category page. Optionally, rename the
148-
category from the source code into a display name with `name:`. If there is no matching category
149-
defined in dartdoc_options.yaml, those declared categories in the source code will be invisible.
150-
* **categoryOrder**: Specify the order of topics for display in the sidebar and
146+
* **categories**: A map from _category names_ to _category definitions_.
147+
The _category definition_ consists of a `markdown:` property and an optional `displayName:` property.
148+
For topics you'd like to document, specify a _markdown file_ to be rendered on the category page,
149+
using the `markdown:` property.
150+
Optionally, you may specify a `displayName:` to be used in the rendered HTML, instead of the _category name_.
151+
Categories are referenced in documentation comments using the `{@category <category name>}` tag.
152+
Categories with no matching _category name_ defined in `dartdoc_options.yaml` will be invisible.
153+
* **categoryOrder**: A list of _category names_ specifying the order of topics for display in the sidebar and
151154
the package page.
152155
* **exclude**: Specify a list of library names to avoid generating docs for,
153156
overriding any specified in include. All libraries listed must be local to this package, unlike
@@ -210,12 +213,12 @@ You can tag libraries or top level classes, functions, and variables in their do
210213
the string `{@category YourCategory}`. For libraries, that will cause the library to appear in a
211214
category when showing the sidebar on the Package and Library pages. For other types of objects,
212215
the `{@category}` will be shown with a link to the category page **but only if specified in
213-
dartdoc_options.yaml**, as above.
216+
`dartdoc_options.yaml`**, as above.
214217

215218
```dart
216219
/// Here is my library.
217220
///
218-
/// {@category Amazing}
221+
/// {@category awesome}
219222
library my_library;
220223
```
221224

dartdoc_options.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
dartdoc:
22
linkToSource:
33
root: '.'
4-
uriTemplate: 'https://github.com/dart-lang/dartdoc/blob/v8.3.3/%f%#L%l%'
4+
uriTemplate: 'https://github.com/dart-lang/dartdoc/blob/v8.3.4-wip/%f%#L%l%'

lib/src/model/category.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
65
import 'package:analyzer/dart/element/element2.dart';
76
import 'package:analyzer/file_system/file_system.dart';
87
import 'package:dartdoc/src/dartdoc_options.dart';
@@ -78,7 +77,6 @@ class Category
7877
}
7978
}
8079

81-
8280
@override
8381
Element2? get element => null;
8482

@@ -107,7 +105,10 @@ class Category
107105
late final bool isDocumented =
108106
documentedWhere != DocumentLocation.missing && documentationFile != null;
109107

110-
String get filePath => 'topics/$name-topic.html';
108+
String get filePath {
109+
assert(_name != null);
110+
return 'topics/$_name-topic.html';
111+
}
111112

112113
@override
113114
String? get href => isCanonical ? '${package.baseHref}$filePath' : null;

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: dartdoc
2-
version: 8.3.3
2+
version: 8.3.4-wip
33
description: A non-interactive HTML documentation generator for Dart source code.
44
repository: https://github.com/dart-lang/dartdoc
55

test/end2end/model_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,13 +720,13 @@ void main() async {
720720
expect(
721721
category.categoryLabel,
722722
'<span class="category superb cp-0 linked" title="This is part of the Superb topic.">'
723-
'<a href="${htmlBasePlaceholder}topics/Superb-topic.html">Superb</a></span>');
723+
'<a href="${htmlBasePlaceholder}topics/Excellent-topic.html">Superb</a></span>');
724724
});
725725

726726
test('CategoryRendererHtml renders linkedName', () {
727727
var category = packageGraph.publicPackages.first.categories.first;
728728
expect(category.linkedName,
729-
'<a href="${htmlBasePlaceholder}topics/Superb-topic.html">Superb</a>');
729+
'<a href="${htmlBasePlaceholder}topics/Excellent-topic.html">Superb</a>');
730730
});
731731
});
732732

0 commit comments

Comments
 (0)