Fix some errors with webpages nested in directories

This commit is contained in:
Lucien Cartier-Tilet 2020-07-26 17:36:45 +02:00
parent 71f38b13e9
commit 167cad1ce3
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA
2 changed files with 11 additions and 9 deletions

View File

@ -1,6 +1,6 @@
import './parse_sitemap.dart' show createSitemap;
import './reorganize_html.dart' show reorganizeHtml;
import './theme.dart' show enableThemeChanger, setTheme;
import './parse_sitemap.dart' show createSitemap;
Future<void> main() async {
await setTheme();

View File

@ -18,9 +18,12 @@ Future<String> fetchRemoteSitemap() async {
// Parse the list of elements and detect pages from this list
Map<String, String> detectPages(List<dom.Element> t_sitemap,
[String t_prefix]) {
final links = <String, String>{};
[String t_prefix, Map<String, String> t_links]) {
t_links ??= <String, String>{};
// parse each element in sitemap
for (var elem in t_sitemap) {
// if its a link
if (elem.innerHtml.startsWith('<a')) {
elem = elem.firstChild;
final url = elem.attributes['href'];
@ -29,16 +32,15 @@ Map<String, String> detectPages(List<dom.Element> t_sitemap,
excluded_keywords.contains(url.substring(0, url.length - 5))) {
continue;
}
links['/$url'] = (t_prefix == null) ? text : '$text ($t_prefix)';
t_links['/$url'] = (t_prefix == null) ? text : '$text ($t_prefix)';
} else {
t_prefix = (t_prefix == null)
final prefix = (t_prefix == null)
? elem.firstChild.text.replaceAll('\n', '')
: '$t_prefix / ${elem.firstChild.text}';
final ul = elem.children[0].children;
links.addAll(detectPages(ul, t_prefix));
: '$t_prefix / ${elem.firstChild.text}'.replaceAll('\n', '');
t_links = detectPages(elem.children[0].children, prefix, t_links);
}
}
return links;
return t_links;
}
// This function returns a Map which contains all links to languages detected