...
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
#!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.data.encoder
|
||||
import crypto.ed25519
|
||||
@@ -30,9 +30,9 @@ console.print_debug('${e.data}')
|
||||
// do decoding
|
||||
mut d := encoder.decoder_new(e.data)
|
||||
mut aa := AStruct{}
|
||||
aa.items = d.get_list_string()
|
||||
aa.nr = d.get_int()
|
||||
aa.privkey = d.get_bytes()
|
||||
aa.items = d.get_list_string()!
|
||||
aa.nr = d.get_int()!
|
||||
aa.privkey = d.get_bytes()!
|
||||
|
||||
assert a == aa
|
||||
|
||||
|
||||
@@ -8,3 +8,5 @@ import freeflowuniverse.herolib.develop.gittools
|
||||
mut gs := gittools.get(reload: true)!
|
||||
|
||||
gs.repos_print()!
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -cg -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.web.docusaurus
|
||||
import os
|
||||
|
||||
// Create a new docusaurus factory
|
||||
mut docs := docusaurus.new(
|
||||
build_path: '/tmp/docusaurus_build'
|
||||
mut ds := docusaurus.new(
|
||||
path_build: '/tmp/docusaurus_build'
|
||||
path_publish: '/tmp/docusaurus_publish'
|
||||
)!
|
||||
|
||||
mut site:=ds.get(path:"${os.home_dir()}/code/git.threefold.info/tfgrid/docs_tfgrid4/ebooks/tech",name:"atest")!
|
||||
|
||||
println(site)
|
||||
|
||||
site.generate()!
|
||||
0
examples/web/docusaurus_example_cli.sh
Executable file → Normal file
0
examples/web/docusaurus_example_cli.sh
Executable file → Normal file
@@ -7,8 +7,7 @@ import os
|
||||
import markdown
|
||||
import freeflowuniverse.herolib.data.markdownparser2
|
||||
|
||||
path2 := '${os.home_dir()}/code/github/freeflowuniverse/herolib/examples/webtools/mdbook_markdown/content/links.md'
|
||||
path1 := '${os.home_dir()}/code/github/freeflowuniverse/herolib/examples/webtools/mdbook_markdown/content/test.md'
|
||||
path1 := '${os.home_dir()}/code/github/freeflowuniverse/herolib/examples/web/mdbook_markdown/content/cybercity.md'
|
||||
|
||||
text := os.read_file(path1)!
|
||||
|
||||
@@ -17,11 +16,3 @@ println('=== PLAINTEXT RENDERING ===')
|
||||
println(markdown.to_plain(text))
|
||||
println('')
|
||||
|
||||
// Example 2: Using our custom structure renderer to show markdown structure
|
||||
println('=== STRUCTURE RENDERING ===')
|
||||
println(markdownparser2.to_structure(text))
|
||||
|
||||
// // Example 3: Using a simple markdown example to demonstrate structure
|
||||
// println('\n=== STRUCTURE OF A SIMPLE MARKDOWN EXAMPLE ===')
|
||||
// simple_md := '# Heading 1\n\nThis is a paragraph with **bold** and *italic* text.\n\n- List item 1\n- List item 2\n\n```v\nfn main() {\n\tprintln("Hello, world!")\n}\n```\n\n[Link to V language](https://vlang.io)'
|
||||
// println(markdown.to_structure(simple_md))
|
||||
|
||||
@@ -16,8 +16,8 @@ pub mut:
|
||||
name string
|
||||
url string
|
||||
path_src pathlib.Path
|
||||
path_build pathlib.Path
|
||||
// path_publish pathlib.Path
|
||||
// path_build pathlib.Path
|
||||
path_publish pathlib.Path
|
||||
args DSiteGetArgs
|
||||
errors []SiteError
|
||||
config Configuration
|
||||
@@ -28,7 +28,7 @@ pub fn (mut s DocSite) build() ! {
|
||||
s.generate()!
|
||||
osal.exec(
|
||||
cmd: '
|
||||
cd ${s.path_build.path}
|
||||
cd ${s.factory.path_build.path}
|
||||
exit 1
|
||||
'
|
||||
retry: 0
|
||||
@@ -39,7 +39,7 @@ pub fn (mut s DocSite) build_dev_publish() ! {
|
||||
s.generate()!
|
||||
osal.exec(
|
||||
cmd: '
|
||||
cd ${s.path_build.path}
|
||||
cd ${s.factory.path_build.path}
|
||||
exit 1
|
||||
'
|
||||
retry: 0
|
||||
@@ -50,7 +50,7 @@ pub fn (mut s DocSite) build_publish() ! {
|
||||
s.generate()!
|
||||
osal.exec(
|
||||
cmd: '
|
||||
cd ${s.path_build.path}
|
||||
cd ${s.factory.path_build.path}
|
||||
exit 1
|
||||
'
|
||||
retry: 0
|
||||
@@ -74,7 +74,7 @@ pub fn (mut s DocSite) dev(args DevArgs) ! {
|
||||
s.generate()!
|
||||
osal.exec(
|
||||
cmd: '
|
||||
cd ${s.path_build.path}
|
||||
cd ${s.factory.path_build.path}
|
||||
bun run start -p ${args.port} -h ${args.host}
|
||||
'
|
||||
retry: 0
|
||||
@@ -99,8 +99,8 @@ pub fn (mut s DocSite) dev_watch(args DevArgs) ! {
|
||||
)!
|
||||
|
||||
// Send commands to the screen session
|
||||
console.print_item('To view the server output:: cd ${s.path_build.path}')
|
||||
scr.cmd_send('cd ${s.path_build.path}')!
|
||||
console.print_item('To view the server output:: cd ${s.factory.path_build.path}')
|
||||
scr.cmd_send('cd ${s.factory.path_build.path}')!
|
||||
|
||||
// Start script recording in the screen session for log streaming
|
||||
log_file := '/tmp/docusaurus_${screen_name}.log'
|
||||
@@ -143,7 +143,7 @@ pub fn (mut s DocSite) dev_watch(args DevArgs) ! {
|
||||
|
||||
if s.args.watch_changes {
|
||||
docs_path := '${s.path_src.path}/docs'
|
||||
watch_docs(docs_path, s.path_src.path, s.path_build.path)!
|
||||
watch_docs(docs_path, s.path_src.path, s.factory.path_build.path)!
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,18 +199,3 @@ pub fn (mut site DocSite) error(args ErrorArgs) {
|
||||
console.print_stderr(args.msg)
|
||||
}
|
||||
|
||||
fn check_item(item string) ! {
|
||||
item2 := item.trim_space().trim('/').trim_space().all_after_last('/')
|
||||
if ['internal', 'infodev', 'info', 'dev', 'friends', 'dd', 'web'].contains(item2) {
|
||||
return error('destination path is wrong, cannot be: ${item}')
|
||||
}
|
||||
}
|
||||
|
||||
fn (mut site DocSite) check() ! {
|
||||
for item in site.config.main.build_dest {
|
||||
check_item(item)!
|
||||
}
|
||||
for item in site.config.main.build_dest_dev {
|
||||
check_item(item)!
|
||||
}
|
||||
}
|
||||
|
||||
20
lib/web/docusaurus/dsite_check.v
Normal file
20
lib/web/docusaurus/dsite_check.v
Normal file
@@ -0,0 +1,20 @@
|
||||
module docusaurus
|
||||
|
||||
|
||||
//to avoid overwriting wrong locations
|
||||
|
||||
fn check_item(item string) ! {
|
||||
item2 := item.trim_space().trim('/').trim_space().all_after_last('/')
|
||||
if ['internal', 'infodev', 'info', 'dev', 'friends', 'dd', 'web'].contains(item2) {
|
||||
return error('destination path is wrong, cannot be: ${item}')
|
||||
}
|
||||
}
|
||||
|
||||
fn (mut site DocSite) check() ! {
|
||||
for item in site.config.main.build_dest {
|
||||
check_item(item)!
|
||||
}
|
||||
for item in site.config.main.build_dest_dev {
|
||||
check_item(item)!
|
||||
}
|
||||
}
|
||||
188
lib/web/docusaurus/dsite_configuration.v
Normal file
188
lib/web/docusaurus/dsite_configuration.v
Normal file
@@ -0,0 +1,188 @@
|
||||
module docusaurus
|
||||
|
||||
// import os
|
||||
// import json
|
||||
// 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 mut:
|
||||
main Main
|
||||
navbar Navbar
|
||||
footer Footer
|
||||
}
|
||||
|
||||
pub struct Main {
|
||||
pub mut:
|
||||
title string
|
||||
tagline string
|
||||
favicon string
|
||||
url string
|
||||
base_url string @[json: 'baseUrl']
|
||||
url_home string
|
||||
image string
|
||||
metadata Metadata
|
||||
build_dest []string @[json: 'buildDest']
|
||||
build_dest_dev []string @[json: 'buildDestDev']
|
||||
copyright string
|
||||
name string
|
||||
}
|
||||
|
||||
pub struct Metadata {
|
||||
pub mut:
|
||||
description string
|
||||
image string
|
||||
title string
|
||||
}
|
||||
|
||||
pub struct Navbar {
|
||||
pub mut:
|
||||
title string
|
||||
logo Logo
|
||||
items []NavbarItem
|
||||
}
|
||||
|
||||
pub struct Logo {
|
||||
pub mut:
|
||||
alt string
|
||||
src string
|
||||
src_dark string @[json: 'srcDark']
|
||||
}
|
||||
|
||||
pub struct NavbarItem {
|
||||
pub mut:
|
||||
label string
|
||||
href string
|
||||
position string
|
||||
to string
|
||||
}
|
||||
|
||||
pub struct Footer {
|
||||
pub mut:
|
||||
style string
|
||||
links []FooterLink
|
||||
}
|
||||
|
||||
pub struct FooterLink {
|
||||
pub mut:
|
||||
title string
|
||||
items []FooterItem
|
||||
}
|
||||
|
||||
pub struct FooterItem {
|
||||
pub mut:
|
||||
label string
|
||||
href 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
|
||||
// }
|
||||
|
||||
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
|
||||
|
||||
// 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
|
||||
url: site_cfg_from_heroscript.url
|
||||
base_url: site_cfg_from_heroscript.base_url
|
||||
url_home: site_cfg_from_heroscript.url_home
|
||||
image: site_cfg_from_heroscript.image // General site image
|
||||
metadata: Metadata{
|
||||
title: site_cfg_from_heroscript.meta_title // Specific title for metadata
|
||||
description: site_cfg_from_heroscript.description
|
||||
image: site_cfg_from_heroscript.meta_image // Use the specific meta_image from siteconfig
|
||||
}
|
||||
build_dest: site_cfg_from_heroscript.build_dest.map(it.path)
|
||||
build_dest_dev: site_cfg_from_heroscript.build_dest_dev.map(it.path)
|
||||
copyright: site_cfg_from_heroscript.copyright
|
||||
name: site_cfg_from_heroscript.name
|
||||
}
|
||||
navbar: Navbar{
|
||||
title: site_cfg_from_heroscript.menu.title
|
||||
logo: Logo{
|
||||
alt: site_cfg_from_heroscript.menu.logo_alt
|
||||
src: site_cfg_from_heroscript.menu.logo_src
|
||||
src_dark: site_cfg_from_heroscript.menu.logo_src_dark
|
||||
}
|
||||
items: nav_items
|
||||
}
|
||||
footer: Footer{
|
||||
style: site_cfg_from_heroscript.footer.style
|
||||
links: footer_links
|
||||
}
|
||||
}
|
||||
return config_fix(cfg)!
|
||||
|
||||
}
|
||||
|
||||
fn config_fix(config Configuration) !Configuration {
|
||||
return Configuration{
|
||||
...config
|
||||
main: Main{
|
||||
...config.main
|
||||
title: if config.main.title == '' { 'Docusaurus' } else { config.main.title }
|
||||
favicon: if config.main.favicon == '' { 'img/favicon.ico' } else { config.main.favicon }
|
||||
url: if config.main.url == '' { 'https://example.com' } else { config.main.url }
|
||||
base_url: if config.main.base_url == '' { '/' } else { config.main.base_url }
|
||||
}
|
||||
}
|
||||
}
|
||||
68
lib/web/docusaurus/dsite_generate.v
Normal file
68
lib/web/docusaurus/dsite_generate.v
Normal file
@@ -0,0 +1,68 @@
|
||||
module docusaurus
|
||||
|
||||
import freeflowuniverse.herolib.develop.gittools
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
import json
|
||||
import os
|
||||
import freeflowuniverse.herolib.osal
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
pub fn (mut site DocSite) generate() ! {
|
||||
console.print_header(' site generate: ${site.name} on ${site.factory.path_build.path}')
|
||||
console.print_header(' site source on ${site.path_src.path}')
|
||||
|
||||
//lets make sure we remove the cfg dir so we rebuild
|
||||
cfg_path := os.join_path(site.factory.path_build.path, 'cfg')
|
||||
osal.rm(cfg_path)!
|
||||
|
||||
mut gs := gittools.new()!
|
||||
|
||||
template_path := gs.get_path(
|
||||
pull: false
|
||||
reset: false
|
||||
url: 'https://github.com/freeflowuniverse/docusaurus_template/src/branch/main/template/'
|
||||
)!
|
||||
|
||||
//we need to copy the template each time for these 2 items, otherwise there can be leftovers from other run
|
||||
for item in ["src","static"]{
|
||||
mut template_src_path:=pathlib.get_dir(path:"${template_path}/${item}",create:true)!
|
||||
template_src_path.copy(dest: '${site.factory.path_build.path}/${item}', delete: true)!
|
||||
//now copy the info which can be overruled from source in relation to the template
|
||||
if os.exists("${site.path_src.path}/${item}"){
|
||||
mut src_path:=pathlib.get_dir(path:"${site.path_src.path}/${item}",create:false)!
|
||||
src_path.copy(dest: '${site.factory.path_build.path}/${item}', delete: false)!
|
||||
}
|
||||
}
|
||||
|
||||
mut main_file := pathlib.get_file(path: '${cfg_path}/main.json', create: true)!
|
||||
main_file.write(json.encode(site.config.main))!
|
||||
|
||||
mut navbar_file := pathlib.get_file(path: '${cfg_path}/navbar.json', create: true)!
|
||||
navbar_file.write(json.encode(site.config.navbar))!
|
||||
|
||||
mut footer_file := pathlib.get_file(path: '${cfg_path}/footer.json', create: true)!
|
||||
footer_file.write(json.encode(site.config.footer))!
|
||||
|
||||
mut aa := site.path_src.dir_get("docs")!
|
||||
aa.copy(dest: '${site.factory.path_build.path}/docs', delete: true)!
|
||||
|
||||
site.download_collections()!
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
pub fn (mut site DocSite) download_collections() ! {
|
||||
|
||||
// mut gs := gittools.new()!
|
||||
// for item in site.config.import_sources {
|
||||
// mypath := gs.get_path(
|
||||
// pull: false
|
||||
// reset: false
|
||||
// url: item.url
|
||||
// )!
|
||||
// mut mypatho := pathlib.get(mypath)
|
||||
// site.process_md(mut mypatho, item)!
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import freeflowuniverse.herolib.core.pathlib
|
||||
import freeflowuniverse.herolib.core.texttools
|
||||
import freeflowuniverse.herolib.develop.gittools
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.osal
|
||||
|
||||
@[params]
|
||||
pub struct DSiteGetArgs {
|
||||
@@ -13,27 +14,21 @@ pub mut:
|
||||
nameshort string
|
||||
path string
|
||||
url string
|
||||
publish_path string
|
||||
build_path string
|
||||
path_publish string //default empty
|
||||
// path_build string //default empty
|
||||
production bool
|
||||
watch_changes bool = true
|
||||
update bool
|
||||
open bool
|
||||
init bool // means create new one if needed
|
||||
deploykey string
|
||||
config ?Configuration
|
||||
// config ?Configuration
|
||||
}
|
||||
|
||||
pub fn (mut f DocusaurusFactory) get(args_ DSiteGetArgs) !&DocSite {
|
||||
console.print_header(' Docusaurus: ${args_.name}')
|
||||
mut args := args_
|
||||
|
||||
if args.build_path.len == 0 {
|
||||
args.build_path = '${f.path_build.path}'
|
||||
}
|
||||
// if args.publish_path.len == 0 {
|
||||
// args.publish_path = '${f.path_publish.path}/${args.name}'
|
||||
|
||||
// coderoot:"${os.home_dir()}/hero/var/publishcode"
|
||||
mut gs := gittools.new(ssh_key_path: args.deploykey)!
|
||||
|
||||
@@ -46,52 +41,30 @@ pub fn (mut f DocusaurusFactory) get(args_ DSiteGetArgs) !&DocSite {
|
||||
}
|
||||
args.path = args.path.replace('~', os.home_dir())
|
||||
|
||||
// First, check if the new site args provides a configuration
|
||||
if cfg := args.config {
|
||||
// Use the provided config
|
||||
generate_configuration(args.path, cfg)!
|
||||
} else if f.config.main.title != '' {
|
||||
// Use the factory's config from heroscript if available
|
||||
generate_configuration(args.path, f.config)!
|
||||
// } else {
|
||||
// // Then ensure cfg directory exists in src,
|
||||
// if !os.exists('${args.path}/cfg') {
|
||||
// if args.init {
|
||||
// // else copy config from template
|
||||
// mut template_cfg := template_path.dir_get('cfg')!
|
||||
// template_cfg.copy(dest: '${args.path}/cfg')!
|
||||
// } else {
|
||||
// return error("Can't find cfg dir in chosen docusaurus location: ${args.path}")
|
||||
// }
|
||||
// }
|
||||
configpath:='${args.path}/cfg'
|
||||
if ! os.exists(configpath) {
|
||||
return error("can't find config file in ${configpath}")
|
||||
}
|
||||
|
||||
osal.rm("${args.path}/cfg/main.json")!
|
||||
osal.rm("${args.path}/cfg/footer.json")!
|
||||
osal.rm("${args.path}/cfg/navbar.json")!
|
||||
osal.rm("${args.path}/build.sh")!
|
||||
osal.rm("${args.path}/develop.sh")!
|
||||
osal.rm("${args.path}/sync.sh")!
|
||||
osal.rm("${args.path}/.DS_Store")!
|
||||
|
||||
if !os.exists('${args.path}/docs') {
|
||||
if args.init {
|
||||
// Create docs directory if it doesn't exist in template or site
|
||||
os.mkdir_all('${args.path}/docs')!
|
||||
|
||||
// Create a default docs/intro.md file
|
||||
intro_content := '---
|
||||
title: Introduction
|
||||
slug: /
|
||||
sidebar_position: 1
|
||||
---
|
||||
|
||||
# Introduction
|
||||
|
||||
Welcome to the documentation site.
|
||||
|
||||
This is a default page created by the Docusaurus site generator.
|
||||
'
|
||||
os.write_file('${args.path}/docs/intro.md', intro_content)!
|
||||
panic("implement")
|
||||
} else {
|
||||
return error("Can't find docs dir in chosen docusaurus location: ${args.path}")
|
||||
}
|
||||
}
|
||||
|
||||
mut myconfig := load_configuration('${args.path}/cfg') or {
|
||||
return error('Failed to load configuration from ${args.path}/cfg:\n${err.msg()}')
|
||||
}
|
||||
mut myconfig:=config_load(configpath)!
|
||||
|
||||
if myconfig.main.name.len == 0 {
|
||||
myconfig.main.name = myconfig.main.base_url.trim_space().trim('/').trim_space()
|
||||
@@ -106,17 +79,19 @@ This is a default page created by the Docusaurus site generator.
|
||||
}
|
||||
args.nameshort = texttools.name_fix(args.nameshort)
|
||||
|
||||
if args.path_publish == ""{
|
||||
args.path_publish = "${f.path_publish}/${args.name}"
|
||||
}
|
||||
|
||||
mut ds := DocSite{
|
||||
name: args.name
|
||||
url: args.url
|
||||
path_src: pathlib.get_dir(path: args.path, create: false)!
|
||||
path_build: f.path_build
|
||||
// path_publish: pathlib.get_dir(path: args.publish_path, create: true)!
|
||||
path_publish: pathlib.get_dir(path:args.path_publish)!
|
||||
args: args
|
||||
config: myconfig
|
||||
factory: &f
|
||||
}
|
||||
|
||||
ds.check()!
|
||||
|
||||
f.sites << &ds
|
||||
|
||||
@@ -13,7 +13,7 @@ pub struct DocusaurusFactory {
|
||||
pub mut:
|
||||
sites []&DocSite @[skip; str: skip]
|
||||
path_build pathlib.Path
|
||||
// path_publish pathlib.Path
|
||||
path_publish pathlib.Path
|
||||
args DocusaurusArgs
|
||||
config Configuration // Stores configuration from HeroScript if provided
|
||||
}
|
||||
@@ -21,8 +21,8 @@ pub mut:
|
||||
@[params]
|
||||
pub struct DocusaurusArgs {
|
||||
pub mut:
|
||||
// publish_path string
|
||||
build_path string
|
||||
path_publish string
|
||||
path_build string
|
||||
production bool
|
||||
update bool
|
||||
// heroscript string
|
||||
@@ -31,21 +31,21 @@ pub mut:
|
||||
|
||||
pub fn new(args_ DocusaurusArgs) !&DocusaurusFactory {
|
||||
mut args := args_
|
||||
if args.build_path == '' {
|
||||
args.build_path = '${os.home_dir()}/hero/var/docusaurus'
|
||||
if args.path_build == '' {
|
||||
args.path_build = '${os.home_dir()}/hero/var/docusaurus/build'
|
||||
}
|
||||
if args.path_publish == ""{
|
||||
args.path_publish = "${os.home_dir()}/hero/var/docusaurus/publish"
|
||||
}
|
||||
// if args.publish_path == ""{
|
||||
// args.publish_path = "${os.home_dir()}/hero/var/docusaurus/publish"
|
||||
// }
|
||||
|
||||
// Create the factory instance
|
||||
mut ds := &DocusaurusFactory{
|
||||
mut f := &DocusaurusFactory{
|
||||
args: args_
|
||||
path_build: pathlib.get_dir(path: args.build_path, create: true)!
|
||||
// path_publish: pathlib.get_dir(path: args_.publish_path, create: true)!
|
||||
path_build: pathlib.get_dir(path: args.path_build, create: true)!
|
||||
path_publish: pathlib.get_dir(path: args_.path_publish, create: true)!
|
||||
}
|
||||
|
||||
ds.template_install(install: true, template_update: args.update, delete: true)!
|
||||
f.template_install(install: args.update, template_update: args.update)!
|
||||
|
||||
return ds
|
||||
return f
|
||||
}
|
||||
|
||||
51
lib/web/docusaurus/factory_generate_template.v
Normal file
51
lib/web/docusaurus/factory_generate_template.v
Normal file
@@ -0,0 +1,51 @@
|
||||
module docusaurus
|
||||
|
||||
import freeflowuniverse.herolib.develop.gittools
|
||||
import freeflowuniverse.herolib.osal
|
||||
import freeflowuniverse.herolib.installers.web.bun
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
import os
|
||||
|
||||
|
||||
@[params]
|
||||
struct TemplateInstallArgs {
|
||||
mut:
|
||||
template_update bool = true
|
||||
install bool
|
||||
delete bool
|
||||
}
|
||||
|
||||
//copy template in build location
|
||||
fn (mut self DocusaurusFactory) template_install(args_ TemplateInstallArgs) ! {
|
||||
mut gs := gittools.new()!
|
||||
mut args:=args_
|
||||
|
||||
template_path := gs.get_path(
|
||||
pull: args.template_update
|
||||
reset: args.delete
|
||||
url: 'https://github.com/freeflowuniverse/docusaurus_template/src/branch/main/template'
|
||||
)!
|
||||
|
||||
mut template_path0:=pathlib.get_dir(path:template_path,create:false)!
|
||||
|
||||
template_path0.copy(dest: '${self.path_build.path}', delete: args.delete)!
|
||||
|
||||
if ! os.exists("${self.path_build.path}/node_modules"){
|
||||
args.install = true
|
||||
}
|
||||
|
||||
if args.install {
|
||||
// install bun
|
||||
mut installer := bun.get()!
|
||||
installer.install()!
|
||||
osal.exec(
|
||||
//always stay in the context of the build directory
|
||||
cmd: '
|
||||
${osal.profile_path_source_and()!}
|
||||
export PATH=${self.path_build.path}/node_modules/.bin::??{HOME}/.bun/bin/:??PATH
|
||||
cd ${self.path_build.path}
|
||||
bun install
|
||||
'
|
||||
)!
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
module docusaurus
|
||||
|
||||
import freeflowuniverse.herolib.develop.gittools
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
import json
|
||||
import os
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
@[params]
|
||||
struct TemplateInstallArgs {
|
||||
template_update bool = true
|
||||
install bool = true
|
||||
delete bool = true
|
||||
}
|
||||
|
||||
pub fn (mut site DocSite) generate() ! {
|
||||
console.print_header(' site generate: ${site.name} on ${site.path_build.path}')
|
||||
console.print_header(' site source on ${site.path_src.path}')
|
||||
site.check()!
|
||||
site.template_install()!
|
||||
|
||||
site.config = fix_configuration(site.config)!
|
||||
|
||||
cfg_path := os.join_path(site.path_build.path, 'cfg')
|
||||
|
||||
mut main_file := pathlib.get_file(path: '${cfg_path}/main.json', create: true)!
|
||||
main_file.write(json.encode(site.config.main))!
|
||||
|
||||
mut navbar_file := pathlib.get_file(path: '${cfg_path}/navbar.json', create: true)!
|
||||
navbar_file.write(json.encode(site.config.navbar))!
|
||||
|
||||
mut footer_file := pathlib.get_file(path: '${cfg_path}/footer.json', create: true)!
|
||||
footer_file.write(json.encode(site.config.footer))!
|
||||
|
||||
mut aa := site.path_src.dir_get("docs")!
|
||||
aa.copy(dest: '${site.path_build.path}/docs', delete: true)!
|
||||
|
||||
// mut gs := gittools.new()!
|
||||
// for item in site.config.import_sources {
|
||||
// mypath := gs.get_path(
|
||||
// pull: false
|
||||
// reset: false
|
||||
// url: item.url
|
||||
// )!
|
||||
// mut mypatho := pathlib.get(mypath)
|
||||
// site.process_md(mut mypatho, item)!
|
||||
// }
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
module docusaurus
|
||||
|
||||
import freeflowuniverse.herolib.develop.gittools
|
||||
import freeflowuniverse.herolib.osal
|
||||
import freeflowuniverse.herolib.installers.web.bun
|
||||
|
||||
|
||||
fn (mut self DocusaurusFactory) template_install(args TemplateInstallArgs) ! {
|
||||
mut gs := gittools.new()!
|
||||
|
||||
mut r := gs.get_repo(
|
||||
url: 'https://github.com/freeflowuniverse/docusaurus_template.git'
|
||||
pull: args.template_update
|
||||
)!
|
||||
mut template_path := r.patho()!
|
||||
template_path.copy(dest: '${self.path_build.path}/template/', delete: args.delete)!
|
||||
|
||||
if args.install {
|
||||
// install bun
|
||||
mut installer := bun.get()!
|
||||
installer.install()!
|
||||
osal.exec(
|
||||
//always stay in the context of the build directory
|
||||
cmd: '
|
||||
${osal.profile_path_source_and()!}
|
||||
export PATH=${self.path_build}/node_modules/.bin::??{HOME}/.bun/bin/:??PATH
|
||||
cd ${self.path_build.path}
|
||||
bun install
|
||||
'
|
||||
)!
|
||||
}
|
||||
}
|
||||
@@ -1,200 +0,0 @@
|
||||
module docusaurus
|
||||
|
||||
import os
|
||||
import json
|
||||
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 mut:
|
||||
main Main
|
||||
navbar Navbar
|
||||
footer Footer
|
||||
}
|
||||
|
||||
pub struct Main {
|
||||
pub mut:
|
||||
title string
|
||||
tagline string
|
||||
favicon string
|
||||
url string
|
||||
base_url string @[json: 'baseUrl']
|
||||
url_home string
|
||||
image string
|
||||
metadata Metadata
|
||||
build_dest []string @[json: 'buildDest']
|
||||
build_dest_dev []string @[json: 'buildDestDev']
|
||||
copyright string
|
||||
name string
|
||||
}
|
||||
|
||||
pub struct Metadata {
|
||||
pub mut:
|
||||
description string
|
||||
image string
|
||||
title string
|
||||
}
|
||||
|
||||
pub struct Navbar {
|
||||
pub mut:
|
||||
title string
|
||||
logo Logo
|
||||
items []NavbarItem
|
||||
}
|
||||
|
||||
pub struct Logo {
|
||||
pub mut:
|
||||
alt string
|
||||
src string
|
||||
src_dark string @[json: 'srcDark']
|
||||
}
|
||||
|
||||
pub struct NavbarItem {
|
||||
pub mut:
|
||||
label string
|
||||
href string
|
||||
position string
|
||||
to string
|
||||
}
|
||||
|
||||
pub struct Footer {
|
||||
pub mut:
|
||||
style string
|
||||
links []FooterLink
|
||||
}
|
||||
|
||||
pub struct FooterLink {
|
||||
pub mut:
|
||||
title string
|
||||
items []FooterItem
|
||||
}
|
||||
|
||||
pub struct FooterItem {
|
||||
pub mut:
|
||||
label string
|
||||
href 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 {
|
||||
primary_heroscript_filename := 'config.heroscript' // Define the primary HeroScript file to look for
|
||||
hero_script_main_file_path := os.join_path(cfg_path, primary_heroscript_filename)
|
||||
|
||||
if os.exists(hero_script_main_file_path) {
|
||||
println('Found primary HeroScript file: ${hero_script_main_file_path}. Attempting to load configuration.')
|
||||
|
||||
// Use siteconfig.new from factory.v. This function handles PlayBook creation, playing, and Redis interaction.
|
||||
site_cfg_ref := siteconfig.new(hero_script_main_file_path) or {
|
||||
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
|
||||
url: site_cfg_from_heroscript.url
|
||||
base_url: site_cfg_from_heroscript.base_url
|
||||
url_home: site_cfg_from_heroscript.url_home
|
||||
image: site_cfg_from_heroscript.image // General site image
|
||||
metadata: Metadata{
|
||||
title: site_cfg_from_heroscript.meta_title // Specific title for metadata
|
||||
description: site_cfg_from_heroscript.description
|
||||
image: site_cfg_from_heroscript.meta_image // Use the specific meta_image from siteconfig
|
||||
}
|
||||
build_dest: site_cfg_from_heroscript.build_dest.map(it.path)
|
||||
build_dest_dev: site_cfg_from_heroscript.build_dest_dev.map(it.path)
|
||||
copyright: site_cfg_from_heroscript.copyright
|
||||
name: site_cfg_from_heroscript.name
|
||||
}
|
||||
navbar: Navbar{
|
||||
title: site_cfg_from_heroscript.menu.title
|
||||
logo: Logo{
|
||||
alt: site_cfg_from_heroscript.menu.logo_alt
|
||||
src: site_cfg_from_heroscript.menu.logo_src
|
||||
src_dark: site_cfg_from_heroscript.menu.logo_src_dark
|
||||
}
|
||||
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 {
|
||||
return Configuration{
|
||||
...config
|
||||
main: Main{
|
||||
...config.main
|
||||
title: if config.main.title == '' { 'Docusaurus' } else { config.main.title }
|
||||
favicon: if config.main.favicon == '' { 'img/favicon.ico' } else { config.main.favicon }
|
||||
url: if config.main.url == '' { 'https://example.com' } else { config.main.url }
|
||||
base_url: if config.main.base_url == '' { '/' } else { config.main.base_url }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
module docusaurus
|
||||
|
||||
// fn (mut site DocSite) process_md(mut path pathlib.Path, args ImportSource) ! {
|
||||
// if path.is_dir() {
|
||||
// mut pathlist_images := path.list(
|
||||
// regex: [r'.*\.png$', r'.*\.jpg$', r'.*\.svg$', r'.*\.jpeg$']
|
||||
// recursive: true
|
||||
// )!
|
||||
// for mut mypatho_img in pathlist_images.paths {
|
||||
// // now copy the image to the dest
|
||||
// dest := '${site.path_build.path}/docs/${args.dest}/img/${texttools.name_fix(mypatho_img.name())}'
|
||||
// // println("image copy: ${dest}")
|
||||
// mypatho_img.copy(dest: dest, rsync: false)!
|
||||
// }
|
||||
|
||||
// mut pathlist := path.list(regex: [r'.*\.md$'], recursive: true)!
|
||||
// for mut mypatho2 in pathlist.paths {
|
||||
// site.process_md(mut mypatho2, args)!
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
// mydest := '${site.path_build.path}/docs/${args.dest}/${texttools.name_fix(path.name())}'
|
||||
// mut mydesto := pathlib.get_file(path: mydest, create: true)!
|
||||
|
||||
// mut mymd := markdownparser.new(path: path.path)!
|
||||
// mut myfm := mymd.frontmatter2()!
|
||||
// if !args.visible {
|
||||
// myfm.args['draft'] = 'true'
|
||||
// }
|
||||
// // println(myfm)
|
||||
// // println(mymd.markdown()!)
|
||||
// mydesto.write(mymd.markdown()!)!
|
||||
// // Note: exit(0) was removed to prevent unexpected program termination
|
||||
// }
|
||||
Reference in New Issue
Block a user