Fix some errors with webpages nested in directories
This commit is contained in:
		
							parent
							
								
									71f38b13e9
								
							
						
					
					
						commit
						167cad1ce3
					
				| @ -1,6 +1,6 @@ | |||||||
|  | import './parse_sitemap.dart' show createSitemap; | ||||||
| import './reorganize_html.dart' show reorganizeHtml; | import './reorganize_html.dart' show reorganizeHtml; | ||||||
| import './theme.dart' show enableThemeChanger, setTheme; | import './theme.dart' show enableThemeChanger, setTheme; | ||||||
| import './parse_sitemap.dart' show createSitemap; |  | ||||||
| 
 | 
 | ||||||
| Future<void> main() async { | Future<void> main() async { | ||||||
|   await setTheme(); |   await setTheme(); | ||||||
|  | |||||||
| @ -18,9 +18,12 @@ Future<String> fetchRemoteSitemap() async { | |||||||
| 
 | 
 | ||||||
| // Parse the list of elements and detect pages from this list | // Parse the list of elements and detect pages from this list | ||||||
| Map<String, String> detectPages(List<dom.Element> t_sitemap, | Map<String, String> detectPages(List<dom.Element> t_sitemap, | ||||||
|     [String t_prefix]) { |     [String t_prefix, Map<String, String> t_links]) { | ||||||
|   final links = <String, String>{}; |   t_links ??= <String, String>{}; | ||||||
|  | 
 | ||||||
|  |   // parse each element in sitemap | ||||||
|   for (var elem in t_sitemap) { |   for (var elem in t_sitemap) { | ||||||
|  |     // if it’s a link | ||||||
|     if (elem.innerHtml.startsWith('<a')) { |     if (elem.innerHtml.startsWith('<a')) { | ||||||
|       elem = elem.firstChild; |       elem = elem.firstChild; | ||||||
|       final url = elem.attributes['href']; |       final url = elem.attributes['href']; | ||||||
| @ -29,16 +32,15 @@ Map<String, String> detectPages(List<dom.Element> t_sitemap, | |||||||
|           excluded_keywords.contains(url.substring(0, url.length - 5))) { |           excluded_keywords.contains(url.substring(0, url.length - 5))) { | ||||||
|         continue; |         continue; | ||||||
|       } |       } | ||||||
|       links['/$url'] = (t_prefix == null) ? text : '$text ($t_prefix)'; |       t_links['/$url'] = (t_prefix == null) ? text : '$text ($t_prefix)'; | ||||||
|     } else { |     } else { | ||||||
|       t_prefix = (t_prefix == null) |       final prefix = (t_prefix == null) | ||||||
|           ? elem.firstChild.text.replaceAll('\n', '') |           ? elem.firstChild.text.replaceAll('\n', '') | ||||||
|           : '$t_prefix / ${elem.firstChild.text}'; |           : '$t_prefix / ${elem.firstChild.text}'.replaceAll('\n', ''); | ||||||
|       final ul = elem.children[0].children; |       t_links = detectPages(elem.children[0].children, prefix, t_links); | ||||||
|       links.addAll(detectPages(ul, t_prefix)); |  | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   return links; |   return t_links; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // This function returns a Map which contains all links to languages detected | // This function returns a Map which contains all links to languages detected | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user