forked from xianyu110/awesome-openclaw-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmd2docx-single.sh
More file actions
executable file
·76 lines (65 loc) · 1.83 KB
/
Copy pathmd2docx-single.sh
File metadata and controls
executable file
·76 lines (65 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env bash
# Convert all markdown files into a single DOCX document
set -euo pipefail
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
# Directories
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
DOCS_DIR="$PROJECT_ROOT/docs"
OUTPUT_DIR="$PROJECT_ROOT/output"
OUTPUT_FILE="$OUTPUT_DIR/awesome-openclaw-tutorial.docx"
# Check pandoc
if ! command -v pandoc &> /dev/null; then
echo -e "${RED}Error: pandoc is not installed${NC}"
echo "Install it with: brew install pandoc"
exit 1
fi
# Create output directory
mkdir -p "$OUTPUT_DIR"
echo -e "${GREEN}Creating single DOCX document (all chapters)...${NC}"
echo ""
# Create temporary file list
TEMP_LIST=$(mktemp)
# Collect only numbered chapter files (01-*.md, 02-*.md, etc.)
# Exclude CHAPTER-*, SPLIT-*, PLAN-*, PROGRESS-*, DIRECTORY-* files
find "$DOCS_DIR" -type f -name "[0-9][0-9]-*.md" ! -path "*/images/*" | \
grep -v "CHAPTER-" | \
grep -v "SPLIT-" | \
grep -v "PLAN-" | \
grep -v "PROGRESS-" | \
grep -v "DIRECTORY-" | \
sort > "$TEMP_LIST"
# Show files to be merged
echo -e "${YELLOW}Files to merge:${NC}"
cat "$TEMP_LIST" | while read -r file; do
echo " - ${file#$DOCS_DIR/}"
done
echo ""
# Convert to single DOCX
echo -e "${YELLOW}Converting to DOCX...${NC}"
if pandoc $(cat "$TEMP_LIST") \
--from markdown \
--to docx \
--output "$OUTPUT_FILE" \
--standalone \
--toc \
--toc-depth=3 \
--highlight-style=tango \
--metadata title="Awesome OpenClaw Tutorial" \
2>/dev/null; then
echo -e "${GREEN}✓ Success!${NC}"
echo "Output: $OUTPUT_FILE"
echo ""
echo "To open the document:"
echo " open '$OUTPUT_FILE'"
else
echo -e "${RED}✗ Conversion failed${NC}"
rm -f "$TEMP_LIST"
exit 1
fi
# Cleanup
rm -f "$TEMP_LIST"