This commit is contained in:
2025-08-15 08:52:46 +02:00
parent 71298a9704
commit 43ffedfad8
36 changed files with 517 additions and 550 deletions

View File

@@ -4,9 +4,9 @@ import os
import freeflowuniverse.herolib.core.pathlib
__global (
docusaurus_sites map[string]&DocSite
docusaurus_sites map[string]&DocSite
docusaurus_config []DocusaurusConfigParams
docusaurus_last string //the last one we worked with
docusaurus_last string // the last one we worked with
)
pub struct DocusaurusConfig {
@@ -16,7 +16,7 @@ pub mut:
install bool
reset bool
template_update bool
coderoot string
coderoot string
}
@[params]
@@ -27,16 +27,16 @@ pub mut:
install bool
reset bool
template_update bool
coderoot string
coderoot string
}
//return the last know config
// return the last know config
pub fn config() !DocusaurusConfig {
if docusaurus_config.len == 0 {
docusaurus_config << DocusaurusConfigParams{}
}
mut args:= docusaurus_config[0] or { panic("bug in docusaurus config") }
if args.path_build == '' {
mut args := docusaurus_config[0] or { panic('bug in docusaurus config') }
if args.path_build == '' {
args.path_build = '${os.home_dir()}/hero/var/docusaurus/build'
}
if args.path_publish == '' {
@@ -47,16 +47,16 @@ pub fn config() !DocusaurusConfig {
}
mut c := DocusaurusConfig{
path_publish: pathlib.get_dir(path: args.path_publish, create: true)!
path_build: pathlib.get_dir(path: args.path_build, create: true)!
coderoot: args.coderoot
install: args.install
reset: args.reset
path_publish: pathlib.get_dir(path: args.path_publish, create: true)!
path_build: pathlib.get_dir(path: args.path_build, create: true)!
coderoot: args.coderoot
install: args.install
reset: args.reset
template_update: args.template_update
}
if c.install {
install(c)!
c.install=true
c.install = true
}
return c
}

View File

@@ -8,8 +8,8 @@ import freeflowuniverse.herolib.ui.console
@[heap]
pub struct DocSite {
pub mut:
name string
url string
name string
url string
// path_src pathlib.Path
path_publish pathlib.Path
path_build pathlib.Path
@@ -17,7 +17,7 @@ pub mut:
config Configuration
website sitemodule.Site
generated bool
}
}
pub fn (mut s DocSite) build() ! {
s.generate()!
@@ -51,20 +51,19 @@ pub fn (mut s DocSite) build_publish() ! {
retry: 0
)!
for item in s.website.siteconfig.build_dest {
if item.path.trim_space().trim("/ ") == "" {
$if debug{
if item.path.trim_space().trim('/ ') == '' {
$if debug {
print_backtrace()
}
return error("build destination path is empty for docusaurus.")
return error('build destination path is empty for docusaurus.')
}
osal.exec(
cmd: '
cmd: '
cd ${s.path_build.path}
rsync -avz --delete -e "ssh -p 22 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" build/ ${item.path}
'
)!
}
}
@[params]

View File

@@ -1,6 +1,5 @@
module docusaurus
import freeflowuniverse.herolib.core.pathlib
import json
import os
@@ -16,8 +15,8 @@ pub fn (mut docsite DocSite) generate() ! {
console.print_header(' docsite generate: ${docsite.name} on ${c.path_build.path}')
osal.rm('${c.path_build.path}/docs')!
cfg_path:="${c.path_build.path}/cfg"
cfg_path := '${c.path_build.path}/cfg'
osal.rm(cfg_path)!
mut main_file := pathlib.get_file(path: '${cfg_path}/main.json', create: true)!
@@ -32,5 +31,4 @@ pub fn (mut docsite DocSite) generate() ! {
docsite.generate_docs()!
docsite.import()!
}

View File

@@ -20,10 +20,9 @@ mut:
// Generate docs from site configuration
pub fn (mut docsite DocSite) generate_docs() ! {
c := config()!
//we generate the docs in the build path
// we generate the docs in the build path
docs_path := '${c.path_build.path}/docs'
mut gen := SiteGenerator{

View File

@@ -6,13 +6,10 @@ import freeflowuniverse.herolib.core.pathlib
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.core.texttools.regext
pub fn (mut docsite DocSite) import() ! {
for importparams in docsite.website.siteconfig.imports {
console.print_header('Importing: path:${importparams.path} or url:${importparams.url}')
// pub struct ImportItem {
// name string // will normally be empty
// url string // http git url can be to specific path
@@ -22,10 +19,10 @@ pub fn (mut docsite DocSite) import() ! {
// visible bool = true
// }
c:=config()!
c := config()!
if importparams.path == "" && importparams.url != "" {
return error("in import for docusaurus need to specify url or path")
if importparams.path == '' && importparams.url != '' {
return error('in import for docusaurus need to specify url or path')
}
// Use gittools to get path of what we want to import
@@ -37,11 +34,11 @@ pub fn (mut docsite DocSite) import() ! {
path: importparams.path
)!
if import_path.path == "" {
return error("import path not found for url:${importparams.url} and path:${importparams.path}")
if import_path.path == '' {
return error('import path not found for url:${importparams.url} and path:${importparams.path}')
}
if importparams.dest.starts_with("/") {
return error("Import path ${importparams.dest} must be relative, will be relative in relation to the build dir.")
if importparams.dest.starts_with('/') {
return error('Import path ${importparams.dest} must be relative, will be relative in relation to the build dir.')
}
import_path.copy(dest: '${c.path_build.path}/${importparams.dest}', delete: false)!

View File

@@ -24,7 +24,7 @@ pub fn dsite_define(sitename string) ! {
// Create the DocSite instance
mut dsite := &DocSite{
name: sitename
path_publish: pathlib.get_dir(path: "${path_build_}/build", create: true)!
path_publish: pathlib.get_dir(path: '${path_build_}/build', create: true)!
path_build: pathlib.get_dir(path: path_build_, create: true)!
config: new_configuration(website.siteconfig)!
website: website
@@ -36,7 +36,7 @@ pub fn dsite_define(sitename string) ! {
pub fn dsite_get(name_ string) !&DocSite {
mut name := texttools.name_fix(name_)
if name=="" {
if name == '' {
name = docusaurus_last
}
return docusaurus_sites[name] or {
@@ -46,9 +46,9 @@ pub fn dsite_get(name_ string) !&DocSite {
pub fn dsite_exists(name_ string) !bool {
mut name := texttools.name_fix(name_)
if name=="" {
if name == '' {
name = docusaurus_last
}
}
_ := docusaurus_sites[name] or { return false }
return true
}

View File

@@ -6,7 +6,7 @@ import freeflowuniverse.herolib.develop.gittools
import freeflowuniverse.herolib.osal.core as osal
import freeflowuniverse.herolib.installers.web.bun
fn install( c DocusaurusConfig) ! {
fn install(c DocusaurusConfig) ! {
mut gs := gittools.new()!
if c.reset {
@@ -22,7 +22,7 @@ fn install( c DocusaurusConfig) ! {
mut template_path0 := pathlib.get_dir(path: template_path, create: false)!
template_path0.copy(dest: c.path_build.path, delete: false)! //the dir has already been deleted so no point to delete again
template_path0.copy(dest: c.path_build.path, delete: false)! // the dir has already been deleted so no point to delete again
// install bun
mut installer := bun.get()!
@@ -36,5 +36,4 @@ fn install( c DocusaurusConfig) ! {
bun install
'
)!
}

View File

@@ -9,7 +9,7 @@ pub fn play(mut plbook PlayBook) ! {
return
}
//there should be 1 define section
// there should be 1 define section
mut action_define := plbook.ensure_once(filter: 'docusaurus.define')!
mut param_define := action_define.params
@@ -24,10 +24,9 @@ pub fn play(mut plbook PlayBook) ! {
site_name := param_define.get('name') or {
return error('In docusaurus.define, param "name" is required.')
}
dsite_define(site_name)!
action_define.done = true
mut dsite := dsite_get(site_name)!
@@ -47,7 +46,6 @@ pub fn play(mut plbook PlayBook) ! {
action.done = true
}
mut actions_build := plbook.find(filter: 'docusaurus.build')!
if actions_build.len > 1 {
return error('Multiple "docusaurus.build" actions found. Only one is allowed.')

View File

@@ -1,6 +1,6 @@
module docusaurus
//not longer working because is coming from doctree
// not longer working because is coming from doctree
// import freeflowuniverse.herolib.osal.notifier
// import os
@@ -97,9 +97,6 @@ module docusaurus
// }
// }
// pub fn (mut s DocSite) dev_watch(args DevArgs) ! {
// s.generate()!