From d32f0f4245f84fc59b7546c4dc8b3d84ae58e4a7 Mon Sep 17 00:00:00 2001 From: despiegk Date: Sat, 19 Jul 2025 17:27:25 +0200 Subject: [PATCH] ... --- lib/data/doctree/list.v | 65 +++++++++++++++++++++++++++++ lib/web/docusaurus/dsite_generate.v | 3 +- lib/web/sitegen/site.v | 4 +- 3 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 lib/data/doctree/list.v diff --git a/lib/data/doctree/list.v b/lib/data/doctree/list.v new file mode 100644 index 00000000..cdb44ee9 --- /dev/null +++ b/lib/data/doctree/list.v @@ -0,0 +1,65 @@ +module doctree + +import freeflowuniverse.herolib.ui.console + +// list_pages returns a map of collection names to a list of page names within that collection. +// The structure is map[collectionname][]pagename. +pub fn (mut t Tree) list_pages() map[string][]string { + mut result := map[string][]string{} + mut sorted_collections := t.collections.values() + sorted_collections.sort(a.name < b.name) + + for _, col in sorted_collections { + mut page_names := []string{} + mut sorted_pages := col.pages.values() + sorted_pages.sort(a.name < b.name) + for _, page in sorted_pages { + page_names << page.name + } + result[col.name] = page_names + } + return result +} + +// list_markdown returns the collections and their pages in markdown format. +pub fn (mut t Tree) list_markdown() string { + mut markdown_output := '' + pages_map := t.list_pages() + + if pages_map.len == 0 { + return 'No collections or pages found in this doctree.' + } + + for col_name, page_names in pages_map { + markdown_output += '## ${col_name}\n' + if page_names.len == 0 { + markdown_output += ' * No pages in this collection.\n' + } else { + for page_name in page_names { + markdown_output += ' * ${page_name}\n' + } + } + markdown_output += '\n' // Add a newline for spacing between collections + } + return markdown_output +} + +// print_pages prints the collections and their pages in a nice, easy-to-see format. +pub fn (mut t Tree) print_pages() { + pages_map := t.list_pages() + console.print_header('Doctree: ${t.name}') + if pages_map.len == 0 { + console.print_green('No collections or pages found in this doctree.') + return + } + for col_name, page_names in pages_map { + console.print_green('Collection: ${col_name}') + if page_names.len == 0 { + console.print_green(' No pages in this collection.') + } else { + for page_name in page_names { + console.print_item(' ${page_name}') + } + } + } +} \ No newline at end of file diff --git a/lib/web/docusaurus/dsite_generate.v b/lib/web/docusaurus/dsite_generate.v index 8eef7871..c1fe60e4 100644 --- a/lib/web/docusaurus/dsite_generate.v +++ b/lib/web/docusaurus/dsite_generate.v @@ -61,9 +61,8 @@ pub fn (mut site DocSite) generate() ! { configpath:="${site.path_src.path}/cfg" sitegen.play(heroscript_path: configpath)! - if true{panic("123456")} // TODO: remove this line, it is just to show where the code continues sitegenpath := '${os.home_dir()}/hero/var/sitegen/${site.name}' - if os.exists(sitegenpath) { + if true || os.exists(sitegenpath) { panic("Sdsdsd:${sitegenpath}") } site.process_imports()! diff --git a/lib/web/sitegen/site.v b/lib/web/sitegen/site.v index 040cb4d7..823c9041 100644 --- a/lib/web/sitegen/site.v +++ b/lib/web/sitegen/site.v @@ -60,8 +60,8 @@ pub fn (mut site Site) page_add(args_ Page) ! { mut c:=content.join("\n") mut mypage:=site.tree.page_get(args.src) or { - println(site.tree) - return error("Couldn't find page '${args.src}' in site tree:'${site.tree.name}', needs to be in form \$collection:\$name") + // site.tree.print_pages() + return error("Couldn't find page '${args.src}' in site tree:'${site.tree.name}', needs to be in form \$collection:\$name\n${site.tree.list_markdown()}") } c+="\n${mypage.get_markdown()!}\n"