Fixed issue where sitemap wouldn’t load
This commit is contained in:
parent
c9d263b12c
commit
d69682ec06
@ -1,9 +1,10 @@
|
||||
import './reorganize_html.dart' show reorganizeHtml;
|
||||
import './theme.dart' show enableThemeChanger, setTheme;
|
||||
import './parse_sitemap.dart' show getSitemap;
|
||||
import './parse_sitemap.dart' show createSitemap;
|
||||
|
||||
Future<void> main() async {
|
||||
await setTheme();
|
||||
await reorganizeHtml().then((_) => enableThemeChanger());
|
||||
await getSitemap();
|
||||
await reorganizeHtml()
|
||||
.then((_) => enableThemeChanger())
|
||||
.then((_) => createSitemap());
|
||||
}
|
||||
|
@ -20,8 +20,8 @@ Future<String> fetchRemoteSitemap() async {
|
||||
Map<String, String> detectPages(List<dom.Element> sitemap, [String prefix]) {
|
||||
final links = <String, String>{};
|
||||
for (var elem in sitemap) {
|
||||
for (var kw in excluded_keywords) {
|
||||
if (elem.outerHtml.contains(kw)) {
|
||||
for (var keyword in excluded_keywords) {
|
||||
if (elem.outerHtml.contains(keyword)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -32,7 +32,7 @@ Map<String, String> detectPages(List<dom.Element> sitemap, [String prefix]) {
|
||||
links[url] = (prefix == null) ? text : '$text ($prefix)';
|
||||
} else {
|
||||
prefix = (prefix == null)
|
||||
? elem.firstChild.text
|
||||
? elem.firstChild.text.replaceAll('\n', '')
|
||||
: '$prefix / ${elem.firstChild.text}';
|
||||
final ul = elem.children[0].children;
|
||||
links.addAll(detectPages(ul, prefix));
|
||||
@ -53,22 +53,15 @@ Future sleep(Duration time) async {
|
||||
return Future.delayed(time);
|
||||
}
|
||||
|
||||
Future<html.Element> getSitemap() async {
|
||||
Future<void> createSitemap() async {
|
||||
final sitemap = await parseSitemap();
|
||||
final pages = <html.Element>[];
|
||||
final pages = html.querySelector('#drop-page');
|
||||
sitemap.forEach((url, name) {
|
||||
final link = html.Element.li()
|
||||
..classes.add('dropdown-item')
|
||||
..append(html.Element.a()
|
||||
..attributes['href'] = url
|
||||
..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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user