refactor: Generalize playbook find method and restructure site module

- Replace `actions_find` with a more generic `find(filter:)`
- Rename `siteconfig` module and related types to `site`
- Introduce a `Site` object to encapsulate configuration
- Update site generation to accept a playbook object directly
- Remove redundant blank lines and format code
This commit is contained in:
Mahmoud-Emad
2025-07-31 14:02:46 +03:00
parent d3d7eccf3d
commit e6c1d84836
10 changed files with 58 additions and 63 deletions

View File

@@ -3,7 +3,7 @@ module docusaurus
import freeflowuniverse.herolib.osal.screen
import os
import freeflowuniverse.herolib.core.pathlib
import freeflowuniverse.herolib.web.siteconfig
import freeflowuniverse.herolib.web.site as sitemodule
import freeflowuniverse.herolib.develop.gittools
import freeflowuniverse.herolib.osal.core as osal
import freeflowuniverse.herolib.ui.console
@@ -12,32 +12,32 @@ import time
@[heap]
pub struct DocSite {
pub mut:
name string
url string
path_src pathlib.Path
name string
url string
path_src pathlib.Path
path_publish pathlib.Path
args DSiteGetArgs
errors []SiteError
config Configuration
siteconfig siteconfig.SiteConfig
siteconfig sitemodule.SiteConfig
factory &DocusaurusFactory @[skip; str: skip] // Reference to the parent
}
@[params]
pub struct DSiteGetArgs {
pub mut:
name string
nameshort string
path string
git_url string
git_reset bool
git_root string
git_pull bool
open bool // Added
watch_changes bool // Added
path_publish string // Added
init bool // Added
update bool // Added (maps to template_update in DocusaurusArgs)
name string
nameshort string
path string
git_url string
git_reset bool
git_root string
git_pull bool
open bool // Added
watch_changes bool // Added
path_publish string // Added
init bool // Added
update bool // Added (maps to template_update in DocusaurusArgs)
}
pub fn (mut s DocSite) build() ! {

View File

@@ -4,12 +4,11 @@ import os
import freeflowuniverse.herolib.core.pathlib
import freeflowuniverse.herolib.core.texttools
import freeflowuniverse.herolib.develop.gittools
import freeflowuniverse.herolib.web.siteconfig
import freeflowuniverse.herolib.web.site
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.osal.core as osal
// import freeflowuniverse.herolib.data.doctree
pub fn (mut f DocusaurusFactory) add(args_ DSiteGetArgs) !&DocSite {
console.print_header(' Docusaurus: ${args_.name}')
mut args := args_
@@ -53,7 +52,7 @@ pub fn (mut f DocusaurusFactory) add(args_ DSiteGetArgs) !&DocSite {
if args.nameshort.len == 0 {
args.nameshort = args.name
}
args.name = texttools.name_fix(args.name)
args.nameshort = texttools.name_fix(args.nameshort)
@@ -61,8 +60,9 @@ pub fn (mut f DocusaurusFactory) add(args_ DSiteGetArgs) !&DocSite {
args.path_publish = '${f.path_publish}/${args.name}'
}
//this will get us the siteconfig run through plbook
mut mysiteconfig := *siteconfig.new(configpath)!
// this will get us the siteconfig run through plbook
mut mysite := site.new(name: args.name)!
mut mysiteconfig := mysite.siteconfig
// NOT NEEDED IS DONE FROM HEROSCRIPT BEFORE
// //now run the plbook to get all relevant for the site, {SITENAME} has been set in the context.session
@@ -71,9 +71,8 @@ pub fn (mut f DocusaurusFactory) add(args_ DSiteGetArgs) !&DocSite {
// reset: args.update
// )!
mut ds := DocSite{
name: args.name
name: args.name
path_src: pathlib.get_dir(path: args.path, create: false)!
path_publish: pathlib.get_dir(path: args.path_publish)!
args: args

View File

@@ -3,7 +3,7 @@ module docusaurus
// import os
// import json
// import freeflowuniverse.herolib.core.pathlib
import freeflowuniverse.herolib.web.siteconfig // For siteconfig.SiteConfig and siteconfig.new
import freeflowuniverse.herolib.web.site // For site.SiteConfig and site.new
// import strings // No longer needed as we are not concatenating
// import freeflowuniverse.herolib.core.playbook // No longer directly needed here
@@ -79,9 +79,9 @@ pub mut:
}
fn config_load(path string) !Configuration {
// Use siteconfig.new from factory.v. This function handles PlayBook creation, playing, and Redis interaction.
site_cfg_ref := siteconfig.new(path)!
site_cfg_from_heroscript := *site_cfg_ref // Dereference to get the actual SiteConfig struct
// Use site.new from factory.v. This function handles PlayBook creation, playing, and Redis interaction.
site_ref := site.new(name: 'default')!
site_cfg_from_heroscript := site_ref.siteconfig // Get the actual SiteConfig struct
// Transform siteconfig.SiteConfig to docusaurus.Configuration
mut nav_items := []NavbarItem{}

View File

@@ -2,13 +2,14 @@ module docusaurus
import freeflowuniverse.herolib.develop.gittools
import freeflowuniverse.herolib.core.pathlib
import freeflowuniverse.herolib.core.playbook
import json
import os
import freeflowuniverse.herolib.osal.core as osal
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.core.texttools.regext
// import freeflowuniverse.herolib.data.doctree
import freeflowuniverse.herolib.web.site
import freeflowuniverse.herolib.web.site as sitegen
pub fn (mut site DocSite) generate() ! {
console.print_header(' site generate: ${site.name} on ${site.factory.path_build.path}')
@@ -46,9 +47,9 @@ pub fn (mut site DocSite) generate() ! {
mut footer_file := pathlib.get_file(path: '${cfg_path}/footer.json', create: true)!
footer_file.write(json.encode_pretty(site.config.footer))!
osal.rm("${site.factory.path_build.path}/docs")!
osal.rm('${site.factory.path_build.path}/docs')!
if os.exists("${site.path_src.path}/docs"){
if os.exists('${site.path_src.path}/docs') {
mut aa := site.path_src.dir_get('docs')!
aa.copy(dest: '${site.factory.path_build.path}/docs', delete: true)!
}
@@ -62,12 +63,10 @@ pub fn (mut site DocSite) generate() ! {
// draft:1 hide_title:1
configpath := '${site.path_src.path}/cfg'
sitegen.play(mut sitegen.Args{
heroscript_path: configpath
dest: '${site.factory.path_build.path}/docs'
flat: true
sitename: site.name
})!
// Create a playbook from the config path and run site processing
mut plbook := playbook.new(path: configpath)!
sitegen.play(mut plbook)!
site.process_imports()!
}