This commit is contained in:
2025-05-19 07:37:10 +04:00
parent 238fabbcb2
commit 97dfcbeb51
7 changed files with 201 additions and 107 deletions

46
lib/web/site/factory.v Normal file
View File

@@ -0,0 +1,46 @@
module site
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.core.texttools
__global (
doctrees shared map[string]&SiteConfig
)
@[params]
pub struct SiteConfigArgsGet {
pub mut:
name string = 'default'
path string
}
// new creates a new siteconfig and stores it in global map
pub fn new(args_ SiteConfigArgsGet) !&SiteConfig {
mut args := args_
args.name = texttools.name_fix(args.name)
mut t := SiteConfig{
name: args.name
}
set(t)
if args.path != '' {
mut plbook := playbook.new(path: args.path)!
play(plbook:plbook)!
}
return &t
}
// tree_get gets siteconfig from global map
pub fn get(name string) !&SiteConfig {
rlock doctrees {
if name in doctrees {
return doctrees[name] or { return error('SiteConfig ${name} not found') }
}
}
return error("can't get siteconfig:'${name}'")
}
// tree_set stores siteconfig in global map
pub fn set(siteconfig SiteConfig) {
lock doctrees {
doctrees[siteconfig.name] = &siteconfig
}
}