...
This commit is contained in:
9
examples/webtools/siteconfig.vsh
Executable file
9
examples/webtools/siteconfig.vsh
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -cg -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.web.siteconfig
|
||||
import os
|
||||
mypath :='${os.dir(@FILE)}/siteconfigexample'
|
||||
|
||||
mut sc:=siteconfig.new(path:mypath)!
|
||||
|
||||
println(sc)
|
||||
@@ -2,7 +2,7 @@ module openai
|
||||
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
// import freeflowuniverse.herolib.ui.console
|
||||
|
||||
__global (
|
||||
openai_global map[string]&OpenAI
|
||||
|
||||
@@ -44,7 +44,8 @@ pub fn (mut plbook PlayBook) add(args_ PlayBookNewArgs) ! {
|
||||
mut paths := ol0.paths.clone()
|
||||
mut ol1 := p.list(recursive: true, regex: [r'.*\.hero$'])!
|
||||
paths << ol1.paths
|
||||
|
||||
mut ol2 := p.list(recursive: true, regex: [r'.*\.heroscript$'])!
|
||||
paths << ol2.paths
|
||||
for mut p2 in paths {
|
||||
c2 := p2.read()!
|
||||
plbook.add(text: c2, prio: args.prio, session: args_.session)!
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
module site
|
||||
|
||||
module siteconfig
|
||||
// Combined config structure
|
||||
pub struct SiteConfig {
|
||||
pub mut:
|
||||
100
lib/web/siteconfig/example/config.heroscript
Normal file
100
lib/web/siteconfig/example/config.heroscript
Normal file
@@ -0,0 +1,100 @@
|
||||
!!site.config
|
||||
name:"depin"
|
||||
description:"ThreeFold is laying the foundation for a geo aware Web 4, the next generation of the Internet."
|
||||
tagline:"Geo Aware Internet Platform"
|
||||
favicon:"img/favicon.png"
|
||||
image:"img/tf_graph.png"
|
||||
copyright:"ThreeFold"
|
||||
|
||||
!!site.menu
|
||||
title:"ThreeFold DePIN Tech"
|
||||
logo_alt:"ThreeFold Logo"
|
||||
logo_src:"img/logo.svg"
|
||||
logo_src_dark:"img/new_logo_tft.png"
|
||||
|
||||
!!site.menu_item
|
||||
label:"ThreeFold.io"
|
||||
href:"https://threefold.io"
|
||||
position:"right"
|
||||
|
||||
!!site.menu_item
|
||||
label:"Mycelium Network"
|
||||
href:"https://mycelium.threefold.io/"
|
||||
position:"right"
|
||||
|
||||
!!site.menu_item
|
||||
label:"AI Box"
|
||||
href:"https://aibox.threefold.io/"
|
||||
position:"right"
|
||||
|
||||
!!site.footer
|
||||
style:"dark"
|
||||
|
||||
!!site.footer_item
|
||||
title:"Docs"
|
||||
label:"Introduction"
|
||||
href:"https://docs.threefold.io/docs/introduction"
|
||||
|
||||
!!site.footer_item
|
||||
title:"Docs"
|
||||
label:"Litepaper"
|
||||
href:"https://docs.threefold.io/docs/litepaper/"
|
||||
|
||||
!!site.footer_item
|
||||
title:"Docs"
|
||||
label:"Roadmap"
|
||||
href:"https://docs.threefold.io/docs/roadmap"
|
||||
|
||||
!!site.footer_item
|
||||
title:"Docs"
|
||||
label:"Manual"
|
||||
href:"https://manual.grid.tf/"
|
||||
|
||||
!!site.footer_item
|
||||
title:"Features"
|
||||
label:"Become a Farmer"
|
||||
href:"https://docs.threefold.io/docs/category/become-a-farmer"
|
||||
|
||||
!!site.footer_item
|
||||
title:"Features"
|
||||
label:"Components"
|
||||
href:"https://docs.threefold.io/docs/category/components"
|
||||
|
||||
!!site.footer_item
|
||||
title:"Features"
|
||||
label:"Technology"
|
||||
href:"https://threefold.info/tech/"
|
||||
|
||||
!!site.footer_item
|
||||
title:"Features"
|
||||
label:"Tokenomics"
|
||||
href:"https://docs.threefold.io/docs/tokens/tokenomics"
|
||||
|
||||
!!site.footer_item
|
||||
title:"Web"
|
||||
label:"ThreeFold.io"
|
||||
href:"https://threefold.io"
|
||||
|
||||
!!site.footer_item
|
||||
title:"Web"
|
||||
label:"Dashboard"
|
||||
href:"https://dashboard.grid.tf"
|
||||
|
||||
!!site.footer_item
|
||||
title:"Web"
|
||||
label:"GitHub"
|
||||
href:"https://github.com/threefoldtech/home"
|
||||
|
||||
!!site.footer_item
|
||||
title:"Web"
|
||||
label:"Mycelium Network"
|
||||
href:"https://mycelium.threefold.io/"
|
||||
|
||||
!!site.footer_item
|
||||
title:"Web"
|
||||
label:"AI Box"
|
||||
href:"https://www2.aibox.threefold.io/"
|
||||
|
||||
!!site.collections
|
||||
url:"https://github.com/example/external-docs"
|
||||
replace:"PROJECT_NAME:My Project, VERSION:1.0.0"
|
||||
18
lib/web/siteconfig/example/site.heroscript
Normal file
18
lib/web/siteconfig/example/site.heroscript
Normal file
@@ -0,0 +1,18 @@
|
||||
!!site.page name:intro
|
||||
description:"ThreeFold is laying the foundation for a geo aware Web 4, the next generation of the Internet."
|
||||
|
||||
//next is example where we use all properties, folder is where the page is located, prio is the order of the page, if not used the filled in from order in which we parse this config file
|
||||
!!site.page name:mycelium draft:true folder:"/specs/components" prio:4
|
||||
content:"the page content itself, only for small pages"
|
||||
title:"Mycelium as Title"
|
||||
description:"..."
|
||||
|
||||
!!site.page name:fungistor folder:"/specs/components" prio:1
|
||||
src:"mycollection:mycelium.md"
|
||||
title:"fungistor as Title"
|
||||
description:"...."
|
||||
|
||||
!!site.page name:fungistor folder:"/specs/components" prio:1
|
||||
src:"mycollection:mycelium" //can be without .md
|
||||
title:"fungistor as Title"
|
||||
description:"..."
|
||||
@@ -1,46 +1,50 @@
|
||||
module site
|
||||
module siteconfig
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.core.texttools
|
||||
|
||||
__global (
|
||||
doctrees shared map[string]&SiteConfig
|
||||
siteconfigs map[string]&SiteConfig
|
||||
siteconfigs_current string
|
||||
)
|
||||
|
||||
@[params]
|
||||
pub struct SiteConfigArgsGet {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
name string
|
||||
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 != '' {
|
||||
if args.name != '' {
|
||||
return error('can not set name and path at the same time')
|
||||
}
|
||||
mut plbook := playbook.new(path: args.path)!
|
||||
// println('playbook: ${plbook} \nfor ${args.path}')
|
||||
play(plbook:plbook)!
|
||||
}
|
||||
return &t
|
||||
mut i:=get(siteconfigs_current) or { panic(err) }
|
||||
|
||||
args.name = texttools.name_fix(args.name)
|
||||
if args.name == '' {
|
||||
args.name = siteconfigs_current
|
||||
}
|
||||
mut sc:=get(args.name)!
|
||||
return sc
|
||||
}
|
||||
|
||||
// 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') }
|
||||
}
|
||||
if name in siteconfigs {
|
||||
return siteconfigs[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
|
||||
}
|
||||
siteconfigs[siteconfig.name] = &siteconfig
|
||||
siteconfigs_current = siteconfig.name
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
module site
|
||||
module siteconfig
|
||||
|
||||
import freeflowuniverse.herolib.core.playbook { PlayBook }
|
||||
import freeflowuniverse.herolib.core.texttools
|
||||
@@ -21,13 +21,12 @@ pub fn play(args_ PlayArgs) ! {
|
||||
mut config:= SiteConfig{}
|
||||
|
||||
play_config(mut plbook, mut config)!
|
||||
set(config)
|
||||
|
||||
play_collections(mut plbook, mut config)!
|
||||
play_menu(mut plbook, mut config)!
|
||||
play_footer(mut plbook, mut config)!
|
||||
play_pages(mut plbook, mut config)!
|
||||
|
||||
set(config)
|
||||
siteconfigs_current = config.name
|
||||
}
|
||||
|
||||
fn play_config(mut plbook PlayBook, mut config SiteConfig) ! {
|
||||
@@ -54,6 +53,7 @@ fn play_config(mut plbook PlayBook, mut config SiteConfig) ! {
|
||||
|
||||
fn play_collections(mut plbook PlayBook, mut config SiteConfig) ! {
|
||||
import_actions := plbook.find(filter: 'site.collections')!
|
||||
// println('import_actions: ${import_actions}')
|
||||
for action in import_actions {
|
||||
mut p := action.params
|
||||
mut replace_map := map[string]string{}
|
||||
@@ -132,6 +132,7 @@ fn play_footer(mut plbook PlayBook, mut config SiteConfig) ! {
|
||||
|
||||
fn play_pages(mut plbook PlayBook, mut config SiteConfig) ! {
|
||||
page_actions := plbook.find(filter: 'site.page')!
|
||||
// println('page_actions: ${page_actions}')
|
||||
for action in page_actions {
|
||||
mut p := action.params
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module site
|
||||
module siteconfig
|
||||
import os
|
||||
|
||||
fn test_play_collections() ! {
|
||||
Reference in New Issue
Block a user