This commit is contained in:
2025-05-20 06:47:36 +04:00
parent 0789a38ea9
commit b8b339b85c
21 changed files with 379 additions and 790 deletions

View File

@@ -1,3 +0,0 @@
!!hero_code.play
name:'docusaurus'

View File

@@ -12,11 +12,5 @@
"title": "ThreeFold Technology Vision"
},
"buildDest":["root@info.ourworld.tf:/root/hero/www/info"],
"buildDestDev":["root@info.ourworld.tf:/root/hero/www/infodev"],
"import":[{
"url":"",
"dest":"",
"visible":true
}],
"copyright": "someone"
"buildDestDev":["root@info.ourworld.tf:/root/hero/www/infodev"]
}

View File

@@ -0,0 +1,95 @@
module docusaurus
import os
import strings
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}') }
}
}
}
}

134
lib/web/docusaurus/config.v Normal file
View File

@@ -0,0 +1,134 @@
module docusaurus
import freeflowuniverse.herolib.core.pathlib
import json
import os
// Footer config structures
pub struct FooterItem {
pub mut:
label string
to string
href string
}
pub struct FooterLink {
pub mut:
title string
items []FooterItem
}
pub struct Footer {
pub mut:
style string = 'dark'
links []FooterLink
}
// Main config structure
pub struct MainMetadata {
pub mut:
description string = 'Docusaurus'
image string = 'Docusaurus'
title string = 'Docusaurus'
}
pub struct Main {
pub mut:
name string
title string = 'Docusaurus'
tagline string
favicon string = 'img/favicon.png'
url string = 'http://localhost'
url_home string
base_url string = '/' @[json: 'baseUrl']
image string = 'img/tf_graph.png' @[required]
metadata MainMetadata
build_dest []string @[json: 'buildDest']
build_dest_dev []string @[json: 'buildDestDev']
}
// Navbar config structures
pub struct NavbarItem {
pub mut:
href string
label string
position string
}
pub struct Navbar {
pub mut:
title string
items []NavbarItem
}
// Combined config structure
pub struct Config {
pub mut:
footer Footer
main Main
navbar Navbar
}
// load_config loads all configuration from the specified directory
pub fn load_config(cfg_dir string) !Config {
// Ensure the config directory exists
if !os.exists(cfg_dir) {
return error('Config directory ${cfg_dir} does not exist')
}
// Load and parse footer config
footer_content := os.read_file(os.join_path(cfg_dir, 'footer.json'))!
footer := json.decode(Footer, footer_content)!
// Load and parse main config
main_config_path := os.join_path(cfg_dir, 'main.json')
main_content := os.read_file(main_config_path)!
main := json.decode(Main, main_content) or {
eprintln('main.json in ${cfg_dir} is not in the right format please fix.\nError: ${err}')
println('
## EXAMPLE OF A GOOD ONE:
- note the list for buildDest and buildDestDev
- note its the full path where the html is pushed too
{
"title": "ThreeFold Web4",
"tagline": "ThreeFold Web4",
"favicon": "img/favicon.png",
"url": "https://docs.threefold.io",
"url_home": "docs/introduction",
"baseUrl": "/",
"image": "img/tf_graph.png",
"metadata": {
"description": "ThreeFold is laying the foundation for a geo aware Web 4, the next generation of the Internet.",
"image": "https://threefold.info/kristof/img/tf_graph.png",
"title": "ThreeFold Docs"
},
"buildDest":["root@info.ourworld.tf:/root/hero/www/info/tfgrid4"],
"buildDestDev":["root@info.ourworld.tf:/root/hero/www/infodev/tfgrid4"]
}
')
exit(99)
}
// Load and parse navbar config
navbar_content := os.read_file(os.join_path(cfg_dir, 'navbar.json'))!
navbar := json.decode(Navbar, navbar_content)!
return Config{
footer: footer
main: main
navbar: navbar
}
}
pub fn (c Config) write(path string) ! {
mut footer_file := pathlib.get_file(path: '${path}/footer.json', create: true)!
footer_file.write(json.encode(c.footer))!
mut main_file := pathlib.get_file(path: '${path}/main.json', create: true)!
main_file.write(json.encode(c.main))!
mut navbar_file := pathlib.get_file(path: '${path}/navbar.json', create: true)!
navbar_file.write(json.encode(c.navbar))!
}

View File

@@ -4,10 +4,9 @@ import freeflowuniverse.herolib.osal.screen
import os
import freeflowuniverse.herolib.core.pathlib
import freeflowuniverse.herolib.core.texttools
// import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.data.markdownparser
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.develop.gittools
// import json
import json
import freeflowuniverse.herolib.osal
import freeflowuniverse.herolib.ui.console
@@ -19,12 +18,13 @@ pub mut:
path_src pathlib.Path
path_build pathlib.Path
// path_publish pathlib.Path
args DSiteGetArgs
errors []SiteError
config Config
args DSiteGetArgs
errors []SiteError
config Config
factory &DocusaurusFactory @[skip; str: skip] // Reference to the parent
}
pub fn (mut s DocSite) build() ! {
s.generate()!
osal.exec(
@@ -47,7 +47,7 @@ pub fn (mut s DocSite) build_dev_publish() ! {
)!
}
pub fn (mut s DocSite) build_publish() ! {
pub fn (mut s DocSite) build_publish()! {
s.generate()!
osal.exec(
cmd: '
@@ -58,14 +58,7 @@ pub fn (mut s DocSite) build_publish() ! {
)!
}
pub fn (mut s DocSite) open() ! {
// Print instructions for user
console.print_item('open browser: ${s.url}')
osal.exec(cmd: 'open https://localhost:3000')!
}
pub fn (mut s DocSite) dev() ! {
pub fn (mut s DocSite) dev()! {
s.clean()!
s.generate()!
@@ -83,9 +76,8 @@ pub fn (mut s DocSite) dev() ! {
)!
// 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}')!
scr.cmd_send('bun start')!
scr.cmd_send('bash develop.sh')!
// Print instructions for user
console.print_header(' Docusaurus Development Server')
@@ -106,14 +98,11 @@ pub fn (mut s DocSite) dev() ! {
// tf.wait()!
println('\n')
if s.args.open {
s.open()!
}
if s.args.watch_changes {
docs_path := '${s.path_src.path}/docs'
watch_docs(docs_path, s.path_src.path, s.path_build.path)!
}
}
@[params]
@@ -135,20 +124,21 @@ 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 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 {
for item in site.config.main.build_dest{
check_item(item)!
}
for item in site.config.main.build_dest_dev {
for item in site.config.main.build_dest_dev{
check_item(item)!
}
}
}
pub fn (mut site DocSite) generate() ! {
@@ -156,6 +146,13 @@ pub fn (mut site DocSite) generate() ! {
console.print_header(' site source on ${site.path_src.path}')
site.check()!
site.template_install()!
// osal.exec(
// cmd: '
// cd ${site.path_build.path}
// #Docusaurus build --dest-dir ${site.path_publish.path}
// '
// retry: 0
// )!
// Now copy all directories that exist in src to build
for item in ['src', 'static', 'cfg'] {
@@ -170,74 +167,31 @@ pub fn (mut site DocSite) generate() ! {
aa.copy(dest: '${site.path_build.path}/${item}', 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)!
}
}
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
}
fn (mut site DocSite) template_install() ! {
mut gs := gittools.new()!
site.factory.template_install(template_update: false, install: true, delete: false)!
site.factory.template_install(template_update:false, install:false, delete:false)!
cfg := site.config
mut myhome := '\$\{HOME\}' // for usage in bash
mut myhome:="\$\{HOME\}" //for usage in bash
profile_include := osal.profile_path_source()!.replace(os.home_dir(), myhome)
profile_include := osal.profile_path_source()!.replace(os.home_dir(),myhome)
mydir := site.path_build.path.replace(os.home_dir(), myhome)
mydir:=site.path_build.path.replace(os.home_dir(),myhome)
for item in ['src', 'static'] {
mut aa := site.path_src.dir_get(item) or { continue }
aa.copy(dest: '${site.factory.path_build.path}/${item}', delete: false)!
mut aa := site.path_src.dir_get(item) or {continue}
aa.copy(dest: '${site.factory.path_build.path}/${item}', delete:false)!
}
develop := $tmpl('templates/develop.sh')
build := $tmpl('templates/build.sh')
// build_dev_publish := $tmpl('templates/build_dev_publish.sh')
build_dev_publish := $tmpl('templates/build_dev_publish.sh')
build_publish := $tmpl('templates/build_publish.sh')
mut develop_ := site.path_build.file_get_new('develop.sh')!
@@ -252,17 +206,16 @@ fn (mut site DocSite) template_install() ! {
build_publish_.template_write(build_publish, true)!
build_publish_.chmod(0o700)!
// mut build_dev_publish_ := site.path_build.file_get_new('build_dev_publish.sh')!
// build_dev_publish_.template_write(build_dev_publish, true)!
// build_dev_publish_.chmod(0o700)!
mut build_dev_publish_ := site.path_build.file_get_new('build_dev_publish.sh')!
build_dev_publish_.template_write(build_dev_publish, true)!
build_dev_publish_.chmod(0o700)!
develop_templ := $tmpl('templates/develop_src.sh')
mut develop2_ := site.path_src.file_get_new('develop.sh')!
develop2_.template_write(develop_templ, true)!
develop2_.template_write(develop, true)!
develop2_.chmod(0o700)!
build_templ := $tmpl('templates/build_src.sh')
mut build2_ := site.path_src.file_get_new('build.sh')!
build2_.template_write(build_templ, true)!
build2_.template_write(build, true)!
build2_.chmod(0o700)!
}

View File

@@ -18,10 +18,9 @@ pub mut:
production bool
watch_changes bool = true
update bool
open bool
init bool // means create new one if needed
init bool //means create new one if needed
deploykey string
config ?Configuration
config ?Config
}
pub fn (mut f DocusaurusFactory) get(args_ DSiteGetArgs) !&DocSite {
@@ -41,60 +40,43 @@ pub fn (mut f DocusaurusFactory) get(args_ DSiteGetArgs) !&DocSite {
args.path = gs.get_path(url: args.url)!
}
if args.path.trim_space() == '' {
if args.path.trim_space() == "" {
args.path = os.getwd()
}
}
args.path = args.path.replace('~', os.home_dir())
mut r := gs.get_repo(
url: 'https://github.com/freeflowuniverse/docusaurus_template.git'
url: 'https://github.com/freeflowuniverse/docusaurus_template.git'
)!
mut template_path := r.patho()!
// First, check if the new site args provides a configuration
// First, check if the new site args provides a configuration that can be written instead of template cfg dir
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)!
panic("not implemented")
// cfg.write('${args.path}/cfg')!
} else {
// Then ensure cfg directory exists in src,
if !os.exists('${args.path}/cfg') {
if args.init {
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 {
}else{
return error("Can't find cfg dir in chosen docusaurus location: ${args.path}")
}
}
}
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)!
} else {
if args.init{
mut template_cfg := template_path.dir_get('docs')!
template_cfg.copy(dest: '${args.path}/docs')!
}else{
return error("Can't find docs dir in chosen docusaurus location: ${args.path}")
}
}
}
mut myconfig := load_configuration('${args.path}/cfg')!
mut myconfig := load_config('${args.path}/cfg')!
if myconfig.main.name.len == 0 {
myconfig.main.name = myconfig.main.base_url.trim_space().trim('/').trim_space()
@@ -115,8 +97,8 @@ This is a default page created by the Docusaurus site generator.
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)!
args: args
config: myconfig
args: args
config: myconfig
factory: &f
}

View File

@@ -5,8 +5,7 @@ import os
import freeflowuniverse.herolib.core.pathlib
// import freeflowuniverse.herolib.ui.console
// import freeflowuniverse.herolib.core.base
// import freeflowuniverse.herolib.develop.gittools
// import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.develop.gittools
@[heap]
pub struct DocusaurusFactory {
@@ -14,19 +13,16 @@ pub mut:
sites []&DocSite @[skip; str: skip]
path_build pathlib.Path
// path_publish pathlib.Path
args DocusaurusArgs
config Configuration // Stores configuration from HeroScript if provided
args DocusaurusArgs
}
@[params]
pub struct DocusaurusArgs {
pub mut:
// publish_path string
build_path string
production bool
update bool
heroscript string
heroscript_path string
build_path string
production bool
update bool
}
pub fn new(args_ DocusaurusArgs) !&DocusaurusFactory {
@@ -36,16 +32,14 @@ pub fn new(args_ DocusaurusArgs) !&DocusaurusFactory {
}
// if args.publish_path == ""{
// args.publish_path = "${os.home_dir()}/hero/var/docusaurus/publish"
// }
// Create the factory instance
// }
mut ds := &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)!
}
ds.template_install(install: true, template_update: args.update, delete: true)!
ds.template_install(install:true,template_update:args.update,delete:true)!
return ds
}
}

View File

@@ -1,229 +0,0 @@
module docusaurus
import freeflowuniverse.herolib.develop.gittools
import freeflowuniverse.herolib.osal
import freeflowuniverse.herolib.installers.web.bun
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)!
generate_configuration(site.path_build.path, site.config)!
generate_docusaurus_config_ts(site.path_build.path, site.config)!
// Now copy all directories that exist in src to build
for item in ['src', 'static', 'cfg'] {
if os.exists('${site.path_src.path}/${item}') {
mut aa := site.path_src.dir_get(item)!
aa.copy(dest: '${site.path_build.path}/${item}')!
}
}
for item in ['docs'] {
if os.exists('${site.path_src.path}/${item}') {
mut aa := site.path_src.dir_get(item)!
aa.copy(dest: '${site.path_build.path}/${item}', 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)!
// }
}
fn generate_configuration(path string, config Configuration) ! {
cfg_path := os.join_path(path, 'cfg')
mut main_file := pathlib.get_file(path: '${cfg_path}/main.json', create: true)!
main_file.write(json.encode(config.main))!
mut navbar_file := pathlib.get_file(path: '${cfg_path}/navbar.json', create: true)!
navbar_file.write(json.encode(config.navbar))!
mut footer_file := pathlib.get_file(path: '${cfg_path}/footer.json', create: true)!
footer_file.write(json.encode(config.footer))!
}
fn generate_docusaurus_config_ts(path string, config Configuration) ! {
mut config_file := pathlib.get_file(
path: os.join_path(path, 'docusaurus.config.ts')
create: true
)!
content := $tmpl('templates/docusaurus.config.ts')
config_file.write(content)!
}
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()!
// always start from template first for static assets and source files
for item in ['src', 'static'] {
mut aa := template_path.dir_get(item)!
aa.copy(dest: '${self.path_build.path}/${item}', delete: args.delete)!
}
// Generate config files dynamically from config
self.generate_package_json()!
self.generate_tsconfig_json()!
self.generate_sidebars_ts()!
self.generate_gitignore()!
if args.install {
// install bun
mut installer := bun.get()!
installer.install()!
osal.exec(
cmd: '
${osal.profile_path_source_and()!}
export PATH=/tmp/docusaurus_build/node_modules/.bin:${os.home_dir()}/.bun/bin/:??PATH
cd ${self.path_build.path}
bun install
'
)!
}
}
fn (mut self DocusaurusFactory) generate_gitignore() ! {
mut gitignore := pathlib.get_file(
path: os.join_path(self.path_build.path, '.gitignore')
create: true
)!
content := $tmpl('templates/.gitignore')
gitignore.write(content)!
}
// Generate package.json based on the configuration
fn (mut self DocusaurusFactory) generate_package_json() ! {
// Build package.json content as a structured JSON string
mut name := 'docusaurus-site'
if self.config.main.name != '' {
name = self.config.main.name
} else if self.config.navbar.title != '' {
name = self.config.navbar.title.to_lower().replace(' ', '-')
}
// Load package.json from template
// The 'name' variable is defined in this function's scope and will be used by $tmpl.
content := $tmpl('templates/package.json')
mut package_file := pathlib.get_file(
path: os.join_path(self.path_build.path, 'package.json')
create: true
)!
package_file.write(content)!
}
// Generate tsconfig.json based on the configuration
fn (mut self DocusaurusFactory) generate_tsconfig_json() ! {
// Load tsconfig.json from template
content := $tmpl('templates/tsconfig.json')
mut tsconfig_file := pathlib.get_file(
path: os.join_path(self.path_build.path, 'tsconfig.json')
create: true
)!
tsconfig_file.write(content)!
}
// Generate sidebars.ts based on the configuration
fn (mut self DocusaurusFactory) generate_sidebars_ts() ! {
// Load sidebars.ts from template
content := $tmpl('templates/sidebars.ts')
mut sidebars_file := pathlib.get_file(
path: os.join_path(self.path_build.path, 'sidebars.ts')
create: true
)!
sidebars_file.write(content)!
}
// // Generate docusaurus.config.ts based on the configuration
// fn (mut self DocusaurusFactory) generate_docusaurus_config_ts() ! {
// // Use config values with fallbacks
// title := if self.config.main.title != '' { self.config.main.title } else { 'Docusaurus Site' }
// // Format navbar items from config
// mut navbar_items_list_temp := []string{}
// for item in self.config.navbar.items {
// navbar_items_list_temp << "{
// label: '${item.label}',
// href: '${item.href}',
// position: '${item.position}'
// }"
// }
// // Generate footer links if available
// mut footer_links_list_temp := []string{}
// for link in self.config.footer.links {
// mut items_temp := []string{}
// for item in link.items {
// mut item_str := '{'
// if item.label != '' {
// item_str += "label: '${item.label}', "
// }
// if item.href != '' {
// item_str += "href: '${item.href}'"
// } else if item.to != '' {
// item_str += "to: '${item.to}'"
// } else {
// item_str += "to: '/docs'" // Default link
// }
// item_str += '}'
// items_temp << item_str
// }
// footer_links_list_temp << "{
// title: '${link.title}',
// items: [
// ${items_temp.join(',\n ')}
// ]
// }"
// }
// // Year for copyright
// year := time.now().year.str()
// // Copyright string (variable `copyright` must be in scope for the template)
// // `title` is defined at line 181, `year` is defined above.
// copyright := if self.config.main.copyright != '' {
// self.config.main.copyright
// } else {
// 'Copyright © ${year} ${title}'
// }
// // Load docusaurus.config.ts from template
// // All required variables (title, tagline, favicon, url, base_url,
// // projectName, navbarTitle, navbarItems, footerLinks, copyright)
// // are in scope for $tmpl.
// content := $tmpl('templates/docusaurus.config.ts')
// mut config_file := pathlib.get_file(
// path: os.join_path(self.path_build.path, 'docusaurus.config.ts')
// create: true
// )!
// config_file.write(content)!
// }

View File

@@ -1,101 +0,0 @@
module docusaurus
import os
import json
import freeflowuniverse.herolib.core.pathlib
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
}
pub fn load_configuration(cfg_path string) !Configuration {
mut main_json := pathlib.get_file(path: os.join_path(cfg_path, 'main.json'))!
mut navbar_json := pathlib.get_file(path: os.join_path(cfg_path, 'navbar.json'))!
mut footer_json := pathlib.get_file(path: os.join_path(cfg_path, 'footer.json'))!
mut cfg := Configuration{
main: json.decode(Main, main_json.read()!)!,
navbar: json.decode(Navbar, navbar_json.read()!)!,
footer: json.decode(Footer, footer_json.read()!)!
}
return cfg
}
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 },
}
}
}

View File

@@ -1,35 +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
// }

View File

@@ -0,0 +1,58 @@
module docusaurus
import freeflowuniverse.herolib.develop.gittools
import freeflowuniverse.herolib.osal
import freeflowuniverse.herolib.installers.web.bun
import os
@[params]
struct TemplateInstallArgs{
template_update bool = true
install bool
delete bool = true
}
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()!
for item in ['package.json', 'sidebars.ts', 'tsconfig.json'] {
mut aa := template_path.file_get(item)!
aa.copy(dest: '${self.path_build.path}/${item}')!
}
// always start from template first
for item in ['src', 'static'] {
mut aa := template_path.dir_get(item)!
aa.copy(dest: '${self.path_build.path}/${item}', delete: args.delete)!
}
for item in ['package.json', 'sidebars.ts', 'tsconfig.json', 'docusaurus.config.ts'] {
src_path := os.join_path(template_path.path, item)
dest_path := os.join_path(self.path_build.path, item)
os.cp(src_path, dest_path) or {
return error('Failed to copy ${item} to build path: ${err}')
}
}
if args.install{
// install bun
mut installer := bun.get()!
installer.install()!
osal.exec(
cmd: '
${osal.profile_path_source_and()!}
export PATH=/tmp/docusaurus_build/node_modules/.bin:${os.home_dir()}/.bun/bin/:??PATH
cd ${self.path_build.path}
bun install
'
)!
}
}

View File

@@ -1,21 +0,0 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
node_modules
.pnp
.pnp.js
# build output
build
.docusaurus
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*

View File

@@ -0,0 +1,23 @@
#!/bin/bash
set -e
script_dir="???cd "???dirname "??{BASH_SOURCE[0]}")" && pwd)"
cd "??{script_dir}"
echo "Docs directory: ??script_dir"
cd "${mydir}"
export PATH=/tmp/docusaurus_build/node_modules/.bin:??{HOME}/.bun/bin/:??PATH
rm -rf ${site.path_build.path}/build/
${profile_include}
bun docusaurus build
@for dest in cfg.main.build_dest_dev
rsync -rv --delete ${site.path_build.path}/build/ ${dest.trim_right("/")}/
@end

View File

@@ -1,6 +0,0 @@
#!/bin/bash -e
script_dir="???cd "???dirname "??{BASH_SOURCE[0]}")" && pwd)"
cd "??{script_dir}"
hero docusaurus -bp

View File

@@ -1,6 +0,0 @@
#!/bin/bash -e
script_dir="???cd "???dirname "??{BASH_SOURCE[0]}")" && pwd)"
cd "??{script_dir}"
hero docusaurus -d

View File

@@ -1,94 +0,0 @@
import {themes as prismThemes} from 'prism-react-renderer';
import type {Configuration} from '@@docusaurus/types';
import type * as Preset from '@@docusaurus/preset-classic';
const config: Configuration = {
title: '@{config.main.title}',
tagline: '@{config.main.tagline}',
favicon: '@{config.main.favicon}',
// Set the production url of your site here
url: '@{config.main.url}',
// Set the /<baseUrl>/ pathname under which your site is served
// For GitHub pages deployment, it is often '/<projectName>/'
baseUrl: '@{config.main.base_url}',
// GitHub pages deployment config.
// If you aren't using GitHub pages, you don't need these.
organizationName: 'freeflowuniverse', // Usually your GitHub org/user name.
projectName: '@{config.main.name}', // Usually your repo name.
onBrokenLinks: 'warn',
onBrokenMarkdownLinks: 'warn',
// Enable for i18n
// i18n: {
// defaultLocale: 'en',
// locales: ['en'],
// },
presets: [
[
'classic',
{
docs: {
sidebarPath: './sidebars.ts',
},
theme: {
customCss: './src/css/custom.css',
},
} satisfies Preset.Options,
],
],
themeConfig: {
// Replace with your project's social card
image: 'img/docusaurus-social-card.jpg',
colorMode: {
defaultMode: 'dark',
},
navbar: {
title: '@{config.navbar.title}',
items: [
@for item in config.navbar.items
{
label: '@{item.label}',
href: '@{item.href}',
position: '@{item.position}'
},
@end
],
},
footer: {
style: '@{config.footer.style}',
links: [
@for link_group in config.footer.links
{
title: '@{link_group.title}',
items: [
@for item in link_group.items
{
label: '@{item.label}',
@if item.href != ''
href: '@{item.href}'
@else if item.to != ''
to: '@{item.to}'
@else
to: '/docs'
@end
},
@end
]
},
@end
],
copyright: '@{config.main.copyright}',
},
prism: {
theme: prismThemes.github,
darkTheme: prismThemes.dracula,
},
} satisfies Preset.ThemeConfig,
};
export default config;

View File

@@ -1,84 +0,0 @@
## Definition of the main config
!!docusaurus.config
title: 'Internet Geek'
tagline: 'Internet Geek'
favicon: 'img/favicon.png'
url: 'https://friends.threefold.info'
url_home: 'docs/'
base_url: '/testsite/'
image: 'img/tf_graph.png'
!!docusaurus.config_meta
description: 'ThreeFold is laying the foundation for a geo aware Web 4, the next generation of the Internet.'
image: 'https://threefold.info/kristof/img/tf_graph.png'
title: 'ThreeFold Technology Vision'
## Definition of the imports & build destinations
!!docusaurus.ssh_connection name:'main' host:'info.ourworld.tf' port:'21' login:'root' passwd:'' key_path:'' key:''
!!docusaurus.import_source
url:'https://git.ourworld.tf/ourworld_holding/info_docs_owh/src/branch/main/docs'
path:''
dest:'' //if empty is root of docs
replace:'NAME:MyName, URGENCY:red'
!!docusaurus.build_dest ssh_name:'main'
path:' /root/hero/www/info/testsite'
## Definition of the navbar (is the top of the page)
!!docusaurus.navbar title:'Kristof = Chief Executive Geek'
!!docusaurus.navbar_item
label: "ThreeFold Technology"
href: "https://threefold.info/tech"
position: "right" #left or right
!!docusaurus.navbar_item
label: "ThreeFold Website"
href: "https://threefold.io"
position: "right" #left or right
## Definition of the footer
!!docusaurus.footer style:dark
#FIRST PART OF FOOTER (IS VERTICAL PART)
!!docusaurus.footer_item
title: 'Docs'
label: 'Introduction'
to: '/docs'
!!docusaurus.footer_item
title: 'Docs'
label: 'TFGrid V4 Docs'
href: 'https://docs.threefold.io/'
#2ND PART OF FOOTER (IS VERTICAL PART)
!!docusaurus.footer_item
title: 'Community'
label: 'Telegram'
href: 'https://t.me/threefold'
!!docusaurus.footer_item
title: 'Community'
label: 'X'
href: 'https://x.com/threefold_io'
#3E PART OF FOOTER (IS VERTICAL PART)
!!docusaurus.footer_item
title: 'Links'
label: 'ThreeFold.io'
href: 'https://threefold.io'

View File

@@ -1,39 +0,0 @@
{
"name": "@{name}",
"version": "0.0.1",
"private": true,
"scripts": {
"docusaurus": "docusaurus",
"start": "docusaurus start",
"build": "docusaurus build",
"swizzle": "docusaurus swizzle",
"deploy": "docusaurus deploy",
"clear": "docusaurus clear",
"serve": "docusaurus serve",
"write-translations": "docusaurus write-translations",
"write-heading-ids": "docusaurus write-heading-ids",
"typecheck": "tsc"
},
"dependencies": {
"@@docusaurus/core": "^3.1.0",
"@@docusaurus/preset-classic": "^3.1.0",
"@@mdx-js/react": "^3.0.0",
"clsx": "^2.0.0",
"prism-react-renderer": "^2.3.0",
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"devDependencies": {
"@@docusaurus/module-type-aliases": "^3.1.0",
"@@docusaurus/tsconfig": "^3.1.0",
"@@docusaurus/types": "^3.1.0",
"typescript": "^5.2.2"
},
"browserslist": {
"production": [">0.5%", "not dead", "not op_mini all"],
"development": ["last 1 chrome version", "last 1 firefox version", "last 1 safari version"]
},
"engines": {
"node": ">=18.0"
}
}

View File

@@ -1,18 +0,0 @@
import type {SidebarsConfig} from '@@docusaurus/plugin-content-docs';
/**
* Creating a sidebar enables you to:
- create an ordered group of docs
- render a sidebar for each doc of that group
- provide next/previous navigation
The sidebars can be generated from the filesystem, or explicitly defined here.
Create as many sidebars as you want.
*/
const sidebars: SidebarsConfig = {
// By default, Docusaurus generates a sidebar from the docs folder structure
tutorialSidebar: [{type: 'autogenerated', dirName: '.'}],
};
export default sidebars;

View File

@@ -1,8 +0,0 @@
{
"extends": "@@docusaurus/tsconfig",
"compilerOptions": {
"baseUrl": ".",
"resolveJsonModule": true
},
"include": ["src/**/*", "docusaurus.config.ts"]
}