...
This commit is contained in:
@@ -40,11 +40,9 @@ pub fn (mut c AtlasClient) get_page_path(collection_name string, page_name strin
|
||||
|
||||
// get_file_path returns the path for a file in a collection
|
||||
// Files are stored in {export_dir}/content/{collection}/{filename}
|
||||
pub fn (mut c AtlasClient) get_file_path(collection_name string, file_name string) !string {
|
||||
// Apply name normalization
|
||||
fixed_collection_name := texttools.name_fix(collection_name)
|
||||
// Files keep their original names with extensions
|
||||
fixed_file_name := texttools.name_fix_keepext(os.file_name(file_name))
|
||||
pub fn (mut c AtlasClient) get_file_path(collection_name_ string, file_name_ string) !string {
|
||||
collection_name := texttools.name_fix_no_ext(collection_name_)
|
||||
file_name := texttools.name_fix_keepext(file_name_)
|
||||
|
||||
// Check if export directory exists
|
||||
if !os.exists(c.export_dir) {
|
||||
@@ -52,12 +50,11 @@ pub fn (mut c AtlasClient) get_file_path(collection_name string, file_name strin
|
||||
}
|
||||
|
||||
// Construct the file path
|
||||
file_path := os.join_path(c.export_dir, 'content', fixed_collection_name, 'files',
|
||||
fixed_file_name)
|
||||
file_path := os.join_path(c.export_dir, 'content', collection_name, 'files', file_name)
|
||||
|
||||
// Check if the file exists
|
||||
if !os.exists(file_path) {
|
||||
return error('file_not_found: File "${file_name}" not found in collection "${collection_name}"')
|
||||
return error('file_not_found:"${file_path}" File "${file_name}" not found in collection "${collection_name}"')
|
||||
}
|
||||
|
||||
return file_path
|
||||
@@ -65,11 +62,11 @@ pub fn (mut c AtlasClient) get_file_path(collection_name string, file_name strin
|
||||
|
||||
// get_image_path returns the path for an image in a collection
|
||||
// Images are stored in {export_dir}/content/{collection}/{imagename}
|
||||
pub fn (mut c AtlasClient) get_image_path(collection_name string, image_name string) !string {
|
||||
pub fn (mut c AtlasClient) get_image_path(collection_name_ string, image_name_ string) !string {
|
||||
// Apply name normalization
|
||||
fixed_collection_name := texttools.name_fix_no_ext(collection_name)
|
||||
collection_name := texttools.name_fix_no_ext(collection_name_)
|
||||
// Images keep their original names with extensions
|
||||
fixed_image_name := texttools.name_fix_keepext(os.file_name(image_name))
|
||||
image_name := texttools.name_fix_keepext(image_name_)
|
||||
|
||||
// Check if export directory exists
|
||||
if !os.exists(c.export_dir) {
|
||||
@@ -77,12 +74,11 @@ pub fn (mut c AtlasClient) get_image_path(collection_name string, image_name str
|
||||
}
|
||||
|
||||
// Construct the image path
|
||||
image_path := os.join_path(c.export_dir, 'content', fixed_collection_name, 'img',
|
||||
fixed_image_name)
|
||||
image_path := os.join_path(c.export_dir, 'content', collection_name, 'img', image_name)
|
||||
|
||||
// Check if the image exists
|
||||
if !os.exists(image_path) {
|
||||
return error('image_not_found: Image "${image_name}" not found in collection "${collection_name}"')
|
||||
return error('image_not_found":"${image_path}" Image "${image_name}" not found in collection "${collection_name}"')
|
||||
}
|
||||
|
||||
return image_path
|
||||
@@ -289,12 +285,14 @@ pub fn (mut c AtlasClient) copy_images(collection_name string, page_name string,
|
||||
if link.file_type != .image {
|
||||
continue
|
||||
}
|
||||
|
||||
if link.status == .external {
|
||||
continue
|
||||
}
|
||||
// Get image path and copy
|
||||
img_path := c.get_image_path(link.target_collection_name, link.target_item_name)!
|
||||
mut src := pathlib.get_file(path: img_path)!
|
||||
src.copy(dest: '${img_dest.path}/${src.name_fix_keepext()}')!
|
||||
console.print_debug('Copied image: ${src.path} to ${img_dest.path}/${src.name_fix_keepext()}')
|
||||
// console.print_debug('Copied image: ${src.path} to ${img_dest.path}/${src.name_fix_keepext()}')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,8 +26,8 @@ pub mut:
|
||||
|
||||
pub struct FileMetadata {
|
||||
pub mut:
|
||||
name string // name with extension
|
||||
path string // path in the collection
|
||||
name string // name WITH extension (e.g., "image.png", "data.csv")
|
||||
path string // relative path in export (e.g., "img/image.png" or "files/data.csv")
|
||||
}
|
||||
|
||||
pub struct LinkMetadata {
|
||||
@@ -38,10 +38,19 @@ pub mut:
|
||||
line int
|
||||
target_collection_name string
|
||||
target_item_name string
|
||||
status string
|
||||
status LinkStatus
|
||||
file_type LinkFileType
|
||||
}
|
||||
|
||||
pub enum LinkStatus {
|
||||
init
|
||||
external
|
||||
found
|
||||
not_found
|
||||
anchor
|
||||
error
|
||||
}
|
||||
|
||||
pub enum LinkFileType {
|
||||
page // Default: link to another page
|
||||
file // Link to a non-image file
|
||||
|
||||
@@ -80,9 +80,8 @@ fn (mut c Collection) add_file(mut p pathlib.Path) ! {
|
||||
relativepath := file_abs_path.path_relative(col_path.absolute())!
|
||||
|
||||
mut file_new := File{
|
||||
name: name // name without extension
|
||||
ext: p.extension_lower()
|
||||
path: relativepath // relative path of file in the collection
|
||||
name: name
|
||||
path: relativepath // relative path of file in the collection, includes the name
|
||||
collection: &c
|
||||
}
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ pub fn (mut c Collection) export(args CollectionExportArgs) ! {
|
||||
if (link.file_type == .file || link.file_type == .image) && !is_local {
|
||||
mut target_file := link.target_file() or { continue }
|
||||
// Use file name as key to avoid duplicates
|
||||
file_key := target_file.file_name()
|
||||
file_key := target_file.name
|
||||
if file_key !in cross_collection_files {
|
||||
cross_collection_files[file_key] = target_file
|
||||
}
|
||||
@@ -131,7 +131,7 @@ pub fn (mut c Collection) export(args CollectionExportArgs) ! {
|
||||
create: true
|
||||
)!
|
||||
|
||||
mut dest_path := '${subdir_path.path}/${file.file_name()}'
|
||||
mut dest_path := '${subdir_path.path}/${file.name}'
|
||||
mut dest_file := pathlib.get_file(path: dest_path, create: true)!
|
||||
src_file.copy(dest: dest_file.path)!
|
||||
}
|
||||
@@ -163,7 +163,7 @@ pub fn (mut c Collection) export(args CollectionExportArgs) ! {
|
||||
create: true
|
||||
)!
|
||||
|
||||
mut dest_path := '${subdir_path.path}/${ref_file.file_name()}'
|
||||
mut dest_path := '${subdir_path.path}/${ref_file.name}'
|
||||
mut dest_file := pathlib.get_file(path: dest_path, create: true)!
|
||||
src_file.copy(dest: dest_file.path)!
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
module atlas
|
||||
|
||||
import incubaid.herolib.core.pathlib
|
||||
import os
|
||||
|
||||
pub enum FileType {
|
||||
file
|
||||
@@ -26,5 +27,5 @@ pub fn (f File) is_image() bool {
|
||||
}
|
||||
|
||||
pub fn (f File) ext() string {
|
||||
return pathlib.get_file_ext(f.name)
|
||||
return os.file_ext(f.name)
|
||||
}
|
||||
|
||||
@@ -268,11 +268,11 @@ fn (mut p Page) export_link_path(mut link Link) !string {
|
||||
match link.file_type {
|
||||
.image {
|
||||
mut tf := link.target_file()!
|
||||
return 'img/${tf.file_name()}'
|
||||
return 'img/${tf.name}'
|
||||
}
|
||||
.file {
|
||||
mut tf := link.target_file()!
|
||||
return 'files/${tf.file_name()}'
|
||||
return 'files/${tf.name}'
|
||||
}
|
||||
.page {
|
||||
mut tp := link.target_page()!
|
||||
|
||||
@@ -143,7 +143,7 @@ fn (mut generator SiteGenerator) page_generate(args_ Page) ! {
|
||||
pagefile.write(c)!
|
||||
|
||||
generator.client.copy_images(collection_name, page_name, pagefile.path_dir()) or {
|
||||
generator.error("Couldn't copy image ${pagefile.path} for page:'${page_name}' in collection:'${collection_name}'\nERROR:${err}")!
|
||||
generator.error("Couldn't copy images for page:'${page_name}' in collection:'${collection_name}'\nERROR:${err}")!
|
||||
return
|
||||
}
|
||||
generator.client.copy_files(collection_name, page_name, pagefile.path_dir()) or {
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
module docusaurus
|
||||
|
||||
import incubaid.herolib.develop.gittools
|
||||
import os
|
||||
import incubaid.herolib.core.pathlib
|
||||
import incubaid.herolib.ui.console
|
||||
import incubaid.herolib.core.texttools.regext
|
||||
|
||||
//import other parts of a docusaurus module into the one we build, this is to import e.g. static parts
|
||||
// import other parts of a docusaurus module into the one we build, this is to import e.g. static parts
|
||||
pub fn (mut docsite DocSite) import() ! {
|
||||
for importparams in docsite.website.siteconfig.imports {
|
||||
console.print_header('Importing: path:${importparams.path} or url:${importparams.url}')
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
module docusaurus
|
||||
|
||||
import incubaid.herolib.core.playbook { PlayBook }
|
||||
import incubaid.herolib.web.site
|
||||
import os
|
||||
|
||||
pub fn play(mut plbook PlayBook) ! {
|
||||
if !plbook.exists(filter: 'docusaurus.') {
|
||||
|
||||
Reference in New Issue
Block a user