import 'dart:html' as html show HttpRequest, Element, querySelector;
import 'package:html/parser.dart' show parse;
import 'package:html/dom.dart' as dom show Element;
final excluded_keywords = {'index', 'CONTRIBUTING', 'LICENSE', 'README'};
// Get the sitemap content
Future fetchRemoteSitemap() async {
const path = 'sitemap.html';
try {
return await html.HttpRequest.getString(path);
} catch (e) {
print('Couldn’t open $path');
}
return 'Error';
}
// Parse the list of elements and detect pages from this list
Map detectPages(List sitemap, [String prefix]) {
final links = {};
for (var elem in sitemap) {
for (var keyword in excluded_keywords) {
if (elem.outerHtml.contains(keyword)) {
continue;
}
}
if (elem.innerHtml.startsWith('> parseSitemap() async {
final content = await fetchRemoteSitemap();
final sitemap = parse(content).getElementsByClassName('org-ul')[0].children;
return detectPages(sitemap);
}
Future sleep(Duration time) async {
return Future.delayed(time);
}
Future createSitemap() async {
final sitemap = await parseSitemap();
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.append(link);
});
}