...
This commit is contained in:
@@ -5,7 +5,7 @@ import incubaid.herolib.core.redisclient
|
||||
// AtlasClient provides access to Atlas-exported documentation collections
|
||||
// It reads from both the exported directory structure and Redis metadata
|
||||
pub struct AtlasClient {
|
||||
AtlasError // Embedded error handler for generating standardized errors
|
||||
// AtlasError // Embedded error handler for generating standardized errors
|
||||
pub mut:
|
||||
redis &redisclient.Redis
|
||||
export_dir string // Path to the atlas export directory (contains content/ and meta/)
|
||||
|
||||
@@ -7,11 +7,10 @@ import json
|
||||
@[params]
|
||||
pub struct ExportArgs {
|
||||
pub mut:
|
||||
destination string @[required]
|
||||
destination_meta string // NEW: where to save collection metadata
|
||||
reset bool = true
|
||||
include bool = true
|
||||
redis bool = true
|
||||
destination string @[requireds]
|
||||
reset bool = true
|
||||
include bool = true
|
||||
redis bool = true
|
||||
}
|
||||
|
||||
// Export all collections
|
||||
@@ -122,16 +121,16 @@ pub fn (mut c Collection) export(args CollectionExportArgs) ! {
|
||||
// Copy all files/images from this collection to the export directory
|
||||
for _, mut file in c.files {
|
||||
mut src_file := file.path()!
|
||||
|
||||
|
||||
// Determine subdirectory based on file type
|
||||
mut subdir := if file.is_image() { 'img' } else { 'files' }
|
||||
|
||||
|
||||
// Ensure subdirectory exists
|
||||
mut subdir_path := pathlib.get_dir(
|
||||
path: '${col_dir.path}/${subdir}'
|
||||
path: '${col_dir.path}/${subdir}'
|
||||
create: true
|
||||
)!
|
||||
|
||||
|
||||
mut dest_path := '${subdir_path.path}/${file.file_name()}'
|
||||
mut dest_file := pathlib.get_file(path: dest_path, create: true)!
|
||||
src_file.copy(dest: dest_file.path)!
|
||||
@@ -154,16 +153,16 @@ pub fn (mut c Collection) export(args CollectionExportArgs) ! {
|
||||
// Third pass: copy cross-collection referenced files/images to make collection self-contained
|
||||
for _, mut ref_file in cross_collection_files {
|
||||
mut src_file := ref_file.path()!
|
||||
|
||||
|
||||
// Determine subdirectory based on file type
|
||||
mut subdir := if ref_file.is_image() { 'img' } else { 'files' }
|
||||
|
||||
|
||||
// Ensure subdirectory exists
|
||||
mut subdir_path := pathlib.get_dir(
|
||||
path: '${col_dir.path}/${subdir}'
|
||||
path: '${col_dir.path}/${subdir}'
|
||||
create: true
|
||||
)!
|
||||
|
||||
|
||||
mut dest_path := '${subdir_path.path}/${ref_file.file_name()}'
|
||||
mut dest_file := pathlib.get_file(path: dest_path, create: true)!
|
||||
src_file.copy(dest: dest_file.path)!
|
||||
|
||||
@@ -66,7 +66,7 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
for mut action in export_actions {
|
||||
mut p := action.params
|
||||
name = p.get_default('name', 'main')!
|
||||
destination := p.get('destination')!
|
||||
destination := p.get_default('destination', '/tmp/atlas_export')!
|
||||
reset := p.get_default_true('reset')
|
||||
include := p.get_default_true('include')
|
||||
redis := p.get_default_true('redis')
|
||||
|
||||
@@ -6,42 +6,6 @@ import incubaid.herolib.web.site { Page, Section, Site }
|
||||
import incubaid.herolib.data.markdown.tools as markdowntools
|
||||
import incubaid.herolib.ui.console
|
||||
|
||||
// THIS CODE GENERATES A DOCUSAURUS SITE FROM A DOCUMENT CLIENT AND SITE DEFINITION
|
||||
// Supports both atlas.client and doctreeclient through the unified IDocClient interface
|
||||
|
||||
// IDocClient defines the common interface that both atlas.client and doctreeclient implement
|
||||
// This allows the Docusaurus module to work with either client transparently
|
||||
//
|
||||
// Note: V interfaces require exact signature matching, so all methods use `mut` receivers
|
||||
// to match the implementation in both atlas.client and doctreeclient
|
||||
pub interface IDocClient {
|
||||
mut:
|
||||
// Path methods - get absolute paths to resources
|
||||
get_page_path(collection_name string, page_name string) !string
|
||||
get_file_path(collection_name string, file_name string) !string
|
||||
get_image_path(collection_name string, image_name string) !string
|
||||
|
||||
// Existence checks - verify if resources exist
|
||||
page_exists(collection_name string, page_name string) bool
|
||||
file_exists(collection_name string, file_name string) bool
|
||||
image_exists(collection_name string, image_name string) bool
|
||||
|
||||
// Content retrieval
|
||||
get_page_content(collection_name string, page_name string) !string
|
||||
|
||||
// Listing methods - enumerate resources
|
||||
list_collections() ![]string
|
||||
list_pages(collection_name string) ![]string
|
||||
list_files(collection_name string) ![]string
|
||||
list_images(collection_name string) ![]string
|
||||
list_pages_map() !map[string][]string
|
||||
list_markdown() !string
|
||||
|
||||
// Image operations
|
||||
get_page_paths(collection_name string, page_name string) !(string, []string)
|
||||
copy_images(collection_name string, page_name string, destination_path string) !
|
||||
}
|
||||
|
||||
struct SiteGenerator {
|
||||
mut:
|
||||
siteconfig_name string
|
||||
@@ -63,6 +27,8 @@ pub fn (mut docsite DocSite) generate_docs() ! {
|
||||
mut client_instance := atlas_client.new(export_dir: c.atlas_dir)!
|
||||
mut client := IDocClient(client_instance)
|
||||
|
||||
println(client_instance)
|
||||
$dbg;
|
||||
mut gen := SiteGenerator{
|
||||
path: pathlib.get_dir(path: docs_path, create: true)!
|
||||
client: client
|
||||
@@ -178,7 +144,7 @@ fn (mut generator SiteGenerator) page_generate(args_ Page) ! {
|
||||
|
||||
pagefile.write(c)!
|
||||
|
||||
generator.client.copy_images(collection_name, page_name, pagefile.path_dir().path) or {
|
||||
generator.client.copy_images(collection_name, page_name, pagefile.path_dir()) or {
|
||||
generator.error("Couldn't copy image ${pagefile} for '${page_name}' in collection '${collection_name}', try to find the image and fix the path is in ${args.path}.}\nError: ${err}")!
|
||||
return
|
||||
}
|
||||
|
||||
35
lib/web/docusaurus/interface_atlas.v
Normal file
35
lib/web/docusaurus/interface_atlas.v
Normal file
@@ -0,0 +1,35 @@
|
||||
module docusaurus
|
||||
|
||||
import incubaid.herolib.core.pathlib
|
||||
import incubaid.herolib.data.atlas.client as atlas_client
|
||||
import incubaid.herolib.web.site
|
||||
import incubaid.herolib.data.markdown.tools as markdowntools
|
||||
import incubaid.herolib.ui.console
|
||||
|
||||
pub interface IDocClient {
|
||||
mut:
|
||||
// Path methods - get absolute paths to resources
|
||||
get_page_path(collection_name string, page_name string) !string
|
||||
get_file_path(collection_name string, file_name string) !string
|
||||
get_image_path(collection_name string, image_name string) !string
|
||||
|
||||
// Existence checks - verify if resources exist
|
||||
page_exists(collection_name string, page_name string) bool
|
||||
file_exists(collection_name string, file_name string) bool
|
||||
image_exists(collection_name string, image_name string) bool
|
||||
|
||||
// Content retrieval
|
||||
get_page_content(collection_name string, page_name string) !string
|
||||
|
||||
// Listing methods - enumerate resources
|
||||
list_collections() ![]string
|
||||
list_pages(collection_name string) ![]string
|
||||
list_files(collection_name string) ![]string
|
||||
list_images(collection_name string) ![]string
|
||||
list_pages_map() !map[string][]string
|
||||
list_markdown() !string
|
||||
|
||||
// Image operations
|
||||
// get_page_paths(collection_name string, page_name string) !(string, []string)
|
||||
copy_images(collection_name string, page_name string, destination_path string) !
|
||||
}
|
||||
@@ -19,7 +19,7 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
reset: param_define.get_default_false('reset')
|
||||
template_update: param_define.get_default_false('template_update')
|
||||
install: param_define.get_default_false('install')
|
||||
atlas_dir: param_define.get_default('atlas_dir', '')!
|
||||
atlas_dir: param_define.get_default('atlas_dir', '/tmp/atlas_export')!
|
||||
use_atlas: param_define.get_default_false('use_atlas')
|
||||
)!
|
||||
|
||||
@@ -34,20 +34,6 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
|
||||
dsite.generate()!
|
||||
|
||||
mut actions_dev := plbook.find(filter: 'docusaurus.dev')!
|
||||
if actions_dev.len > 1 {
|
||||
return error('Multiple "docusaurus.dev" actions found. Only one is allowed.')
|
||||
}
|
||||
for mut action in actions_dev {
|
||||
mut p := action.params
|
||||
dsite.dev(
|
||||
host: p.get_default('host', 'localhost')!
|
||||
port: p.get_int_default('port', 3000)!
|
||||
open: p.get_default_false('open')
|
||||
)!
|
||||
action.done = true
|
||||
}
|
||||
|
||||
mut actions_build := plbook.find(filter: 'docusaurus.build')!
|
||||
if actions_build.len > 1 {
|
||||
return error('Multiple "docusaurus.build" actions found. Only one is allowed.')
|
||||
@@ -66,5 +52,19 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
action.done = true
|
||||
}
|
||||
|
||||
mut actions_dev := plbook.find(filter: 'docusaurus.dev')!
|
||||
if actions_dev.len > 1 {
|
||||
return error('Multiple "docusaurus.dev" actions found. Only one is allowed.')
|
||||
}
|
||||
for mut action in actions_dev {
|
||||
mut p := action.params
|
||||
dsite.dev(
|
||||
host: p.get_default('host', 'localhost')!
|
||||
port: p.get_int_default('port', 3000)!
|
||||
open: p.get_default_false('open')
|
||||
)!
|
||||
action.done = true
|
||||
}
|
||||
|
||||
plbook.ensure_processed(filter: 'docusaurus.')!
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user