diff --git a/pubspec.yaml b/pubspec.yaml index 30450ec..9532db7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ homepage: https://labs.phundrak.com/phundrak/org-website-backend author: Lucien Cartier-Tilet environment: - sdk: '>=2.7.0 <3.0.0' + sdk: '>=2.12.0 <3.0.0' dependencies: diff --git a/web/dart/navbar.dart b/web/dart/navbar.dart index 61b92ec..d7eecb3 100644 --- a/web/dart/navbar.dart +++ b/web/dart/navbar.dart @@ -35,7 +35,7 @@ final icons = { }; // Get the current page’s title -String getPageTitle() => querySelector('title').text; +String getPageTitle() => querySelector('title')!.text!; // Create the home button Future makeHome() async { @@ -45,7 +45,7 @@ Future makeHome() async { 'afterBegin', Element.a() ..attributes['href'] = '/' - ..append(makeIcon(icons['home']))); + ..append(makeIcon(icons['home']!))); } // Create a clickable icon @@ -61,7 +61,7 @@ Future makePages() async { ..append(Element.a() ..attributes['tabindex'] = '-1' ..attributes['href'] = 'javascript:void(0)' - ..append(makeIcon(icons['pages']))) + ..append(makeIcon(icons['pages']!))) ..classes.addAll(['nav-item', 'has-dropdown']) ..append(Element.ul() ..attributes['id'] = 'drop-page' @@ -87,23 +87,23 @@ Future makeShare() async { ..append(Element.a() ..attributes['href'] = 'javascript:void(0)' ..attributes['tabindex'] = '-1' - ..append(makeIcon(icons['share']))) + ..append(makeIcon(icons['share']!))) ..append(Element.ul() ..classes.add('dropdown') ..attributes['id'] = 'drop-share' ..append(makeShareLink( - makeIcon(icons['twitter']), + makeIcon(icons['twitter']!), 'https://twitter.com/share?text=${getPageTitle()}' '&url=${window.location.href}')) - ..append(makeShareLink(makeIcon(icons['reddit']), + ..append(makeShareLink(makeIcon(icons['reddit']!), 'https://www.reddit.com/submit?title=${getPageTitle()}s&url=${window.location.href}')) - ..append(makeShareLink(makeIcon(icons['email']), - 'mailto:?subject=${getPageTitle}&body=${window.location.href}')) + ..append(makeShareLink(makeIcon(icons['email']!), + 'mailto:?subject=$getPageTitle&body=${window.location.href}')) ..append(makeShareLink( - makeIcon(icons['linkedin']), + makeIcon(icons['linkedin']!), 'https://www.linkedin.com/shareArticle?mini=true&url=${window.location.href}' '&title=${getPageTitle()}')) - ..append(makeShareLink(makeIcon(icons['facebook']), + ..append(makeShareLink(makeIcon(icons['facebook']!), 'https://www.facebook.com/sharer/sharer.php?u=${window.location.href}'))); } @@ -125,7 +125,7 @@ Future makeThemeChanger() async { ..attributes['tabindex'] = '-1' ..append(Element.span() ..style.verticalAlign = 'top' - ..append(makeIcon(icons['theme'])))) + ..append(makeIcon(icons['theme']!)))) ..append(Element.ul() ..classes.add('dropdown') ..attributes['id'] = 'theme-dropdown' @@ -144,7 +144,7 @@ Future makeToc() async { ..append(Element.a() ..attributes['tabindex'] = '-1' ..attributes['href'] = 'javascript:void(0)' - ..append(makeIcon(icons['toc']))); + ..append(makeIcon(icons['toc']!))); } // Add a navbar atop of the HTML body, containing: diff --git a/web/dart/parse_sitemap.dart b/web/dart/parse_sitemap.dart index 92d38ff..3cac6e0 100644 --- a/web/dart/parse_sitemap.dart +++ b/web/dart/parse_sitemap.dart @@ -15,29 +15,29 @@ Future fetchRemoteSitemap() async { // Parse the list of elements and detect pages from this list Map detectPages(List t_sitemap, - [String t_prefix, Map t_links]) { + [String? t_prefix, Map? t_links]) { t_links ??= {}; // parse each element in sitemap for (var elem in t_sitemap) { // if it’s a link - if (elem.innerHtml.startsWith(' detectPages(List t_sitemap, Future> parseSitemap() async { final content = await fetchRemoteSitemap(); final sitemap = Element.ul()..innerHtml = content; - final sitemapNodes = sitemap.querySelector('ul').children; + final sitemapNodes = sitemap.querySelector('ul')!.children; return detectPages(sitemapNodes); } Future createSitemap() async { final sitemap = await parseSitemap(); - final pages = querySelector('#drop-page'); + final pages = querySelector('#drop-page')!; sitemap.forEach((url, name) { final link = Element.li() ..classes.add('dropdown-item') diff --git a/web/dart/reorganize_html.dart b/web/dart/reorganize_html.dart index 215455c..d195649 100644 --- a/web/dart/reorganize_html.dart +++ b/web/dart/reorganize_html.dart @@ -13,7 +13,7 @@ Future makeHeader() async { ..attributes['alt'] = 'Logo' ..attributes['height'] = '150px' ..attributes['width'] = '150px') - ..append(querySelector('h1')); + ..append(querySelector('h1')!); final subt = header.querySelector('.subtitle'); if (subt != null) { header.append(subt); @@ -32,8 +32,8 @@ Future wrapTables() async { // All images that are not nested inside a link will be linkified to themselves. Future linkifyImg() async { querySelectorAll('img').forEach((img) { - if (img.parent.tagName == 'P') { - final link = Element.a()..attributes['href'] = img.attributes['src']; + if (img.parent!.tagName == 'P') { + final link = Element.a()..attributes['href'] = img.attributes['src']!; img.insertAdjacentElement('beforeBegin', link); link.append(img); } @@ -61,10 +61,10 @@ Future reorganizeHtml() async { await linkifyImg(); // Add navbar to page - querySelector('body').insertAdjacentElement('afterBegin', navbar); + querySelector('body')!.insertAdjacentElement('afterBegin', navbar); // Add headet to page - querySelector('#content').insertAdjacentElement('beforeBegin', header); + querySelector('#content')!.insertAdjacentElement('beforeBegin', header); // Add correct class to TOC final toc = (querySelector('#table-of-contents') ?? @@ -72,7 +72,7 @@ Future reorganizeHtml() async { ..attributes['id'] = 'table-of-contents' ..innerText = 'Table of Contents Unavailable')) ..classes.add('dropdown'); - navbar.querySelector('#toc-drop').append(toc); + navbar.querySelector('#toc-drop')!.append(toc); // Remove all
tags from HTML querySelectorAll('br').forEach((br) => br.remove()); diff --git a/web/dart/theme.dart b/web/dart/theme.dart index 0d2f6ea..20e3f76 100644 --- a/web/dart/theme.dart +++ b/web/dart/theme.dart @@ -2,22 +2,19 @@ import 'dart:html' show window, querySelector; final localStorage = window.localStorage; -Future setTheme([String theme]) async { - final currentTheme = theme ?? localStorage['theme'] ?? - () { - final devicePrefersDark = - window.matchMedia('(prefers-color-scheme: dark)').matches; - return devicePrefersDark ? 'nord' : 'light'; - }(); - localStorage['theme'] = currentTheme; - querySelector('body') +Future setTheme([String? theme]) async { + theme ??= localStorage['theem'] ?? + (window.matchMedia('(prefers-color-scheme: dark)').matches + ? 'dark' + : 'light'); + localStorage['theme'] = theme; + querySelector('body')! ..classes.clear() - ..classes.add(currentTheme); + ..classes.add(theme); } void enableThemeChanger() { final themes = ['light', 'dark', 'nord', 'black']; themes.forEach((theme) => - querySelector('#${theme}Btn').onClick.listen((_) => setTheme(theme)) - ); + querySelector('#${theme}Btn')!.onClick.listen((_) => setTheme(theme))); }