Better coding style
This commit is contained in:
parent
aa4600b588
commit
8ca55cb710
@ -9,9 +9,7 @@ String getPageTitle() {
|
|||||||
|
|
||||||
Element makeIcon(List<String> classes, [String id]) {
|
Element makeIcon(List<String> classes, [String id]) {
|
||||||
final icon = Element.tag('i')..classes.addAll(classes);
|
final icon = Element.tag('i')..classes.addAll(classes);
|
||||||
if (id != null) {
|
icon.attributes['id'] = id ?? '';
|
||||||
icon.attributes['id'] = id;
|
|
||||||
}
|
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +31,7 @@ Future<Element> makePages() async {
|
|||||||
..attributes['href'] = 'javascript:void(0)'
|
..attributes['href'] = 'javascript:void(0)'
|
||||||
..append(makeIcon(['fas', 'fa-flag'])))
|
..append(makeIcon(['fas', 'fa-flag'])))
|
||||||
..classes.addAll(['nav-item', 'has-dropdown'])
|
..classes.addAll(['nav-item', 'has-dropdown'])
|
||||||
..insertAdjacentElement('beforeEnd', pages);
|
..append(pages);
|
||||||
}
|
}
|
||||||
|
|
||||||
Element makeShareLink(Element icon, String url) {
|
Element makeShareLink(Element icon, String url) {
|
||||||
|
@ -3,7 +3,7 @@ import 'dart:html' as html show HttpRequest, Element, querySelector;
|
|||||||
import 'package:html/parser.dart' show parse;
|
import 'package:html/parser.dart' show parse;
|
||||||
import 'package:html/dom.dart' as dom show Element;
|
import 'package:html/dom.dart' as dom show Element;
|
||||||
|
|
||||||
final excluded_keywords = ['index', 'CONTRIBUTING', 'LICENSE', 'README'];
|
final excluded_keywords = {'index', 'CONTRIBUTING', 'LICENSE', 'README'};
|
||||||
|
|
||||||
// Get the sitemap content
|
// Get the sitemap content
|
||||||
Future<String> fetchRemoteSitemap() async {
|
Future<String> fetchRemoteSitemap() async {
|
||||||
@ -31,7 +31,9 @@ Map<String, String> detectPages(List<dom.Element> sitemap, [String prefix]) {
|
|||||||
final text = elem.firstChild.text;
|
final text = elem.firstChild.text;
|
||||||
links[url] = (prefix == null) ? text : '$text ($prefix)';
|
links[url] = (prefix == null) ? text : '$text ($prefix)';
|
||||||
} else {
|
} else {
|
||||||
final prefix = elem.firstChild.text;
|
prefix = (prefix == null)
|
||||||
|
? 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));
|
||||||
}
|
}
|
||||||
@ -68,4 +70,5 @@ Future<html.Element> getSitemap() async {
|
|||||||
drop_container = html.querySelector('#drop-page');
|
drop_container = html.querySelector('#drop-page');
|
||||||
} while (drop_container != null);
|
} while (drop_container != null);
|
||||||
pages.forEach((link) => drop_container.append(link));
|
pages.forEach((link) => drop_container.append(link));
|
||||||
|
return drop_container;
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ Future<void> wrapTables() async {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// All images that are not nested inside a link will be linkified to themselves.
|
// All images that are not nested inside a link will be linkified to themselves.
|
||||||
void linkifyImg() {
|
Future<void> linkifyImg() async {
|
||||||
querySelectorAll('img').forEach((img) {
|
querySelectorAll('img').forEach((img) {
|
||||||
if (img.parent.tagName == 'P') {
|
if (img.parent.tagName == 'P') {
|
||||||
final link = Element.a()..attributes['href'] = img.attributes['src'];
|
final link = Element.a()..attributes['href'] = img.attributes['src'];
|
||||||
@ -41,34 +41,31 @@ void linkifyImg() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> reorganizeHtml() async {
|
Future<void> reorganizeHtml() async {
|
||||||
final content = querySelector('#content');
|
|
||||||
|
|
||||||
// Make navbar
|
// Make navbar
|
||||||
await makeNavbar().then((navbar) {
|
final navbar = await makeNavbar();
|
||||||
querySelector('body').insertAdjacentElement('afterBegin', navbar);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Make header
|
// Make header
|
||||||
await makeHeader().then((header) {
|
final header = await makeHeader();
|
||||||
content.insertAdjacentElement('beforeBegin', header);
|
|
||||||
final subtitle = querySelector('.subtitle');
|
|
||||||
if (subtitle != null) {
|
|
||||||
header.append(subtitle);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// wrap tables in container for better SCSS display
|
// wrap tables in container for better SCSS display
|
||||||
await wrapTables();
|
await wrapTables();
|
||||||
|
|
||||||
linkifyImg();
|
// Make images not linking somewhere link to themselves
|
||||||
|
await linkifyImg();
|
||||||
|
|
||||||
|
// Add navbar to page
|
||||||
|
querySelector('body').insertAdjacentElement('afterBegin', navbar);
|
||||||
|
|
||||||
|
// Add headet to page
|
||||||
|
querySelector('#content').insertAdjacentElement('beforeBegin', header);
|
||||||
|
|
||||||
// Add correct class to TOC
|
// Add correct class to TOC
|
||||||
final toc = (querySelector('#table-of-contents') ??
|
final toc = (querySelector('#table-of-contents') ??
|
||||||
(Element.div()
|
(Element.div()
|
||||||
..attributes['id'] = 'table-of-contents'
|
..attributes['id'] = 'table-of-contents'
|
||||||
..innerText = "Table of Contents Unavailable"))
|
..innerText = 'Table of Contents Unavailable'))
|
||||||
..classes.add('dropdown');
|
..classes.add('dropdown');
|
||||||
querySelector('#toc-drop').append(toc);
|
navbar.querySelector('#toc-drop').append(toc);
|
||||||
|
|
||||||
// Remove all <br> tags from HTML
|
// Remove all <br> tags from HTML
|
||||||
querySelectorAll('br').forEach((br) => br.remove());
|
querySelectorAll('br').forEach((br) => br.remove());
|
||||||
|
Reference in New Issue
Block a user