Simpler code, removed a loop, code style

This commit is contained in:
Lucien Cartier-Tilet 2020-05-26 00:35:55 +02:00
parent 06994305ac
commit 82d3e3d018
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA
1 changed files with 7 additions and 10 deletions

View File

@ -17,25 +17,22 @@ Future<String> fetchRemoteSitemap() async {
}
// Parse the list of elements and detect pages from this list
Map<String, String> detectPages(List<dom.Element> sitemap, [String prefix]) {
Map<String, String> detectPages(List<dom.Element> t_sitemap,
[String t_prefix]) {
final sitemap = t_sitemap.where((e) => !excluded_keywords.contains(e));
final links = <String, String>{};
for (var elem in sitemap) {
for (var keyword in excluded_keywords) {
if (elem.outerHtml.contains(keyword)) {
continue;
}
}
if (elem.innerHtml.startsWith('<a')) {
elem = elem.firstChild;
final url = elem.attributes['href'];
final text = elem.firstChild.text;
links[url] = (prefix == null) ? text : '$text ($prefix)';
links[url] = (t_prefix == null) ? text : '$text ($t_prefix)';
} else {
prefix = (prefix == null)
t_prefix = (t_prefix == null)
? elem.firstChild.text.replaceAll('\n', '')
: '$prefix / ${elem.firstChild.text}';
: '$t_prefix / ${elem.firstChild.text}';
final ul = elem.children[0].children;
links.addAll(detectPages(ul, prefix));
links.addAll(detectPages(ul, t_prefix));
}
}
return links;