This commit is contained in:
2025-07-19 17:08:33 +02:00
parent 555272eeb3
commit e8d4d0afe6
12 changed files with 81 additions and 64 deletions

View File

@@ -11,7 +11,7 @@ docusaurus.new(
!!docusaurus.add name:"tfgrid_docs"
git_url:"https://git.threefold.info/tfgrid/docs_tfgrid4/src/branch/main/ebooks/tech"
git_root:"/tmp/code"
// git_root:"/tmp/code"
// git_reset:1
// git_pull:1

View File

@@ -20,7 +20,7 @@ pub fn play(args_ PlayArgs) ! {
mut doctrees := map[string]&Tree{}
collection_actions := plbook.find(filter: 'doctree.collection')!
collection_actions := plbook.find(filter: 'doctree.scan')!
for action in collection_actions {
mut p := action.params
name := p.get_default('name', 'main')!
@@ -34,6 +34,9 @@ pub fn play(args_ PlayArgs) ! {
git_reset := p.get_default_false('git_reset')
git_pull := p.get_default_false('git_pull')
doctree.scan(path: path, git_url: git_url, git_reset: git_reset, git_pull: git_pull)!
tree_set(doctree)
}
export_actions := plbook.find(filter: 'doctree.export')!
@@ -62,4 +65,10 @@ pub fn play(args_ PlayArgs) ! {
exclude_errors: exclude_errors
)!
}
// println(tree_list())
// println(tree_get("main")!)
// panic("sd")
}

View File

@@ -6,6 +6,7 @@ import freeflowuniverse.herolib.data.doctree.collection { Collection }
import freeflowuniverse.herolib.develop.gittools
import os
import freeflowuniverse.herolib.core.texttools
import freeflowuniverse.herolib.ui.console
@[params]
pub struct TreeScannerArgs {
@@ -37,6 +38,9 @@ pub fn (mut tree Tree) scan(args TreeScannerArgs) ! {
git_root: args.git_root
git_pull: args.git_pull
)!
console.print_header('doctree.scan: ${path.path}')
if !path.is_dir() {
return error('path is not a directory')
}

View File

@@ -61,7 +61,7 @@ pub fn tree_get(name string) !&Tree {
return doctrees[name] or { return error('Doctree ${name} not found') }
}
}
return error("cann't doctree:'${name}'")
return error("can't get doctree:'${name}'")
}
pub fn tree_exist(name string) bool {
@@ -73,6 +73,12 @@ pub fn tree_exist(name string) bool {
return false
}
pub fn tree_list() []string {
rlock doctrees {
return doctrees.keys()
}
}
// tree_set stores tree in global map
pub fn tree_set(tree Tree) {

View File

@@ -14,6 +14,7 @@ pub fn (mut site DocSite) generate() ! {
console.print_header(' site generate: ${site.name} on ${site.factory.path_build.path}')
console.print_header(' site source on ${site.path_src.path}')
// lets make sure we remove the cfg dir so we rebuild
cfg_path := os.join_path(site.factory.path_build.path, 'cfg')
osal.rm(cfg_path)!
@@ -60,11 +61,11 @@ pub fn (mut site DocSite) generate() ! {
configpath:="${site.path_src.path}/cfg"
sitegen.play(heroscript_path: configpath)!
// sitegenpath := '${os.home_dir()}/hero/var/sitegen/${site.name}'
// if os.exists(sitegenpath) {
// panic("Sdsdsd:${sitegenpath}")
// }
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) {
panic("Sdsdsd:${sitegenpath}")
}
site.process_imports()!
}

View File

@@ -35,6 +35,7 @@ pub fn (mut f DocusaurusFactory) get(args_ DSiteGetArgs) !&DocSite {
console.print_header(' Docusaurus: ${args_.name}')
mut args := args_
mut path := gittools.path(
path: args.path
git_url: args.git_url
@@ -95,6 +96,14 @@ 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")}
mut mysiteconfig := *siteconfig.new(configpath)!
mut ds := DocSite{

View File

@@ -37,6 +37,8 @@ pub fn play(args_ PlayArgs) ! {
)!
}
actions := plbook.find(filter: 'docusaurus.add')!
for action in actions {
mut p := action.params
@@ -46,6 +48,7 @@ pub fn play(args_ PlayArgs) ! {
git_reset := p.get_default_false('git_reset')
git_pull := p.get_default_false('git_pull')
mut site := ds.get(
name: name
nameshort: p.get_default('nameshort', name)!
@@ -62,6 +65,7 @@ pub fn play(args_ PlayArgs) ! {
init: p.get_default_false('init')
)!
if plbook.exists_once(filter: 'docusaurus.dev') {
site.dev()!
}

View File

@@ -13,7 +13,7 @@ pub mut:
footer Footer
menu Menu
imports []ImportItem
pages []Page
// pages []Page
// New fields for Docusaurus compatibility
url string // The main URL of the site (from !!site.config url:)
@@ -27,18 +27,18 @@ pub mut:
build_dest_dev []BuildDest // Development build destinations (from !!site.build_dest_dev)
}
pub struct Page {
pub mut:
name string
content string
title string
description string
draft bool
folder string
prio int
src string
collection string
}
// pub struct Page {
// pub mut:
// name string
// content string
// title string
// description string
// draft bool
// folder string
// prio int
// src string
// collection string
// }
// Footer config structures
pub struct FooterItem {
@@ -89,7 +89,7 @@ pub mut:
name string // will normally be empty
url string // http git url can be to specific path
path string
dest string // location in the docs folder of the place where we will build docusaurus
dest string // location in the docs folder of the place where we will build the documentation site e.g. docusaurus
replace map[string]string // will replace ${NAME} in the imported content
visible bool = true
}

View File

@@ -51,7 +51,7 @@ pub fn play(args_ PlayArgs) ! {
play_import(mut plbook, mut config)!
play_menu(mut plbook, mut config)!
play_footer(mut plbook, mut config)!
play_pages(mut plbook, mut config)!
// play_pages(mut plbook, mut config)!
play_build_dest(mut plbook, mut config)!
play_build_dest_dev(mut plbook, mut config)!
@@ -100,7 +100,7 @@ fn play_config(mut plbook PlayBook, mut config SiteConfig) ! {
fn play_import(mut plbook PlayBook, mut config SiteConfig) ! {
import_actions := plbook.find(filter: 'site.import')!
println('import_actions: ${import_actions}')
// println('import_actions: ${import_actions}')
for action in import_actions {
mut p := action.params
mut replace_map := map[string]string{}
@@ -199,23 +199,23 @@ fn play_footer(mut plbook PlayBook, mut config SiteConfig) ! {
}
}
fn play_pages(mut plbook PlayBook, mut config SiteConfig) ! {
page_actions := plbook.find(filter: 'site.page')!
// println('page_actions: ${page_actions}')
for action in page_actions {
mut p := action.params
// fn play_pages(mut plbook PlayBook, mut config SiteConfig) ! {
// page_actions := plbook.find(filter: 'site.page')!
// // println('page_actions: ${page_actions}')
// for action in page_actions {
// mut p := action.params
mut page := Page{
name: p.get('name')!
title: p.get_default('title', '')!
description: p.get_default('description', '')!
content: p.get_default('content', '')!
src: p.get_default('src', '')!
draft: p.get_default_false('draft')
folder: p.get_default('folder', '')!
prio: p.get_int_default('prio', 0)!
}
// mut page := Page{
// name: p.get('name')!
// title: p.get_default('title', '')!
// description: p.get_default('description', '')!
// content: p.get_default('content', '')!
// src: p.get_default('src', '')!
// draft: p.get_default_false('draft')
// folder: p.get_default('folder', '')!
// prio: p.get_int_default('prio', 0)!
// }
config.pages << page
}
}
// config.pages << page
// }
// }

View File

@@ -1,18 +0,0 @@
# Site Generation Library
This library provides functionalities for generating static websites. It includes tools for defining site structures, managing content, and rendering pages.
## Purpose
The `sitegen` library aims to simplify the process of creating and maintaining static websites by offering a programmatic approach to site generation. It allows developers to define their site's layout, content, and navigation using code, which can then be rendered into a complete static website.
## Key Features
- **Site Structure Definition**: Define the overall structure of your website, including pages, sections, and navigation.
- **Content Management**: Integrate with various content sources to populate your website.
- **Template Rendering**: Render content into HTML pages using flexible templating mechanisms.
- **Asset Management**: Handle static assets like CSS, JavaScript, and images.
## Usage
(Further details on usage will be added as the library evolves and specific functionalities are implemented.)

View File

@@ -19,7 +19,7 @@ pub fn play(args_ PlayArgs) ! {
mut args := args_
mut plbook := args.plbook or { playbook.new(text: args.heroscript,path:args.heroscript_path)! }
mut doctreename:="default"
mut doctreename:="main"
if plbook.exists(filter: 'site.doctree'){
if plbook.exists_once(filter: 'site.doctree'){
mut action:=plbook.action_get(actor:'site',name:'doctree')!
@@ -30,8 +30,8 @@ pub fn play(args_ PlayArgs) ! {
}
}
mut tree := doctree.new(name: doctreename) or {
return error("can't find doctree with name ${doctreename}")
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
@@ -45,8 +45,9 @@ pub fn play(args_ PlayArgs) ! {
page_actions := plbook.find(filter: 'site.page')!
mut mypage:=Page{src:"",path:""}
for action in page_actions {
println(action)
mut p := action.params
sitename := p.get('sitename') or { return error("need to specify name in site.page") }
sitename := p.get('sitename') or { return error("need to specify sitename in site.page") }
mypage.path = p.get_default('path', "")!
pagename := mypage.path.split('/').last()
mypage.position = p.get_int_default('position', 0)!

View File

@@ -60,6 +60,7 @@ 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")
}