163 lines
5.9 KiB
Text
163 lines
5.9 KiB
Text
|
|
#!/usr/bin/env nu
|
||
|
|
|
||
|
|
# Simple Content Manager
|
||
|
|
# Uses the enhanced Rust content_processor for all operations
|
||
|
|
|
||
|
|
# Show help information
|
||
|
|
def show_help [] {
|
||
|
|
print $"
|
||
|
|
(ansi blue)Simple Content Manager(ansi reset)
|
||
|
|
Convenient interface for content operations using the Rust content_processor
|
||
|
|
|
||
|
|
(ansi green)USAGE:(ansi reset)
|
||
|
|
./content-manager-simple.nu COMMAND [OPTIONS]
|
||
|
|
|
||
|
|
(ansi green)COMMANDS:(ansi reset)
|
||
|
|
build Build all content
|
||
|
|
build-type TYPE Build specific content type like blog or recipes
|
||
|
|
build-lang LANG Build specific language like en or es
|
||
|
|
build-category CATEGORY Build specific category
|
||
|
|
build-file FILE Build specific file with glob pattern support
|
||
|
|
watch Watch for changes and auto-rebuild
|
||
|
|
clean-build Clean output and rebuild all
|
||
|
|
help Show this help message
|
||
|
|
|
||
|
|
(ansi green)EXAMPLES:(ansi reset)
|
||
|
|
|
||
|
|
# Build all content
|
||
|
|
./content-manager-simple.nu build
|
||
|
|
|
||
|
|
# Build only blog content
|
||
|
|
./content-manager-simple.nu build-type blog
|
||
|
|
|
||
|
|
# Build only English content
|
||
|
|
./content-manager-simple.nu build-lang en
|
||
|
|
|
||
|
|
# Build specific category
|
||
|
|
./content-manager-simple.nu build-category rust
|
||
|
|
|
||
|
|
# Build specific file
|
||
|
|
./content-manager-simple.nu build-file \"blog/en/rust/rust-web-development-2024.md\"
|
||
|
|
|
||
|
|
# Watch for changes
|
||
|
|
./content-manager-simple.nu watch
|
||
|
|
|
||
|
|
# Clean and rebuild
|
||
|
|
./content-manager-simple.nu clean-build
|
||
|
|
|
||
|
|
(ansi green)CONTENT PROCESSOR OPTIONS:(ansi reset)
|
||
|
|
The underlying Rust content_processor supports these options:
|
||
|
|
--content-type TYPE Process specific content type
|
||
|
|
--language LANG Process specific language
|
||
|
|
--category CATEGORY Process specific category
|
||
|
|
--file FILE Process specific files with glob support
|
||
|
|
--watch Watch mode for hot reloading
|
||
|
|
|
||
|
|
(ansi yellow)NOTES:(ansi reset)
|
||
|
|
- All operations use the fast Rust content_processor
|
||
|
|
- Automatically copies generated content to server runtime directory
|
||
|
|
- Respects project configuration-driven architecture
|
||
|
|
- No hardcoded paths or content types
|
||
|
|
"
|
||
|
|
}
|
||
|
|
|
||
|
|
# Run content processor with given arguments
|
||
|
|
def run_processor [...args] {
|
||
|
|
mut cmd = ["cargo", "run", "--features=content-static", "--bin", "content_processor", "--"]
|
||
|
|
$cmd = ($cmd | append $args)
|
||
|
|
print $"(ansi blue)🔧 Running: ($cmd | str join ' ')(ansi reset)"
|
||
|
|
|
||
|
|
try {
|
||
|
|
run-external $cmd.0 ...$cmd.1
|
||
|
|
print $"(ansi green)✅ Content processing completed!(ansi reset)"
|
||
|
|
|
||
|
|
# Copy to server directory
|
||
|
|
let public_dir = "public/static-content"
|
||
|
|
let server_dir = "target/site/static-content"
|
||
|
|
|
||
|
|
print $"(ansi blue)📋 Copying to server directory...(ansi reset)"
|
||
|
|
mkdir $server_dir
|
||
|
|
cp -r ($public_dir | path join "*") $server_dir
|
||
|
|
print $"(ansi green)✅ Content copied to server directory(ansi reset)"
|
||
|
|
|
||
|
|
} catch { |err|
|
||
|
|
print $"(ansi red)❌ Content processing failed: ($err.msg)(ansi reset)"
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
# Clean output directory
|
||
|
|
def clean_output [] {
|
||
|
|
let output_dir = "public/static-content"
|
||
|
|
if ($output_dir | path exists) {
|
||
|
|
print $"(ansi yellow)🧹 Cleaning output directory: ($output_dir)(ansi reset)"
|
||
|
|
rm -rf $output_dir
|
||
|
|
}
|
||
|
|
mkdir $output_dir
|
||
|
|
}
|
||
|
|
|
||
|
|
def main [command?: string, ...args] {
|
||
|
|
if ($command | is-empty) or $command == "help" or $command == "--help" or $command == "-h" {
|
||
|
|
show_help
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
match $command {
|
||
|
|
"build" => {
|
||
|
|
print $"(ansi blue)🚀 Building all content...(ansi reset)"
|
||
|
|
run_processor
|
||
|
|
}
|
||
|
|
"build-type" => {
|
||
|
|
if ($args | length) == 0 {
|
||
|
|
print $"(ansi red)❌ build-type requires a content type argument(ansi reset)"
|
||
|
|
print $" Example: ./content-manager-simple.nu build-type blog"
|
||
|
|
return
|
||
|
|
}
|
||
|
|
let content_type = ($args | first)
|
||
|
|
print $"(ansi blue)🎯 Building ($content_type) content...(ansi reset)"
|
||
|
|
run_processor "--content-type" $content_type
|
||
|
|
}
|
||
|
|
"build-lang" => {
|
||
|
|
if ($args | length) == 0 {
|
||
|
|
print $"(ansi red)❌ build-lang requires a language argument(ansi reset)"
|
||
|
|
print $" Example: ./content-manager-simple.nu build-lang en"
|
||
|
|
return
|
||
|
|
}
|
||
|
|
let language = ($args | first)
|
||
|
|
print $"(ansi blue)🌍 Building ($language) content...(ansi reset)"
|
||
|
|
run_processor "--language" $language
|
||
|
|
}
|
||
|
|
"build-category" => {
|
||
|
|
if ($args | length) == 0 {
|
||
|
|
print $"(ansi red)❌ build-category requires a category argument(ansi reset)"
|
||
|
|
print $" Example: ./content-manager-simple.nu build-category rust"
|
||
|
|
return
|
||
|
|
}
|
||
|
|
let category = ($args | first)
|
||
|
|
print $"(ansi blue)🏷️ Building ($category) category...(ansi reset)"
|
||
|
|
run_processor "--category" $category
|
||
|
|
}
|
||
|
|
"build-file" => {
|
||
|
|
if ($args | length) == 0 {
|
||
|
|
print $"(ansi red)❌ build-file requires a file pattern argument(ansi reset)"
|
||
|
|
print $" Example: ./content-manager-simple.nu build-file \"blog/en/rust/*.md\""
|
||
|
|
return
|
||
|
|
}
|
||
|
|
let file_pattern = ($args | first)
|
||
|
|
print $"(ansi blue)📄 Building file pattern: ($file_pattern)(ansi reset)"
|
||
|
|
run_processor "--file" $file_pattern
|
||
|
|
}
|
||
|
|
"watch" => {
|
||
|
|
print $"(ansi blue)👀 Starting watch mode...(ansi reset)"
|
||
|
|
run_processor "--watch"
|
||
|
|
}
|
||
|
|
"clean-build" => {
|
||
|
|
print $"(ansi blue)🧹 Clean build - removing old content...(ansi reset)"
|
||
|
|
clean_output
|
||
|
|
run_processor
|
||
|
|
}
|
||
|
|
_ => {
|
||
|
|
print $"(ansi red)❌ Unknown command: ($command)(ansi reset)"
|
||
|
|
print $"(ansi yellow)Use 'help' to see available commands(ansi reset)"
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|