refactor: dynamically load site config from heroscript

- Process heroscript files using a playbook
- Dynamically add config, menus, and page files
- Retrieve site config from the processed playbook
- Override site description from meta config
- Remove unused 'deploykey' flag and import
This commit is contained in:
Mahmoud-Emad
2025-08-03 17:33:23 +03:00
parent d747977185
commit 2502f0a655
2 changed files with 51 additions and 6 deletions

View File

@@ -2,7 +2,8 @@ module herocmds
import freeflowuniverse.herolib.web.docusaurus
import freeflowuniverse.herolib.web.site
import freeflowuniverse.herolib.core.pathlib
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.core.playcmds
import os
import cli { Command, Flag }
@@ -123,7 +124,6 @@ fn cmd_docusaurus_execute(cmd Command) ! {
mut open := cmd.flags.get_bool('open') or { false }
mut url := cmd.flags.get_string('url') or { '' }
mut publish_path := cmd.flags.get_string('publish') or { '' }
mut deploykey := cmd.flags.get_string('deploykey') or { '' }
// --- Build Path Logic ---
mut build_path := cmd.flags.get_string('buildpath') or { '' }
@@ -155,8 +155,51 @@ fn cmd_docusaurus_execute(cmd Command) ! {
mut builddevpublish := cmd.flags.get_bool('builddevpublish') or { false }
mut dev := cmd.flags.get_bool('dev') or { false }
// Create a site first using the new API
mut generic_site := site.new(name: 'cli_site')!
// Process heroscript files from the ebook directory to get proper site configuration
mut plbook := playbook.new(path: heroscript_config_dir)!
// Dynamically add ebook configuration files
config_file := '${heroscript_config_dir}/config.heroscript'
if os.exists(config_file) {
println('DEBUG: Adding config file: ${config_file}')
plbook.add(path: config_file)!
}
menus_file := '${heroscript_config_dir}/menus.heroscript'
if os.exists(menus_file) {
println('DEBUG: Adding menus file: ${menus_file}')
plbook.add(path: menus_file)!
}
pages_dir := '${heroscript_config_dir}/pages'
if os.exists(pages_dir) && os.is_dir(pages_dir) {
println('DEBUG: Adding pages directory: ${pages_dir}')
plbook.add(path: pages_dir)!
}
playcmds.run(plbook: plbook)!
// Process site pages to generate the actual documentation files
site.play(mut plbook)!
// Get the site configuration that was processed from the heroscript files
// The site.play() function processes the heroscript and creates sites in the global websites map
// We need to get the site by name from the processed configuration
config_actions := plbook.find(filter: 'site.config')!
if config_actions.len == 0 {
return error('No site.config found in heroscript files. Make sure config.heroscript contains !!site.config.')
}
// Debug: Check if site.page actions are found
page_actions := plbook.find(filter: 'site.page')!
// Get the site name from the first site.config action
site_name := config_actions[0].params.get('name') or {
return error('site.config must specify a name parameter')
}
// Get the processed site configuration
mut generic_site := site.get(name: site_name)!
// Add docusaurus site
mut dsite := docusaurus.add(

View File

@@ -80,8 +80,10 @@ fn play_config(mut plbook PlayBook) !&Site {
config.meta_title = p_meta.get_default('title', config.title)!
// If 'image' is present in site.config_meta, it overrides. Otherwise, meta_image remains empty or uses site.config.image logic.
config.meta_image = p_meta.get_default('image', config.image)!
// 'description' from site.config_meta can also be parsed here if a separate meta_description field is added to
// For now, config.description (from site.config) is used as the primary source or fallback.
// If 'description' is present in site.config_meta, it overrides the main description
if p_meta.exists('description') {
config.description = p_meta.get('description')!
}
return website
}