@@ -16,25 +16,36 @@ import 'views/account/unauthorized.dart';
1616import 'views/page/error.dart' ;
1717import 'views/page/standalone.dart' ;
1818
19- /// The content of `/doc/api.md`
20- final _apiMarkdown = _readDocContent ('api.md' );
21-
2219/// The content of `/doc/policy.md`
2320final _policyMarkdown = _readDocContent ('policy.md' );
2421
2522/// The content of `/doc/security.md`
2623final _securityMarkdown = _readDocContent ('security.md' );
2724
28- /// The content of `/doc/help.md`
29- final _helpMarkdown = _readDocContent ('help.md' );
30-
31- /// The content of `/doc/help-*.md`
32- final _helpScoringMarkdown = _readDocContent ('help-scoring.md' );
33- final _helpSearchMarkdown = _readDocContent ('help-search.md' );
34- final _helpPublishingMarkdown = _readDocContent ('help-publishing.md' );
35- final _helpContentModerationMarkdown = _readDocContent (
36- 'help-content-moderation.md' ,
37- );
25+ /// Loads help articles and stores them as a map with their
26+ /// basename as a key, e.g.:
27+ /// - `help.md` -> (title: 'Help', content: ...)
28+ /// - `help-search.md` -> (title: 'Search', content: ...)
29+ late final _helpArticles = () {
30+ final docDir = io.Directory (static_files.resolveDocDirPath ());
31+ final files = docDir
32+ .listSync ()
33+ .whereType< io.File > ()
34+ .where ((f) => f.path.endsWith ('.md' ));
35+ final results = < String , ({String ? title, d.Node content})> {};
36+ for (final file in files) {
37+ final basename = p.basename (file.path);
38+ if (basename == 'help.md' || basename.startsWith ('help-' )) {
39+ final content = file.readAsStringSync ();
40+ final firstLine = content.split ('\n ' ).first.trim ();
41+ final title = firstLine.startsWith ('# ' )
42+ ? firstLine.substring (2 ).trim ().replaceAll ('`' , '' )
43+ : null ;
44+ results[basename] = (title: title, content: _readDocContent (basename));
45+ }
46+ }
47+ return results;
48+ }();
3849
3950late final _sideImage = d.Image .decorative (
4051 src: static_files.staticUrls.packagesSideImage,
@@ -62,81 +73,21 @@ String renderUnauthorizedPage() {
6273 );
6374}
6475
65- /// Renders the `doc/api.md` .
66- String renderHelpApiPage () {
67- return renderLayoutPage (
68- PageType .standalone,
69- standalonePageNode (
70- _apiMarkdown,
71- sideImage: _sideImage,
72- ),
73- title: 'pub.dev API' ,
74- canonicalUrl: '/help/api' ,
75- );
76- }
77-
78- /// Renders the `doc/help.md` .
79- String renderHelpPage () {
80- return renderLayoutPage (
81- PageType .standalone,
82- standalonePageNode (
83- _helpMarkdown,
84- sideImage: _sideImage,
85- ),
86- title: 'Help | Dart packages' ,
87- canonicalUrl: '/help' ,
88- );
89- }
90-
91- /// Renders the `doc/help-scoring.md` .
92- String renderHelpScoringPage () {
93- return renderLayoutPage (
94- PageType .standalone,
95- standalonePageNode (
96- _helpScoringMarkdown,
97- sideImage: _sideImage,
98- ),
99- title: 'Scoring | Dart packages' ,
100- canonicalUrl: '/help/scoring' ,
101- );
102- }
103-
104- /// Renders the `doc/help-content-moderation.md` .
105- String renderHelpContentModerationPage () {
106- return renderLayoutPage (
107- PageType .standalone,
108- standalonePageNode (
109- _helpContentModerationMarkdown,
110- sideImage: _sideImage,
111- ),
112- title: 'Content Moderation | Pub site' ,
113- canonicalUrl: '/help/content-moderation' ,
114- );
115- }
116-
117- /// Renders the `doc/help-search.md` .
118- String renderHelpSearchPage () {
119- return renderLayoutPage (
120- PageType .standalone,
121- standalonePageNode (
122- _helpSearchMarkdown,
123- sideImage: _sideImage,
124- ),
125- title: 'Search | Dart packages' ,
126- canonicalUrl: '/help/search' ,
127- );
128- }
129-
130- /// Renders the `doc/help-publishing.md` .
131- String renderHelpPublishingPage () {
76+ /// Renders the `doc/help[<-article>].md` .
77+ String ? renderHelpPage ({String ? article}) {
78+ final basename = article == null ? 'help.md' : 'help-$article .md' ;
79+ final page = _helpArticles[basename];
80+ if (page == null ) {
81+ return null ;
82+ }
13283 return renderLayoutPage (
13384 PageType .standalone,
13485 standalonePageNode (
135- _helpPublishingMarkdown ,
86+ page.content ,
13687 sideImage: _sideImage,
13788 ),
138- title: 'Publishing | Dart packages' ,
139- canonicalUrl: '/help/publishing ' ,
89+ title: [page.title, 'Help' , ' Dart packages'].nonNulls. toSet (). join ( ' | ' ) ,
90+ canonicalUrl: article == null ? '/help' : '/help/$ article ' ,
14091 );
14192}
14293
0 commit comments