import 'dart:html'; import './parse_sitemap.dart' show parseSitemap; // Returns the title of the current webpage String getPageTitle() { return querySelector('title').text; } Future addLanguages(Element navbar) async { // Languages var languages = Element.ul()..classes.add('dropdown'); await parseSitemap().then((final sitemap) => { sitemap.forEach((url, name) { final link = Element.a() ..attributes['href'] = url ..innerText = name; final linkLi = Element.li() ..classes.add('dropdown-item') ..insertAdjacentElement('afterBegin', link); languages.insertAdjacentElement('beforeEnd', linkLi); }) }); navbar.append(Element.li() ..append(Element.a() ..attributes['href'] = '#' ..innerText = 'Langues') ..classes.add('nav-item') ..classes.add('has-dropdown') ..insertAdjacentElement('beforeEnd', languages)); return navbar; } // 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 makeNavbar() async { // var _navbar = Navbar(); // Home var navbar_content = Element.ul()..classes.add('navbar-nav'); navbar_content.append(Element.li() ..classes.add('nav-item') ..insertAdjacentElement( 'afterBegin', Element.a() ..attributes['href'] = '/' ..innerText = 'Accueil')); // Add languages // navbar_content.append(Element.html(''' // ''')); navbar_content = await addLanguages(navbar_content); // Page title navbar_content.append(Element.li() ..classes.add('nav-item') ..innerText = getPageTitle()); // Share icon // Add dropdown for sharing on multiple platforms navbar_content = addIcon(navbar_content, ['fas', 'fa-share-alt'], 'shareBtn'); // Theme changer // Add dropdown for theming // navbar_content = addIcon(navbar_content, ['fas', 'fa-sun'], 'themeBtn'); navbar_content.append(Element.html(''' ''')); // Navbar content added to navbar final navbar = Element.nav() ..classes.add('navbar') ..append(navbar_content); return navbar; } Element addIcon(Element navbar, List classes, String id) { var elem = Element.tag('i')..attributes['id'] = id; for (var c in classes) { elem.classes.add(c); } navbar.append(Element.li()..append(elem)); return navbar; } Future wrapTables() async { for (var table in querySelectorAll('table')) { var largetable = DivElement()..className = 'largetable'; table.before(largetable); largetable.children.add(table); } } Future makeHeader() async { querySelector('body') .insertAdjacentElement('afterBegin', Element.tag('header')); querySelector('header').append(querySelector('h1')); querySelector('header').append(querySelector('.subtitle')); } Future reorganizeHtml() async { await makeHeader(); await wrapTables(); await makeNavbar().then((navbar) { querySelector('body').insertAdjacentElement('afterBegin', navbar); }); querySelector('body') ..classes.add('light') // Add a
element after the content div ..appendHtml('
') // Move the postamble in the content div ..append(querySelector('#postamble')); }