#!/usr/bin/env bash # Example workflow script: Convert multiple markdown files to PDF # This script demonstrates a typical document generation workflow set -e # Exit on any error echo "Starting document conversion workflow..." # Define input and output directories INPUT_DIR="/data" OUTPUT_DIR="/home/tsysdevstack/TSYSDevStack/Toolbox/docs/output" WORKFLOW_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" echo "Input directory: $INPUT_DIR" echo "Output directory: $OUTPUT_DIR" # Function to convert a markdown file to PDF convert_to_pdf() { local input_file="$1" local output_file="$2" echo "Converting $input_file to $output_file" pandoc "$input_file" \ -o "$output_file" \ --pdf-engine=xelatex \ --variable=geometry:a4paper \ --variable=margin=1in \ --highlight-style=tango } # Function to convert a markdown file to DOCX convert_to_docx() { local input_file="$1" local output_file="$2" echo "Converting $input_file to $output_file" pandoc "$input_file" -o "$output_file" } # Function to process mdBook build_mdbook() { local book_dir="$1" local output_dir="$2" echo "Building mdBook from $book_dir" mdbook build "$book_dir" -d "$output_dir" } # Function to process Typst document compile_typst() { local input_file="$1" local output_file="$2" echo "Compiling Typst document $input_file to $output_file" typst compile "$input_file" "$output_file" } # Convert all markdown files in the input directory for md_file in "$INPUT_DIR"/*.md; do if [ -f "$md_file" ]; then filename=$(basename "$md_file" .md) echo "Processing markdown file: $filename" # Convert to PDF convert_to_pdf "$md_file" "$OUTPUT_DIR/${filename}.pdf" # Convert to DOCX convert_to_docx "$md_file" "$OUTPUT_DIR/${filename}.docx" echo "Completed conversion of $filename" fi done # Process any mdBook directories for book_dir in "$INPUT_DIR"/book_*; do if [ -d "$book_dir" ] && [ -f "$book_dir/book.toml" ]; then echo "Found mdBook project: $book_dir" build_mdbook "$book_dir" "$OUTPUT_DIR" fi done # Process any Typst documents for typ_file in "$INPUT_DIR"/*.typ; do if [ -f "$typ_file" ]; then filename=$(basename "$typ_file" .typ) echo "Processing Typst file: $filename" compile_typst "$typ_file" "$OUTPUT_DIR/${filename}.pdf" fi done # Generate a summary report echo "Conversion workflow completed!" echo "Generated documents are available in: $OUTPUT_DIR" # Count generated files pdf_count=$(find "$OUTPUT_DIR" -name "*.pdf" | wc -l) docx_count=$(find "$OUTPUT_DIR" -name "*.docx" | wc -l) echo "Total PDFs generated: $pdf_count" echo "Total DOCX files generated: $docx_count" echo "Workflow completed successfully!"