fix docusaurus to use siteconfig in heroscript
This commit is contained in:
@@ -186,7 +186,7 @@ fn cmd_docusaurus_execute(cmd Command) ! {
|
|||||||
|
|
||||||
mut site := docs.get(
|
mut site := docs.get(
|
||||||
url: url
|
url: url
|
||||||
build_path: build_path
|
build_path: build_path
|
||||||
update: update
|
update: update
|
||||||
publish_path: publish_path
|
publish_path: publish_path
|
||||||
deploykey: deploykey
|
deploykey: deploykey
|
||||||
|
|||||||
@@ -95,7 +95,9 @@ This is a default page created by the Docusaurus site generator.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mut myconfig := load_configuration('${args.path}/cfg')!
|
mut myconfig := load_configuration('${args.path}/cfg') or {
|
||||||
|
return error("Failed to load configuration from ${args.path}/cfg:\n${err.msg()}")
|
||||||
|
}
|
||||||
|
|
||||||
if myconfig.main.name.len == 0 {
|
if myconfig.main.name.len == 0 {
|
||||||
myconfig.main.name = myconfig.main.base_url.trim_space().trim('/').trim_space()
|
myconfig.main.name = myconfig.main.base_url.trim_space().trim('/').trim_space()
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ module docusaurus
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import freeflowuniverse.herolib.core.pathlib
|
import freeflowuniverse.herolib.core.pathlib
|
||||||
|
import freeflowuniverse.herolib.web.siteconfig // For siteconfig.SiteConfig and siteconfig.new
|
||||||
|
// import strings // No longer needed as we are not concatenating
|
||||||
|
// import freeflowuniverse.herolib.core.playbook // No longer directly needed here
|
||||||
|
|
||||||
pub struct Configuration {
|
pub struct Configuration {
|
||||||
pub mut:
|
pub mut:
|
||||||
@@ -75,16 +78,100 @@ pub struct FooterItem {
|
|||||||
to string
|
to string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Private helper function for JSON loading logic
|
||||||
|
fn load_configuration_from_json(cfg_path string) !Configuration {
|
||||||
|
mut main_json_path := os.join_path(cfg_path, 'main.json')
|
||||||
|
mut navbar_json_path := os.join_path(cfg_path, 'navbar.json')
|
||||||
|
mut footer_json_path := os.join_path(cfg_path, 'footer.json')
|
||||||
|
|
||||||
|
if !os.exists(main_json_path) || !os.exists(navbar_json_path) || !os.exists(footer_json_path) {
|
||||||
|
return error('Missing one or more required JSON configuration files (main.json, navbar.json, footer.json) in ${cfg_path} and no primary HeroScript file was successfully processed.')
|
||||||
|
}
|
||||||
|
|
||||||
|
mut main_json_content := pathlib.get_file(path: main_json_path)!
|
||||||
|
mut navbar_json_content := pathlib.get_file(path: navbar_json_path)!
|
||||||
|
mut footer_json_content := pathlib.get_file(path: footer_json_path)!
|
||||||
|
|
||||||
|
main_data := json.decode(Main, main_json_content.read()!)!
|
||||||
|
navbar_data := json.decode(Navbar, navbar_json_content.read()!)!
|
||||||
|
footer_data := json.decode(Footer, footer_json_content.read()!)!
|
||||||
|
|
||||||
|
mut cfg := Configuration{
|
||||||
|
main: main_data,
|
||||||
|
navbar: navbar_data,
|
||||||
|
footer: footer_data,
|
||||||
|
}
|
||||||
|
return cfg
|
||||||
|
}
|
||||||
|
|
||||||
pub fn load_configuration(cfg_path string) !Configuration {
|
pub fn load_configuration(cfg_path string) !Configuration {
|
||||||
mut main_json := pathlib.get_file(path: os.join_path(cfg_path, 'main.json'))!
|
primary_heroscript_filename := 'config.heroscript' // Define the primary HeroScript file to look for
|
||||||
mut navbar_json := pathlib.get_file(path: os.join_path(cfg_path, 'navbar.json'))!
|
hero_script_main_file_path := os.join_path(cfg_path, primary_heroscript_filename)
|
||||||
mut footer_json := pathlib.get_file(path: os.join_path(cfg_path, 'footer.json'))!
|
|
||||||
mut cfg := Configuration{
|
if os.exists(hero_script_main_file_path) {
|
||||||
main: json.decode(Main, main_json.read()!)!,
|
println('Found primary HeroScript file: ${hero_script_main_file_path}. Attempting to load configuration.')
|
||||||
navbar: json.decode(Navbar, navbar_json.read()!)!,
|
|
||||||
footer: json.decode(Footer, footer_json.read()!)!
|
// Use siteconfig.new from factory.v. This function handles PlayBook creation, playing, and Redis interaction.
|
||||||
}
|
site_cfg_ref := siteconfig.new(cfg_path) or {
|
||||||
return cfg
|
eprintln('Error loading configuration from HeroScript file ${hero_script_main_file_path}: ${err}. Falling back to JSON.')
|
||||||
|
return load_configuration_from_json(cfg_path) // Fallback to JSON private helper
|
||||||
|
}
|
||||||
|
|
||||||
|
site_cfg_from_heroscript := *site_cfg_ref // Dereference to get the actual SiteConfig struct
|
||||||
|
|
||||||
|
// Transform siteconfig.SiteConfig to docusaurus.Configuration
|
||||||
|
mut nav_items := []NavbarItem{}
|
||||||
|
for item in site_cfg_from_heroscript.menu.items {
|
||||||
|
nav_items << NavbarItem{
|
||||||
|
label: item.label,
|
||||||
|
href: item.href,
|
||||||
|
position: item.position,
|
||||||
|
to: item.to,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mut footer_links := []FooterLink{}
|
||||||
|
for link in site_cfg_from_heroscript.footer.links {
|
||||||
|
mut footer_items_mapped := []FooterItem{}
|
||||||
|
for item in link.items {
|
||||||
|
footer_items_mapped << FooterItem{
|
||||||
|
label: item.label,
|
||||||
|
href: item.href,
|
||||||
|
to: item.to,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
footer_links << FooterLink{
|
||||||
|
title: link.title,
|
||||||
|
items: footer_items_mapped,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg := Configuration{
|
||||||
|
main: Main{
|
||||||
|
title: site_cfg_from_heroscript.title,
|
||||||
|
tagline: site_cfg_from_heroscript.tagline,
|
||||||
|
favicon: site_cfg_from_heroscript.favicon,
|
||||||
|
copyright: site_cfg_from_heroscript.copyright,
|
||||||
|
name: site_cfg_from_heroscript.name,
|
||||||
|
// url, base_url, url_home, image, metadata, build_dest etc. from site_cfg_from_heroscript.main if available
|
||||||
|
// or leave to fix_configuration. siteconfig.SiteConfig doesn't have a direct 'Main' substruct.
|
||||||
|
// These fields are top-level in siteconfig.SiteConfig.
|
||||||
|
},
|
||||||
|
navbar: Navbar{
|
||||||
|
title: site_cfg_from_heroscript.menu.title,
|
||||||
|
// logo: site_cfg_from_heroscript.menu.logo, // siteconfig.Menu doesn't have a direct logo struct like docusaurus.Logo
|
||||||
|
items: nav_items,
|
||||||
|
},
|
||||||
|
footer: Footer{
|
||||||
|
style: site_cfg_from_heroscript.footer.style,
|
||||||
|
links: footer_links,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return cfg
|
||||||
|
} else {
|
||||||
|
println('Primary HeroScript file (${primary_heroscript_filename}) not found in ${cfg_path}. Falling back to JSON configuration.')
|
||||||
|
return load_configuration_from_json(cfg_path)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fix_configuration(config Configuration) !Configuration {
|
pub fn fix_configuration(config Configuration) !Configuration {
|
||||||
|
|||||||
Reference in New Issue
Block a user