This commit is contained in:
2025-05-19 07:37:10 +04:00
parent 238fabbcb2
commit 97dfcbeb51
7 changed files with 201 additions and 107 deletions

View File

@@ -1,96 +0,0 @@
module docusaurus
import os
import strings
// clean removes temporary files and build artifacts from the site directory
pub fn (mut site DocSite) clean(args ...ErrorArgs) ! {
toclean := '
/node_modules
babel.config.js
# Production
/build
# Generated files
.docusaurus
.cache-loader
# Misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*
bun.lockb
bun.lock
yarn.lock
build.sh
build_dev.sh
build-dev.sh
develop.sh
install.sh
package.json
package-lock.json
pnpm-lock.yaml
sidebars.ts
tsconfig.json
'
mut sb := strings.new_builder(200)
for line in toclean.split_into_lines() {
clean_line := line.trim_space()
if clean_line == '' || clean_line.starts_with('#') {
continue
}
// Remove leading slash if present to make path relative
path_to_clean := if clean_line.starts_with('/') {
clean_line[1..]
} else {
clean_line
}
full_path := os.join_path(site.path_src.path, path_to_clean)
// Handle glob patterns (files ending with *)
if path_to_clean.ends_with('*') {
base_pattern := path_to_clean#[..-1] // Remove the * at the end
base_dir := os.dir(full_path)
if os.exists(base_dir) {
files := os.ls(base_dir) or {
sb.writeln('Failed to list directory ${base_dir}: ${err}')
continue
}
for file in files {
if file.starts_with(base_pattern) {
file_path := os.join_path(base_dir, file)
os.rm(file_path) or { sb.writeln('Failed to remove ${file_path}: ${err}') }
}
}
}
continue
}
// Handle regular files and directories
if os.exists(full_path) {
if os.is_dir(full_path) {
os.rmdir_all(full_path) or {
sb.writeln('Failed to remove directory ${full_path}: ${err}')
}
} else {
os.rm(full_path) or { sb.writeln('Failed to remove file ${full_path}: ${err}') }
}
}
}
}

View File

@@ -1,7 +1,7 @@
module site
// Combined config structure
pub struct Config {
pub struct SiteConfig {
pub mut:
name string
title string = 'My Documentation Site'

View File

@@ -1,5 +1,5 @@
!!site.config
name:"ThreeFold DePIN Tech"
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"

46
lib/web/site/factory.v Normal file
View File

@@ -0,0 +1,46 @@
module site
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.core.texttools
__global (
doctrees shared map[string]&SiteConfig
)
@[params]
pub struct SiteConfigArgsGet {
pub mut:
name string = 'default'
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 != '' {
mut plbook := playbook.new(path: args.path)!
play(plbook:plbook)!
}
return &t
}
// 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') }
}
}
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
}
}

View File

@@ -1,6 +1,7 @@
module site
import freeflowuniverse.herolib.core.playbook { PlayBook }
import freeflowuniverse.herolib.core.texttools
import time
@@ -17,9 +18,11 @@ pub fn play(args_ PlayArgs) ! {
mut args := args_
mut plbook := args.plbook or { playbook.new(text: args.heroscript)! }
mut config := Config{}
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)!
@@ -27,12 +30,19 @@ pub fn play(args_ PlayArgs) ! {
}
fn play_config(mut plbook PlayBook, mut config Config) ! {
fn play_config(mut plbook PlayBook, mut config SiteConfig) ! {
config_actions := plbook.find(filter: 'site.config')!
if config_actions.len == 0 {
return error('no config found')
}
if config_actions.len > 1 {
return error('multiple config found, not ok')
}
for action in config_actions {
mut p := action.params
// Get optional name parameter or use base_url as fallback
config.name = p.get_default('name', 'site')!
config.name = p.get('name')!
config.name = texttools.name_fix(config.name)
config.title = p.get_default('title', 'Documentation Site')!
config.description = p.get_default('description', 'Comprehensive documentation built with Docusaurus.')!
config.tagline = p.get_default('tagline', 'Your awesome documentation')!
@@ -42,7 +52,7 @@ fn play_config(mut plbook PlayBook, mut config Config) ! {
}
}
fn play_collections(mut plbook PlayBook, mut config Config) ! {
fn play_collections(mut plbook PlayBook, mut config SiteConfig) ! {
import_actions := plbook.find(filter: 'site.collections')!
for action in import_actions {
mut p := action.params
@@ -67,7 +77,7 @@ fn play_collections(mut plbook PlayBook, mut config Config) ! {
}
}
fn play_menu(mut plbook PlayBook, mut config Config) ! {
fn play_menu(mut plbook PlayBook, mut config SiteConfig) ! {
menu_actions := plbook.find(filter: 'site.menu')!
for action in menu_actions {
mut p := action.params
@@ -86,7 +96,7 @@ fn play_menu(mut plbook PlayBook, mut config Config) ! {
}
}
fn play_footer(mut plbook PlayBook, mut config Config) ! {
fn play_footer(mut plbook PlayBook, mut config SiteConfig) ! {
footer_actions := plbook.find(filter: 'site.footer')!
for action in footer_actions {
mut p := action.params
@@ -120,7 +130,7 @@ fn play_footer(mut plbook PlayBook, mut config Config) ! {
}
}
fn play_pages(mut plbook PlayBook, mut config Config) ! {
fn play_pages(mut plbook PlayBook, mut config SiteConfig) ! {
page_actions := plbook.find(filter: 'site.page')!
for action in page_actions {
mut p := action.params

View File

@@ -0,0 +1,124 @@
# Site Module
The `lib/web/site/` directory contains the Vlang code responsible for generating and managing a documentation website all the config elements are specified in heroscript
## config heroscript
```yaml
!!site.config
name:"ThreeFold DePIN Tech"
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:"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:"Web"
label:"ThreeFold.io"
href:"https://threefold.io"
!!site.footer_item
title:"Web"
label:"Dashboard"
href:"https://dashboard.grid.tf"
!!site.collections
url:"https://github.com/example/external-docs"
replace:"PROJECT_NAME:My Project, VERSION:1.0.0"
```
## site structure
```yaml
!!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:"..."
```
## how to use easy
```v
import freeflowuniverse.herolib.web.site
siteconfig := site.new(path:"/tmp/mypath")!
```
## how to use with playbook
```v
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.web.site
// path string
// text string
// git_url string
// git_pull bool
// git_branch string
// git_reset bool
// session ?&base.Session is optional
mut plbook := playbook.new(path: "....")!
site.play(plbook:plbook)!
```

10
lib/web/site/site_test.v Normal file
View File

@@ -0,0 +1,10 @@
module site
import os
fn test_play_collections() ! {
mypath :='${os.dir(@FILE)}/example'
mut sc:=new(path:mypath)!
}