-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert-docs.sh
executable file
·139 lines (122 loc) · 3.61 KB
/
convert-docs.sh
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/bash
# Directory containing markdown files
INPUT_DIR="docs/whitepaper"
OUTPUT_MD="whitepaper.md"
# Clear or create output file
> "$OUTPUT_MD"
# Add title and author information with adjusted spacing
cat << EOF > "$OUTPUT_MD"
---
title: "Mainstream Token Whitepaper"
author: "Mainstream Token Team"
date: "$(date +%B\ %Y)"
documentclass: report
geometry:
- margin=1in
linkcolor: blue
toc: true
numbersections: true
header-includes:
- \usepackage{titling}
- \usepackage{titlesec}
- \usepackage{tocloft}
- \pretitle{\begin{center}\LARGE\vspace*{-3em}}
- \posttitle{\end{center}\vspace{1em}}
- \preauthor{\begin{center}\large}
- \postauthor{\end{center}\vspace{1em}}
- \titleformat{\chapter}{\normalfont\LARGE\bfseries}{\thechapter.}{1em}{}
- \titlespacing*{\chapter}{0pt}{-20pt}{20pt}
- \setlength{\droptitle}{-2em}
- \setlength{\headheight}{12pt}
- \setlength{\headsep}{12pt}
- \renewcommand{\contentsname}{Table of Contents}
---
EOF
# Rest of the script remains the same
FILES=(
"executive_summary.md"
"introduction.md"
"ecosystem_overview.md"
"mainstreamtoken_details.md"
"technical_appendix.md"
"roadmap.md"
"community_engagement.md"
"team.md"
"aidamis.md"
"conclusion.md"
"legal_disclaimer.md"
"appendices.md"
)
# Function to remove frontmatter, import statements, and manual TOC
remove_frontmatter_and_toc() {
local file="$1"
local BEGIN_FRONT_MATTER=false
local SKIP_TOC=false
while IFS= read -r line; do
# Handle frontmatter
if [[ $line == "---" ]]; then
if [ "$BEGIN_FRONT_MATTER" = false ]; then
BEGIN_FRONT_MATTER=true
continue
else
BEGIN_FRONT_MATTER=false
continue
fi
fi
# Skip if in frontmatter or if line starts with import
if [ "$BEGIN_FRONT_MATTER" = true ] || [[ $line =~ ^import ]]; then
continue
fi
# Skip manual table of contents section
if [[ $line =~ ^#.*Table\ of\ Contents.* ]] || [[ $line =~ ^Download\ Whitepaper\ PDF ]]; then
SKIP_TOC=true
continue
fi
# Resume normal processing after TOC section
if [ "$SKIP_TOC" = true ] && [[ $line =~ ^# ]]; then
SKIP_TOC=false
fi
# Skip if we're in TOC section or if line is a bullet point in TOC
if [ "$SKIP_TOC" = true ] || [[ $line =~ ^[•\*]\ [A-Za-z] ]]; then
continue
fi
# Skip "Chapter X" lines
if [[ $line =~ ^Chapter\ [0-9]+ ]]; then
continue
fi
# Output the line if it hasn't been skipped
echo "$line"
done < "$file"
}
# Process each file
for file in "${FILES[@]}"; do
if [ -f "$INPUT_DIR/$file" ]; then
echo "Processing $file..."
echo "" >> "$OUTPUT_MD"
remove_frontmatter_and_toc "$INPUT_DIR/$file" >> "$OUTPUT_MD"
echo "" >> "$OUTPUT_MD"
echo "\\pagebreak" >> "$OUTPUT_MD"
echo "" >> "$OUTPUT_MD"
else
echo "Warning: $file not found in $INPUT_DIR"
fi
done
echo "Created $OUTPUT_MD"
echo "Converting to PDF..."
# Convert to PDF using pandoc with specific settings
pandoc "$OUTPUT_MD" \
--from markdown \
--to pdf \
--pdf-engine=xelatex \
--toc \
--number-sections \
--highlight-style=tango \
--variable urlcolor=blue \
--variable toccolor=black \
-o whitepaper.pdf
if [ $? -eq 0 ]; then
echo "Successfully created whitepaper.pdf"
mv whitepaper.pdf static/docs/
else
echo "Error during PDF conversion"
fi