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]) { | ||||
|   final icon = Element.tag('i')..classes.addAll(classes); | ||||
|   if (id != null) { | ||||
|     icon.attributes['id'] = id; | ||||
|   } | ||||
|   icon.attributes['id'] = id ?? ''; | ||||
|   return icon; | ||||
| } | ||||
| 
 | ||||
| @ -33,7 +31,7 @@ Future<Element> makePages() async { | ||||
|       ..attributes['href'] = 'javascript:void(0)' | ||||
|       ..append(makeIcon(['fas', 'fa-flag']))) | ||||
|     ..classes.addAll(['nav-item', 'has-dropdown']) | ||||
|     ..insertAdjacentElement('beforeEnd', pages); | ||||
|     ..append(pages); | ||||
| } | ||||
| 
 | ||||
| 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/dom.dart' as dom show Element; | ||||
| 
 | ||||
| final excluded_keywords = ['index', 'CONTRIBUTING', 'LICENSE', 'README']; | ||||
| final excluded_keywords = {'index', 'CONTRIBUTING', 'LICENSE', 'README'}; | ||||
| 
 | ||||
| // Get the sitemap content | ||||
| Future<String> fetchRemoteSitemap() async { | ||||
| @ -31,7 +31,9 @@ Map<String, String> detectPages(List<dom.Element> sitemap, [String prefix]) { | ||||
|       final text = elem.firstChild.text; | ||||
|       links[url] = (prefix == null) ? text : '$text ($prefix)'; | ||||
|     } else { | ||||
|       final prefix = elem.firstChild.text; | ||||
|       prefix = (prefix == null) | ||||
|           ? elem.firstChild.text | ||||
|           : '$prefix / ${elem.firstChild.text}'; | ||||
|       final ul = elem.children[0].children; | ||||
|       links.addAll(detectPages(ul, prefix)); | ||||
|     } | ||||
| @ -68,4 +70,5 @@ Future<html.Element> getSitemap() async { | ||||
|     drop_container = html.querySelector('#drop-page'); | ||||
|   } while (drop_container != null); | ||||
|   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. | ||||
| void linkifyImg() { | ||||
| Future<void> linkifyImg() async { | ||||
|   querySelectorAll('img').forEach((img) { | ||||
|     if (img.parent.tagName == 'P') { | ||||
|       final link = Element.a()..attributes['href'] = img.attributes['src']; | ||||
| @ -41,34 +41,31 @@ void linkifyImg() { | ||||
| } | ||||
| 
 | ||||
| Future<void> reorganizeHtml() async { | ||||
|   final content = querySelector('#content'); | ||||
| 
 | ||||
|   // Make navbar | ||||
|   await makeNavbar().then((navbar) { | ||||
|     querySelector('body').insertAdjacentElement('afterBegin', navbar); | ||||
|   }); | ||||
|   final navbar = await makeNavbar(); | ||||
| 
 | ||||
|   // Make header | ||||
|   await makeHeader().then((header) { | ||||
|     content.insertAdjacentElement('beforeBegin', header); | ||||
|     final subtitle = querySelector('.subtitle'); | ||||
|     if (subtitle != null) { | ||||
|       header.append(subtitle); | ||||
|     } | ||||
|   }); | ||||
|   final header = await makeHeader(); | ||||
| 
 | ||||
|   // wrap tables in container for better SCSS display | ||||
|   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 | ||||
|   final toc = (querySelector('#table-of-contents') ?? | ||||
|       (Element.div() | ||||
|         ..attributes['id'] = 'table-of-contents' | ||||
|         ..innerText = "Table of Contents Unavailable")) | ||||
|         ..innerText = 'Table of Contents Unavailable')) | ||||
|     ..classes.add('dropdown'); | ||||
|   querySelector('#toc-drop').append(toc); | ||||
|   navbar.querySelector('#toc-drop').append(toc); | ||||
| 
 | ||||
|   // Remove all <br> tags from HTML | ||||
|   querySelectorAll('br').forEach((br) => br.remove()); | ||||
|  | ||||
		Reference in New Issue
	
	Block a user