...
This commit is contained in:
@@ -244,3 +244,44 @@ pub fn (mut c DocTreeClient) list_images(collection_name string) ![]string {
|
||||
|
||||
return image_names
|
||||
}
|
||||
|
||||
// list_pages_map returns a map of collection names to a list of page names within that collection.
|
||||
// The structure is map[collectionname][]pagename.
|
||||
pub fn (mut c DocTreeClient) list_pages_map() !map[string][]string {
|
||||
mut result := map[string][]string{}
|
||||
collections := c.list_collections()!
|
||||
|
||||
for col_name in collections {
|
||||
mut page_names := c.list_pages(col_name)!
|
||||
page_names.sort()
|
||||
result[col_name] = page_names
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// list_markdown returns the collections and their pages in markdown format.
|
||||
pub fn (mut c DocTreeClient) list_markdown() !string {
|
||||
mut markdown_output := ''
|
||||
pages_map := c.list_pages_map()!
|
||||
|
||||
if pages_map.len == 0 {
|
||||
return 'No collections or pages found in this doctree.'
|
||||
}
|
||||
|
||||
mut sorted_collections := pages_map.keys()
|
||||
sorted_collections.sort()
|
||||
|
||||
for col_name in sorted_collections {
|
||||
page_names := pages_map[col_name]
|
||||
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
|
||||
}
|
||||
|
||||
@@ -60,11 +60,8 @@ pub fn (mut site DocSite) generate() ! {
|
||||
// draft:1 hide_title:1
|
||||
|
||||
configpath:="${site.path_src.path}/cfg"
|
||||
sitegen.play(heroscript_path: configpath)!
|
||||
sitegenpath := '${os.home_dir()}/hero/var/sitegen/${site.name}'
|
||||
if true || os.exists(sitegenpath) {
|
||||
panic("Sdsdsd:${sitegenpath}")
|
||||
}
|
||||
sitegen.play(heroscript_path: configpath, dest:'${site.factory.path_build.path}/docs', flat:true)!
|
||||
|
||||
site.process_imports()!
|
||||
}
|
||||
|
||||
|
||||
@@ -96,13 +96,7 @@ pub fn (mut f DocusaurusFactory) get(args_ DSiteGetArgs) !&DocSite {
|
||||
reset: args.update
|
||||
)!
|
||||
|
||||
// doctreename:="main"
|
||||
// mut tree := doctree.tree_get(doctreename) or {
|
||||
// return error("can't find doctree with name ${doctreename}\n list of trees: ${doctree.tree_list()}")
|
||||
// }
|
||||
// println(tree)
|
||||
// if true{panic("226")}
|
||||
|
||||
//the play will automatically do an export on ~/hero/var/doctree/main if no export specified in the heroscript
|
||||
|
||||
mut mysiteconfig := *siteconfig.new(configpath)!
|
||||
|
||||
|
||||
@@ -1,42 +1,54 @@
|
||||
module sitegen
|
||||
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
import freeflowuniverse.herolib.data.doctree
|
||||
import freeflowuniverse.herolib.web.doctreeclient
|
||||
import os
|
||||
|
||||
pub struct SiteFactory {
|
||||
pub mut:
|
||||
sites map[string]&Site
|
||||
path pathlib.Path
|
||||
tree &doctree.Tree
|
||||
client &doctreeclient.DocTreeClient
|
||||
flat bool // if flat then won't use sitenames as subdir's
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct SiteNewArgs {
|
||||
pub struct SiteFactoryArgs {
|
||||
pub mut:
|
||||
path string
|
||||
flat bool // if flat then won't use sitenames as subdir's
|
||||
}
|
||||
|
||||
|
||||
|
||||
// new creates a new siteconfig and stores it in redis, or gets an existing one
|
||||
pub fn new(tree &doctree.Tree, args SiteNewArgs) !SiteFactory {
|
||||
pub fn new(args SiteFactoryArgs) !SiteFactory {
|
||||
mut path := args.path
|
||||
if path == '' {
|
||||
path = '${os.home_dir()}/hero/var/sitegen'
|
||||
}
|
||||
mut factory := SiteFactory{
|
||||
path: pathlib.get_dir(path: path, create: true)!
|
||||
tree: tree
|
||||
client: doctreeclient.new()!
|
||||
flat:args.flat
|
||||
}
|
||||
return factory
|
||||
}
|
||||
|
||||
|
||||
pub fn (mut f SiteFactory) site_get(name string) !&Site {
|
||||
|
||||
|
||||
|
||||
mut s := f.sites[name] or {
|
||||
mut mypath:=f.path
|
||||
if !f.flat {
|
||||
mypath=f.path.dir_get_new(name)!
|
||||
}
|
||||
mut mysite:=&Site{
|
||||
path: f.path.dir_get_new(name)!
|
||||
path: mypath
|
||||
name: name
|
||||
tree: f.tree
|
||||
client: f.client
|
||||
}
|
||||
mysite
|
||||
}
|
||||
|
||||
@@ -2,8 +2,7 @@ module sitegen
|
||||
|
||||
import freeflowuniverse.herolib.core.playbook { PlayBook }
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.data.doctree
|
||||
|
||||
import os
|
||||
|
||||
@[params]
|
||||
pub struct PlayArgs {
|
||||
@@ -11,6 +10,8 @@ pub mut:
|
||||
heroscript string
|
||||
heroscript_path string
|
||||
plbook ?PlayBook
|
||||
dest string
|
||||
flat bool //if flat then won't use sitenames as subdir's
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +20,10 @@ pub fn play(args_ PlayArgs) ! {
|
||||
mut args := args_
|
||||
mut plbook := args.plbook or { playbook.new(text: args.heroscript,path:args.heroscript_path)! }
|
||||
|
||||
if args.dest==""{
|
||||
args.dest = '${os.home_dir()}/hero/var/sitegen'
|
||||
}
|
||||
|
||||
mut doctreename:="main"
|
||||
if plbook.exists(filter: 'site.doctree'){
|
||||
if plbook.exists_once(filter: 'site.doctree'){
|
||||
@@ -30,9 +35,6 @@ pub fn play(args_ PlayArgs) ! {
|
||||
}
|
||||
}
|
||||
|
||||
mut tree := doctree.tree_get(doctreename) or {
|
||||
return error("can't find doctree with name ${doctreename}\n list of trees: ${doctree.tree_list()}")
|
||||
}
|
||||
|
||||
// !!site.page name:"atest" path:"crazy/sub" position:1
|
||||
// src:"marketplace_specs:tft_tfp_marketplace"
|
||||
@@ -40,7 +42,7 @@ pub fn play(args_ PlayArgs) ! {
|
||||
// description:"A description not filled in"
|
||||
// draft:1 hide_title:1
|
||||
|
||||
mut factory:=new(tree)!
|
||||
mut factory:=new(path:args.dest,flat:args.flat)!
|
||||
|
||||
page_actions := plbook.find(filter: 'site.page')!
|
||||
mut mypage:=Page{src:"",path:""}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
module sitegen
|
||||
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
import freeflowuniverse.herolib.data.doctree
|
||||
|
||||
import freeflowuniverse.herolib.web.doctreeclient
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
pub struct Site {
|
||||
pub mut:
|
||||
name string
|
||||
path pathlib.Path
|
||||
tree &doctree.Tree
|
||||
client &doctreeclient.DocTreeClient
|
||||
}
|
||||
|
||||
|
||||
@@ -59,17 +59,27 @@ pub fn (mut site Site) page_add(args_ Page) ! {
|
||||
|
||||
mut c:=content.join("\n")
|
||||
|
||||
mut mypage:=site.tree.page_get(args.src) or {
|
||||
// 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()}")
|
||||
mut parts := args.src.split(':')
|
||||
if parts.len != 2 {
|
||||
return error("Invalid src format for page '${args.src}', expected format: collection:page_name")
|
||||
}
|
||||
collection_name := parts[0]
|
||||
page_name := parts[1]
|
||||
|
||||
mut page_content := site.client.get_page_content(collection_name, page_name) or {
|
||||
return error("Couldn't find page '${page_name}' in collection '${collection_name}' using doctreeclient. Available pages:\n${site.client.list_markdown()!}\nError: ${err}")
|
||||
}
|
||||
|
||||
c+="\n${mypage.get_markdown()!}\n"
|
||||
c+="\n${page_content}\n"
|
||||
|
||||
mut pagepath:= "${site.path.path}/${args.path}"
|
||||
mut pagefile:= pathlib.get_file(path:pagepath,create:true)!
|
||||
|
||||
console.print_debug("Writing page '${pagepath}'")
|
||||
|
||||
pagefile.write(c)!
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user