2020-04-24 16:14:52 +00:00
|
|
|
import 'dart:html';
|
|
|
|
|
|
|
|
import './parse_sitemap.dart' show parseSitemap;
|
|
|
|
|
|
|
|
// Returns the title of the current webpage
|
|
|
|
String getPageTitle() {
|
|
|
|
return querySelector('title').text;
|
|
|
|
}
|
|
|
|
|
2020-04-28 20:32:37 +00:00
|
|
|
Element makeIcon(List<String> classes, [String id]) {
|
|
|
|
final icon = Element.tag('i')..classes.addAll(classes);
|
|
|
|
if (id != null) {
|
|
|
|
icon.attributes['id'] = id;
|
|
|
|
}
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
|
2020-04-28 22:03:51 +00:00
|
|
|
Future<Element> makeLanguages() async {
|
2020-04-24 16:14:52 +00:00
|
|
|
// Languages
|
2020-04-28 20:32:37 +00:00
|
|
|
var languages = Element.ul()
|
|
|
|
..attributes['id'] = 'drop-lang'
|
|
|
|
..classes.add('dropdown');
|
2020-04-24 16:14:52 +00:00
|
|
|
await parseSitemap().then((final sitemap) => {
|
|
|
|
sitemap.forEach((url, name) {
|
2020-04-28 20:32:37 +00:00
|
|
|
final link = Element.li()
|
2020-04-24 16:14:52 +00:00
|
|
|
..classes.add('dropdown-item')
|
2020-04-28 20:32:37 +00:00
|
|
|
..insertAdjacentElement(
|
|
|
|
'afterBegin',
|
|
|
|
Element.a()
|
|
|
|
..attributes['href'] = url
|
|
|
|
..innerText = name);
|
|
|
|
languages.insertAdjacentElement('beforeEnd', link);
|
2020-04-24 16:14:52 +00:00
|
|
|
})
|
|
|
|
});
|
2020-04-28 22:03:51 +00:00
|
|
|
return Element.li()
|
2020-04-24 16:14:52 +00:00
|
|
|
..append(Element.a()
|
2020-04-28 20:32:37 +00:00
|
|
|
..attributes['href'] = 'javascript:void(0)'
|
|
|
|
..append(makeIcon(['fas', 'fa-language'])))
|
|
|
|
..classes.addAll(['nav-item', 'has-dropdown'])
|
2020-04-28 22:03:51 +00:00
|
|
|
..insertAdjacentElement('beforeEnd', languages);
|
2020-04-24 16:14:52 +00:00
|
|
|
}
|
|
|
|
|
2020-04-28 22:40:30 +00:00
|
|
|
Future<Element> makeTocDropDown() async {
|
2020-04-28 20:32:37 +00:00
|
|
|
return Element.li()
|
|
|
|
..attributes['id'] = 'toc-drop'
|
|
|
|
..classes.addAll(['nav-item', 'has-dropdown'])
|
|
|
|
..append(Element.a()
|
|
|
|
..attributes['href'] = 'javascript:void(0)'
|
|
|
|
..append(makeIcon(['fas', 'fa-list-ol'], 'tocBtn')));
|
|
|
|
}
|
|
|
|
|
2020-04-28 22:40:30 +00:00
|
|
|
Future<Element> makeThemeChanger() async {
|
2020-04-28 20:32:37 +00:00
|
|
|
Element makeThemeItem(String t_btnId, Element t_icon, String t_text) {
|
|
|
|
return Element.li()
|
|
|
|
..classes.add('dropdown-item')
|
|
|
|
..append(Element.span()
|
|
|
|
..attributes['id'] = t_btnId
|
|
|
|
..append(t_icon)
|
|
|
|
..appendText(' $t_text'));
|
|
|
|
}
|
|
|
|
|
|
|
|
return Element.li()
|
|
|
|
..classes.addAll(['nav-item', 'has-dropdown'])
|
|
|
|
..append(Element.a()
|
|
|
|
..attributes['href'] = 'javascript:void(0)'
|
2020-04-28 22:03:51 +00:00
|
|
|
..append(Element.span()
|
|
|
|
..classes.add('fa-stack')
|
|
|
|
..style.verticalAlign = 'top'
|
|
|
|
..append(makeIcon(['fas', 'fa-sun', 'fa-stack-1x'])..style.fontSize = '0.9em')
|
|
|
|
..append(makeIcon(['fas', 'fa-moon', 'fa-stack-1x']))))
|
2020-04-28 20:32:37 +00:00
|
|
|
..append(Element.ul()
|
|
|
|
..classes.add('dropdown')
|
|
|
|
..attributes['id'] = 'theme-dropdown'
|
|
|
|
..append(makeThemeItem('lightBtn', makeIcon(['fas', 'fa-sun']), 'Clair'))
|
2020-04-28 22:03:51 +00:00
|
|
|
..append(
|
|
|
|
makeThemeItem('darkBtn', makeIcon(['fas', 'fa-lightbulb']), 'Sombre'))
|
|
|
|
..append(
|
|
|
|
makeThemeItem('blackBtn', makeIcon(['fas', 'fa-moon']), 'Noir')));
|
2020-04-28 20:32:37 +00:00
|
|
|
}
|
|
|
|
|
2020-04-28 22:40:30 +00:00
|
|
|
Element makeShareLink(Element icon, String url) {
|
|
|
|
return Element.li()
|
|
|
|
..classes.add('dropdown-item')
|
|
|
|
..append(Element.a()
|
|
|
|
..attributes['href'] = url
|
|
|
|
..attributes['target'] = '_blank'
|
|
|
|
..append(icon));
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Element> makeShare() async {
|
|
|
|
return Element.li()
|
|
|
|
..classes.addAll(['nav-item', 'has-dropdown'])
|
|
|
|
..append(Element.a()
|
|
|
|
..attributes['href'] = 'javascript:void(0)'
|
|
|
|
..append(makeIcon(['fas', 'fa-share-alt'])))
|
|
|
|
..append(Element.ul()
|
|
|
|
..classes.add('dropdown')
|
|
|
|
..append(makeShareLink(
|
|
|
|
makeIcon(['fab', 'fa-twitter-square']),
|
|
|
|
'https://twitter.com/share?text=${getPageTitle()}'
|
|
|
|
'&url=${window.location.href}'))
|
|
|
|
..append(makeShareLink(makeIcon(['fab', 'fa-reddit-square']),
|
|
|
|
'https://www.reddit.com/submit?title=${getPageTitle()}s&url=${window.location.href}'))
|
|
|
|
..append(makeShareLink(makeIcon(['fas', 'fa-envelope-square']),
|
|
|
|
'mailto:?subject=${getPageTitle}&body=${window.location.href}'))
|
|
|
|
..append(makeShareLink(
|
|
|
|
makeIcon(['fab', 'fa-linkedin']),
|
|
|
|
'https://www.linkedin.com/shareArticle?mini=true&url=${window.location.href}'
|
|
|
|
'&title=${getPageTitle()}'))
|
|
|
|
..append(makeShareLink(makeIcon(['fab', 'fa-facebook-square']),
|
|
|
|
'https://www.facebook.com/sharer/sharer.php?u=${window.location.href}')));
|
|
|
|
}
|
|
|
|
|
2020-04-24 16:14:52 +00:00
|
|
|
// Add a navbar atop of the HTML body, containing two buttons:
|
|
|
|
// - One back to home
|
|
|
|
// - A dropdown to each language detected in the sitemap
|
|
|
|
Future<Element> makeNavbar() async {
|
2020-04-28 20:32:37 +00:00
|
|
|
var navbar_content = Element.ul()..classes.add('navbar-nav');
|
2020-04-24 16:14:52 +00:00
|
|
|
|
|
|
|
// Home
|
|
|
|
navbar_content.append(Element.li()
|
|
|
|
..classes.add('nav-item')
|
|
|
|
..insertAdjacentElement(
|
|
|
|
'afterBegin',
|
|
|
|
Element.a()
|
|
|
|
..attributes['href'] = '/'
|
2020-04-28 20:32:37 +00:00
|
|
|
..append(makeIcon(['fas', 'fa-home']))));
|
2020-04-24 16:14:52 +00:00
|
|
|
|
2020-04-28 20:32:37 +00:00
|
|
|
// Add languages
|
2020-04-28 22:03:51 +00:00
|
|
|
navbar_content.append(await makeLanguages());
|
2020-04-24 16:14:52 +00:00
|
|
|
|
2020-05-02 13:40:39 +00:00
|
|
|
// TOC icon
|
|
|
|
navbar_content.append(await makeTocDropDown());
|
|
|
|
|
2020-04-24 16:14:52 +00:00
|
|
|
// Share icon
|
2020-04-28 22:40:30 +00:00
|
|
|
navbar_content.append(await makeShare());
|
2020-04-24 16:14:52 +00:00
|
|
|
|
|
|
|
// Theme changer
|
2020-04-28 22:40:30 +00:00
|
|
|
navbar_content.append(await makeThemeChanger());
|
2020-04-24 16:14:52 +00:00
|
|
|
|
|
|
|
// Navbar content added to navbar
|
|
|
|
final navbar = Element.nav()
|
|
|
|
..classes.add('navbar')
|
|
|
|
..append(navbar_content);
|
|
|
|
|
|
|
|
return navbar;
|
|
|
|
}
|
|
|
|
|
|
|
|
Element addIcon(Element navbar, List<String> classes, String id) {
|
2020-04-28 20:32:37 +00:00
|
|
|
final icon = makeIcon(classes, id);
|
|
|
|
navbar.append(Element.li()..append(icon));
|
2020-04-24 16:14:52 +00:00
|
|
|
return navbar;
|
|
|
|
}
|
|
|
|
|
2020-04-28 20:32:37 +00:00
|
|
|
Element makeHeader() {
|
|
|
|
var header = Element.tag('header');
|
|
|
|
|
|
|
|
// querySelector('#container').append(Element.tag('header'));
|
|
|
|
// var header = querySelector('header');
|
|
|
|
header
|
|
|
|
..append(Element.img()
|
|
|
|
..attributes['src'] =
|
|
|
|
'https://cdn.phundrak.com/img/mahakala-monochrome.png'
|
|
|
|
..attributes['alt'] = 'Logo de Phundrak'
|
|
|
|
..attributes['heigh'] = '150px'
|
|
|
|
..attributes['width'] = '150px')
|
|
|
|
..append(querySelector('h1'));
|
|
|
|
var subt = querySelector('.subtitle');
|
|
|
|
if (subt != null) {
|
|
|
|
header.append(subt);
|
|
|
|
}
|
|
|
|
return header;
|
|
|
|
}
|
|
|
|
|
2020-04-24 16:14:52 +00:00
|
|
|
Future<void> wrapTables() async {
|
|
|
|
for (var table in querySelectorAll('table')) {
|
|
|
|
var largetable = DivElement()..className = 'largetable';
|
|
|
|
table.before(largetable);
|
|
|
|
largetable.children.add(table);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> reorganizeHtml() async {
|
2020-04-28 20:32:37 +00:00
|
|
|
// Create navbar and then header
|
2020-04-24 16:14:52 +00:00
|
|
|
await makeNavbar().then((navbar) {
|
|
|
|
querySelector('body').insertAdjacentElement('afterBegin', navbar);
|
2020-04-28 20:32:37 +00:00
|
|
|
querySelector('nav').insertAdjacentElement('afterEnd', makeHeader());
|
|
|
|
querySelector('#toc-drop')
|
|
|
|
.append(querySelector('#table-of-contents')..classes.add('dropdown'));
|
2020-04-24 16:14:52 +00:00
|
|
|
});
|
|
|
|
|
2020-04-28 20:32:37 +00:00
|
|
|
// wrap tables in container for better SCSS display
|
|
|
|
await wrapTables();
|
2020-04-24 16:14:52 +00:00
|
|
|
}
|