...
This commit is contained in:
21
examples/web/docusaurus_example.hero
Executable file
21
examples/web/docusaurus_example.hero
Executable file
@@ -0,0 +1,21 @@
|
||||
|
||||
!!docusaurus.define
|
||||
path_build: "/tmp/docusaurus_build"
|
||||
path_publish: "/tmp/docusaurus_publish"
|
||||
// reset: 1
|
||||
// install: 1
|
||||
// template_update: 1
|
||||
|
||||
!!docusaurus.add sitename:"owh_intro"
|
||||
git_url:"https://git.ourworld.tf/ourworld_holding/docs_owh/src/branch/main/ebooks/owh_intro"
|
||||
git_root:"/tmp/code"
|
||||
git_reset:1
|
||||
git_pull:1
|
||||
play:true
|
||||
|
||||
// !!docusaurus.build
|
||||
|
||||
!!docusaurus.dev site:"owh_intro" open:true
|
||||
|
||||
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -cg -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import incubaid.herolib.core.playcmds
|
||||
|
||||
playcmds.run(
|
||||
heroscript: '
|
||||
!!docusaurus.define
|
||||
path_build: "/tmp/docusaurus_build"
|
||||
path_publish: "/tmp/docusaurus_publish"
|
||||
// reset: 1
|
||||
// install: 1
|
||||
// template_update: 1
|
||||
|
||||
!!docusaurus.add sitename:"owh_intro"
|
||||
git_url:"https://git.ourworld.tf/ourworld_holding/docs_owh/src/branch/main/ebooks/owh_intro"
|
||||
git_root:"/tmp/code"
|
||||
git_reset:1
|
||||
git_pull:1
|
||||
play:true
|
||||
|
||||
// !!docusaurus.build
|
||||
|
||||
!!docusaurus.dev site:"owh_intro" open:true
|
||||
'
|
||||
)!
|
||||
20
examples/web/site/site_example.vsh
Executable file
20
examples/web/site/site_example.vsh
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -cg -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import os
|
||||
import incubaid.herolib.develop.gittools
|
||||
import incubaid.herolib.web.site
|
||||
import incubaid.herolib.core.playcmds
|
||||
|
||||
url := 'https://git.ourworld.tf/tfgrid/docs_tfgrid4/src/branch/main/ebooks/tech'
|
||||
|
||||
mysitepath := gittools.path(
|
||||
// git_pull: true
|
||||
// git_reset: true
|
||||
git_url: url
|
||||
// git_root: '/tmp/code'
|
||||
)!
|
||||
|
||||
playcmds.run(heroscript_path: mysitepath.path)!
|
||||
|
||||
mut mysite := site.get(name: 'tfgrid_tech')!
|
||||
println(mysite)
|
||||
@@ -42,7 +42,6 @@ you can now just execute this script and hero will interprete the content
|
||||
```v
|
||||
|
||||
import incubaid.herolib.core.playbook
|
||||
import incubaid.herolib.core.playcmds
|
||||
|
||||
mut plbook := playbook.new(path: "....") or { panic(err) }
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# how to use the playcmds
|
||||
|
||||
## simplified
|
||||
|
||||
```v
|
||||
import incubaid.herolib.core.playcmds
|
||||
|
||||
@@ -11,3 +13,29 @@ playcmds.run(
|
||||
)!
|
||||
|
||||
```
|
||||
|
||||
## with more control
|
||||
|
||||
```v
|
||||
#!/usr/bin/env -S v -n -w -gc none -cg -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import incubaid.herolib.develop.gittools
|
||||
import incubaid.herolib.web.site
|
||||
import incubaid.herolib.core.playcmds
|
||||
|
||||
url := "https://git.ourworld.tf/tfgrid/docs_tfgrid4/src/branch/main/ebooks/tech"
|
||||
|
||||
mysitepath := gittools.path(
|
||||
// git_pull: true
|
||||
// git_reset: true
|
||||
git_url: url
|
||||
git_root: '/tmp/code'
|
||||
)!
|
||||
|
||||
playcmds.run(heroscript_path:mysitepath.path)!
|
||||
|
||||
mut mysite:=site.get(name:"tfgrid_tech")!
|
||||
println(mysite)
|
||||
|
||||
|
||||
```
|
||||
@@ -1,100 +0,0 @@
|
||||
!!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"
|
||||
to:"intro"
|
||||
|
||||
!!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"
|
||||
@@ -1,18 +0,0 @@
|
||||
!!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,29 +1,16 @@
|
||||
module site
|
||||
|
||||
@[heap]
|
||||
pub struct Site {
|
||||
pub mut:
|
||||
pages []Page
|
||||
sections []Section
|
||||
siteconfig SiteConfig
|
||||
}
|
||||
|
||||
pub struct Page {
|
||||
pub mut:
|
||||
name string
|
||||
title string
|
||||
description string
|
||||
draft bool
|
||||
position int
|
||||
hide_title bool
|
||||
src string @[required] // always in format collection:page_name
|
||||
path string @[required]
|
||||
src string @[required] // always in format collection:page_name, can use the default collection if no : specified
|
||||
path string @[required] //is without the page name, so just the path to the folder where the page is in
|
||||
section_name string
|
||||
title_nr int
|
||||
slug string
|
||||
}
|
||||
|
||||
pub struct Section {
|
||||
pub mut:
|
||||
position int
|
||||
path string
|
||||
label string
|
||||
}
|
||||
17
lib/web/site/model_site_section.v
Normal file
17
lib/web/site/model_site_section.v
Normal file
@@ -0,0 +1,17 @@
|
||||
module site
|
||||
|
||||
@[heap]
|
||||
pub struct Site {
|
||||
pub mut:
|
||||
pages []Page
|
||||
sections []Section
|
||||
siteconfig SiteConfig
|
||||
}
|
||||
|
||||
pub struct Section {
|
||||
pub mut:
|
||||
name string
|
||||
position int
|
||||
path string
|
||||
label string
|
||||
}
|
||||
@@ -73,6 +73,7 @@ pub mut:
|
||||
ssh_name string
|
||||
}
|
||||
|
||||
//is to import one docusaurus site into another, can be used to e.g. import static parts from one location into the build one we are building
|
||||
pub struct ImportItem {
|
||||
pub mut:
|
||||
name string // will normally be empty
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
module site
|
||||
|
||||
import incubaid.herolib.core.playbook { PlayBook }
|
||||
import incubaid.herolib.core.texttools
|
||||
|
||||
// plays the sections & pages
|
||||
fn play_pages(mut plbook PlayBook, mut site Site) ! {
|
||||
@@ -18,72 +19,105 @@ fn play_pages(mut plbook PlayBook, mut site Site) ! {
|
||||
}
|
||||
}
|
||||
|
||||
// LETS FIRST DO THE CATEGORIES
|
||||
mut category_actions := plbook.find(filter: 'site.page_category')!
|
||||
mut section := Section{}
|
||||
for mut action in category_actions {
|
||||
// println(action)
|
||||
mut p := action.params
|
||||
section.position = p.get_int_default('position', 20)!
|
||||
section.label = p.get('label') or {
|
||||
return error('need to specify label in site.page_category')
|
||||
}
|
||||
section.path = p.get('path') or {
|
||||
return error('need to specify path in site.page_category')
|
||||
}
|
||||
site.sections << section
|
||||
action.done = true // Mark the action as done
|
||||
}
|
||||
mut section_current := Section{} // is the category
|
||||
mut position_section := 1
|
||||
mut collection_current := '' // current collection we are working on
|
||||
|
||||
mut all_actions := plbook.find(filter: 'site.')!
|
||||
|
||||
for mut action in all_actions {
|
||||
if action.done {
|
||||
continue
|
||||
}
|
||||
|
||||
mut page_actions := plbook.find(filter: 'site.page')!
|
||||
mut mypage := Page{
|
||||
src: ''
|
||||
path: ''
|
||||
}
|
||||
mut position_next := 1
|
||||
mut position := 0
|
||||
mut path := ''
|
||||
for mut action in page_actions {
|
||||
// println(action)
|
||||
mut p := action.params
|
||||
pathnew := p.get_default('path', '')!
|
||||
if pathnew != '' {
|
||||
mypage.path = path
|
||||
if pathnew.ends_with('.md') {
|
||||
// means we fully specified the name
|
||||
mypage.path = pathnew
|
||||
|
||||
if action.name == 'page_category' {
|
||||
mut section := Section{}
|
||||
section.name = p.get('name') or {
|
||||
return error('need to specify name in site.page_category.\n${action}')
|
||||
}
|
||||
position_section = 1 // go back to default position for pages in the category
|
||||
section.position = p.get_int_default('position', section_current.position * 100)!
|
||||
section.label = p.get('label') or {
|
||||
return error('need to specify label in site.page_category.\n${action}')
|
||||
}
|
||||
section.path = p.get_default('path', texttools.name_fix(section.label))!
|
||||
|
||||
site.sections << section
|
||||
action.done = true // Mark the action as done
|
||||
section_current = section
|
||||
continue // next action
|
||||
}
|
||||
|
||||
if action.name == 'page' {
|
||||
mut pagesrc := p.get_default('src', '')!
|
||||
mut pagename := p.get_default('name', '')!
|
||||
mut pagecollection := ''
|
||||
|
||||
if pagesrc.contains(':') {
|
||||
pagecollection = pagesrc.split(':')[0]
|
||||
pagename = pagesrc.split(':')[1]
|
||||
} else {
|
||||
// only remember path if no .md file specified
|
||||
path = pathnew
|
||||
if !path.ends_with('/') {
|
||||
path += '/'
|
||||
if collection_current.len > 0 {
|
||||
pagecollection = collection_current
|
||||
} else {
|
||||
return error('need to specify collection in page.src path as collection:page_name or make sure someone before you did.\n${action}')
|
||||
}
|
||||
// println(' -- NEW PATH: ${path}')
|
||||
mypage.path = path
|
||||
}
|
||||
} else {
|
||||
mypage.path = path
|
||||
}
|
||||
position = p.get_int_default('position', 0)!
|
||||
if position == 0 {
|
||||
position = position_next
|
||||
position_next += 1
|
||||
} else {
|
||||
if position > position_next {
|
||||
position_next = position + 1
|
||||
|
||||
pagecollection = texttools.name_fix(pagecollection)
|
||||
collection_current = pagecollection
|
||||
pagename = texttools.name_fix_keepext(pagename)
|
||||
if pagename.ends_with('.md') {
|
||||
pagename = pagename.replace('.md', '')
|
||||
}
|
||||
|
||||
if pagename == '' {
|
||||
return error('need to specify name in page.src or specify in path as collection:page_name.\n${action}')
|
||||
}
|
||||
if pagecollection == '' {
|
||||
return error('need to specify collection in page.src or specify in path as collection:page_name.\n${action}')
|
||||
}
|
||||
|
||||
// recreate the pagepath
|
||||
pagesrc = '${pagecollection}:${pagename}'
|
||||
|
||||
// get sectionname from category, page_category or section, if not specified use current section
|
||||
section_name := p.get_default('category', p.get_default('page_category', p.get_default('section',
|
||||
section_current.name)!)!)!
|
||||
mut pagepath := p.get_default('path', section_name)!
|
||||
pagepath = pagepath.trim_space().trim('/')
|
||||
pagepath = texttools.name_fix(pagepath)
|
||||
|
||||
mut mypage := Page{
|
||||
section_name: section_name
|
||||
name: pagename
|
||||
path: pagepath
|
||||
src: pagesrc
|
||||
}
|
||||
|
||||
mypage.position = p.get_int_default('position', 0)!
|
||||
if mypage.position == 0 {
|
||||
mypage.position = section_current.position * 100 + position_section
|
||||
position_section += 1
|
||||
}
|
||||
mypage.title = p.get_default('title', '')!
|
||||
|
||||
mypage.description = p.get_default('description', '')!
|
||||
mypage.slug = p.get_default('slug', '')!
|
||||
mypage.draft = p.get_default_false('draft')
|
||||
mypage.hide_title = p.get_default_false('hide_title')
|
||||
mypage.title_nr = p.get_int_default('title_nr', 0)!
|
||||
|
||||
site.pages << mypage
|
||||
|
||||
action.done = true // Mark the action as done
|
||||
}
|
||||
mypage.position = position
|
||||
mypage.src = p.get('src') or { return error('need to specify src in site.page') }
|
||||
mypage.title = p.get_default('title', '')!
|
||||
mypage.description = p.get_default('description', '')!
|
||||
mypage.slug = p.get_default('slug', '')!
|
||||
mypage.draft = p.get_default_false('draft')
|
||||
mypage.hide_title = p.get_default_false('hide_title')
|
||||
mypage.title_nr = p.get_int_default('title_nr', 0)!
|
||||
|
||||
site.pages << mypage
|
||||
|
||||
action.done = true // Mark the action as done
|
||||
println(action)
|
||||
println(section_current)
|
||||
println(site.pages.last())
|
||||
$dbg;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,36 @@
|
||||
# Site Module
|
||||
|
||||
This module has the structure of a website, which menus to use, which pages, etc.
|
||||
|
||||
example see https://git.ourworld.tf/tfgrid/docs_tfgrid4/src/branch/main/ebooks/tech
|
||||
|
||||
## example how to get started
|
||||
|
||||
```v
|
||||
#!/usr/bin/env -S v -n -w -gc none -cg -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import os
|
||||
import incubaid.herolib.develop.gittools
|
||||
import incubaid.herolib.web.site
|
||||
import incubaid.herolib.core.playcmds
|
||||
|
||||
url := "https://git.ourworld.tf/tfgrid/docs_tfgrid4/src/branch/main/ebooks/tech"
|
||||
|
||||
mysitepath := gittools.path(
|
||||
// git_pull: true
|
||||
// git_reset: true
|
||||
git_url: url
|
||||
git_root: '/tmp/code'
|
||||
)!
|
||||
|
||||
playcmds.run(heroscript_path:mysitepath.path)!
|
||||
|
||||
mut mysite:=site.get(name:"tfgrid_tech")!
|
||||
println(mysite)
|
||||
|
||||
|
||||
```
|
||||
|
||||
## config heroscript
|
||||
|
||||
```yaml
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
module site
|
||||
|
||||
import os
|
||||
|
||||
fn test_play_collections() ! {
|
||||
mypath := '${os.dir(@FILE)}/example'
|
||||
|
||||
mut sc := new(mypath)!
|
||||
|
||||
// Add assertions here based on the expected site config structure
|
||||
assert sc.name == 'depin'
|
||||
assert sc.description == 'ThreeFold is laying the foundation for a geo aware Web 4, the next generation of the Internet.'
|
||||
assert sc.tagline == 'Geo Aware Internet Platform'
|
||||
assert sc.favicon == 'img/favicon.png'
|
||||
assert sc.image == 'img/tf_graph.png'
|
||||
assert sc.copyright == 'ThreeFold'
|
||||
|
||||
// Assertions for menu
|
||||
assert sc.menu.title == 'ThreeFold DePIN Tech'
|
||||
assert sc.menu.items.len == 3 // Based on the three !!site.menu_item entries
|
||||
assert sc.menu.items[0].label == 'ThreeFold.io'
|
||||
assert sc.menu.items[0].href == 'https://threefold.io'
|
||||
assert sc.menu.items[0].position == 'right'
|
||||
assert sc.menu.items[1].label == 'Mycelium Network'
|
||||
assert sc.menu.items[1].href == 'https://mycelium.threefold.io/'
|
||||
assert sc.menu.items[1].position == 'right'
|
||||
assert sc.menu.items[2].label == 'AI Box'
|
||||
assert sc.menu.items[2].href == 'https://aibox.threefold.io/'
|
||||
assert sc.menu.items[2].position == 'right'
|
||||
|
||||
// Assertions for footer
|
||||
assert sc.footer.style == 'dark'
|
||||
assert sc.footer.links.len == 3 // Based on the three unique titles in !!site.footer_item
|
||||
assert sc.footer.links[0].title == 'Docs'
|
||||
assert sc.footer.links[0].items.len == 4
|
||||
assert sc.footer.links[1].title == 'Features'
|
||||
assert sc.footer.links[1].items.len == 4
|
||||
assert sc.footer.links[2].title == 'Web'
|
||||
assert sc.footer.links[2].items.len == 5
|
||||
|
||||
// Assertions for collections
|
||||
assert sc.import_collections.len == 1 // Based on the !!site.collections entry
|
||||
assert sc.import_collections[0].url == 'https://github.com/example/external-docs'
|
||||
assert sc.import_collections[0].replace.len == 2
|
||||
assert sc.import_collections[0].replace['PROJECT_NAME'] == 'My Project'
|
||||
assert sc.import_collections[0].replace['VERSION'] == '1.0.0'
|
||||
assert sc.import_collections[0].visible == false // Default value
|
||||
|
||||
// Assertions for pages
|
||||
assert sc.pages.len == 4 // Based on the four !!site.page entries in site.heroscript
|
||||
|
||||
// Assertions for the first page (intro)
|
||||
assert sc.pages[0].name == 'intro'
|
||||
assert sc.pages[0].description == 'ThreeFold is laying the foundation for a geo aware Web 4, the next generation of the Internet.'
|
||||
assert sc.pages[0].title == '' // No title specified in site.heroscript
|
||||
assert sc.pages[0].draft == false // Default value
|
||||
assert sc.pages[0].folder == '' // Default value
|
||||
assert sc.pages[0].prio == 0 // Default value
|
||||
assert sc.pages[0].src == '' // No src specified
|
||||
assert sc.pages[0].content == '' // No content specified
|
||||
|
||||
// Assertions for the second page (mycelium)
|
||||
assert sc.pages[1].name == 'mycelium'
|
||||
assert sc.pages[1].description == '...'
|
||||
assert sc.pages[1].title == 'Mycelium as Title'
|
||||
assert sc.pages[1].draft == true
|
||||
assert sc.pages[1].folder == '/specs/components'
|
||||
assert sc.pages[1].prio == 4
|
||||
assert sc.pages[1].src == '' // No src specified
|
||||
assert sc.pages[1].content == 'the page content itself, only for small pages'
|
||||
|
||||
// Assertions for the third page (fungistor with .md)
|
||||
assert sc.pages[2].name == 'fungistor'
|
||||
assert sc.pages[2].description == '....'
|
||||
assert sc.pages[2].title == 'fungistor as Title'
|
||||
assert sc.pages[2].draft == false // Default value
|
||||
assert sc.pages[2].folder == '/specs/components'
|
||||
assert sc.pages[2].prio == 1
|
||||
assert sc.pages[2].src == 'mycollection:mycelium.md'
|
||||
assert sc.pages[2].content == '' // No content specified
|
||||
|
||||
// Assertions for the fourth page (fungistor without .md)
|
||||
assert sc.pages[3].name == 'fungistor'
|
||||
assert sc.pages[3].description == '...'
|
||||
assert sc.pages[3].title == 'fungistor as Title'
|
||||
assert sc.pages[3].draft == false // Default value
|
||||
assert sc.pages[3].folder == '/specs/components'
|
||||
assert sc.pages[3].prio == 1
|
||||
assert sc.pages[3].src == 'mycollection:mycelium'
|
||||
assert sc.pages[3].content == '' // No content specified
|
||||
}
|
||||
Reference in New Issue
Block a user