Fixed issue where sitemap wouldn’t load

This commit is contained in:
Lucien Cartier-Tilet 2020-05-21 07:33:22 +02:00
parent c9d263b12c
commit d69682ec06
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA
2 changed files with 10 additions and 16 deletions

View File

@ -1,9 +1,10 @@
import './reorganize_html.dart' show reorganizeHtml; import './reorganize_html.dart' show reorganizeHtml;
import './theme.dart' show enableThemeChanger, setTheme; import './theme.dart' show enableThemeChanger, setTheme;
import './parse_sitemap.dart' show getSitemap; import './parse_sitemap.dart' show createSitemap;
Future<void> main() async { Future<void> main() async {
await setTheme(); await setTheme();
await reorganizeHtml().then((_) => enableThemeChanger()); await reorganizeHtml()
await getSitemap(); .then((_) => enableThemeChanger())
.then((_) => createSitemap());
} }

View File

@ -20,8 +20,8 @@ Future<String> fetchRemoteSitemap() async {
Map<String, String> detectPages(List<dom.Element> sitemap, [String prefix]) { Map<String, String> detectPages(List<dom.Element> sitemap, [String prefix]) {
final links = <String, String>{}; final links = <String, String>{};
for (var elem in sitemap) { for (var elem in sitemap) {
for (var kw in excluded_keywords) { for (var keyword in excluded_keywords) {
if (elem.outerHtml.contains(kw)) { if (elem.outerHtml.contains(keyword)) {
continue; continue;
} }
} }
@ -32,7 +32,7 @@ Map<String, String> detectPages(List<dom.Element> sitemap, [String prefix]) {
links[url] = (prefix == null) ? text : '$text ($prefix)'; links[url] = (prefix == null) ? text : '$text ($prefix)';
} else { } else {
prefix = (prefix == null) prefix = (prefix == null)
? elem.firstChild.text ? elem.firstChild.text.replaceAll('\n', '')
: '$prefix / ${elem.firstChild.text}'; : '$prefix / ${elem.firstChild.text}';
final ul = elem.children[0].children; final ul = elem.children[0].children;
links.addAll(detectPages(ul, prefix)); links.addAll(detectPages(ul, prefix));
@ -53,22 +53,15 @@ Future sleep(Duration time) async {
return Future.delayed(time); return Future.delayed(time);
} }
Future<html.Element> getSitemap() async { Future<void> createSitemap() async {
final sitemap = await parseSitemap(); final sitemap = await parseSitemap();
final pages = <html.Element>[]; final pages = html.querySelector('#drop-page');
sitemap.forEach((url, name) { sitemap.forEach((url, name) {
final link = html.Element.li() final link = html.Element.li()
..classes.add('dropdown-item') ..classes.add('dropdown-item')
..append(html.Element.a() ..append(html.Element.a()
..attributes['href'] = url ..attributes['href'] = url
..innerText = name); ..innerText = name);
pages.add(link); pages.append(link);
}); });
var drop_container;
do {
await sleep(Duration(seconds: 1));
drop_container = html.querySelector('#drop-page');
} while (drop_container != null);
pages.forEach((link) => drop_container.append(link));
return drop_container;
} }