Simplify code, remove html dependency

This commit removes the `html' package dependency, speeding up the
compile time of the Dart code.

It also simplifies the code and removes some unused code. For instance
the sun, moon, and lightbulb icons is removed, the `Theme' class is
removed, and the `switchTheme' function is now merged into the
`setTheme' function. The `makeThemeItem' function has also had its
second argument removed.
This commit is contained in:
2020-08-25 03:34:55 +02:00
parent 8b984e301f
commit f99d45e8ab
6 changed files with 38 additions and 76 deletions

View File

@@ -1,7 +1,4 @@
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;
import 'dart:html' show HttpRequest, Element, querySelector;
final excluded_keywords = {'index', 'CONTRIBUTING', 'LICENSE', 'README'};
@@ -9,7 +6,7 @@ final excluded_keywords = {'index', 'CONTRIBUTING', 'LICENSE', 'README'};
Future<String> fetchRemoteSitemap() async {
const path = '/sitemap.html';
try {
return await html.HttpRequest.getString(path);
return await HttpRequest.getString(path);
} catch (e) {
print('Couldnt open $path');
}
@@ -17,7 +14,7 @@ Future<String> fetchRemoteSitemap() async {
}
// Parse the list of elements and detect pages from this list
Map<String, String> detectPages(List<dom.Element> t_sitemap,
Map<String, String> detectPages(List<Element> t_sitemap,
[String t_prefix, Map<String, String> t_links]) {
t_links ??= <String, String>{};
@@ -47,17 +44,18 @@ Map<String, String> detectPages(List<dom.Element> t_sitemap,
// from the sitemap.
Future<Map<String, String>> parseSitemap() async {
final content = await fetchRemoteSitemap();
final sitemap = parse(content).getElementsByClassName('org-ul')[0].children;
return detectPages(sitemap);
final sitemap = Element.ul()..innerHtml = content;
final sitemapNodes = sitemap.querySelector('ul').children;
return detectPages(sitemapNodes);
}
Future<void> createSitemap() async {
final sitemap = await parseSitemap();
final pages = html.querySelector('#drop-page');
final pages = querySelector('#drop-page');
sitemap.forEach((url, name) {
final link = html.Element.li()
final link = Element.li()
..classes.add('dropdown-item')
..append(html.Element.a()
..append(Element.a()
..attributes['href'] = url
..innerText = name);
pages.append(link);