Files
herolib/lib/web/site/factory.v
Mahmoud-Emad 5f9a95f2ca refactor: Improve site configuration and navigation handling
- Consolidate site configuration loading and parsing
- Refactor navbar and menu item processing logic
- Add console output for configuration steps
- Update copyright year dynamically
- Simplify and clarify parameter handling
- Enhance error handling for missing required parameters
2025-12-01 15:32:09 +02:00

59 lines
1.1 KiB
V

module site
import incubaid.herolib.core.texttools
__global (
sites_global map[string]&Site
)
@[params]
pub struct FactoryArgs {
pub mut:
name string = 'default'
}
pub fn new(args FactoryArgs) !&Site {
name := texttools.name_fix(args.name)
// Check if a site with this name already exists
if name in sites_global {
// Return the existing site instead of creating a new one
return get(name: name)!
}
mut site := Site{
nav: SideBar{}
siteconfig: SiteConfig{
name: name
}
}
sites_global[name] = &site
return get(name: name)!
}
pub fn get(args FactoryArgs) !&Site {
name := texttools.name_fix(args.name)
// mut sc := sites_global[name] or { return error('siteconfig with name "${name}" does not exist') }
return sites_global[name] or {
print_backtrace()
return error('could not get site with name:${name}')
}
}
pub fn exists(args FactoryArgs) bool {
name := texttools.name_fix(args.name)
return name in sites_global
}
pub fn default() !&Site {
if sites_global.len == 0 {
return new(name: 'default')!
}
return get()!
}
// list returns all site names that have been created
pub fn list() []string {
return sites_global.keys()
}