-
Notifications
You must be signed in to change notification settings - Fork 0
/
smoo.sh
executable file
·212 lines (166 loc) · 5.86 KB
/
smoo.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/bin/bash
OLDIFS="$IFS"
IFS=$'\n'
if [ "$LOCAL" = "true" ]; then
base_url="http://localhost:8000"
else
base_url="https://docs.mrjs.io"
fi
github_base='https://github.com/Volumetrics-io/documentation/edit/main/source'
site_name='MRjs'
templateDir='source'
templateHTML='source/_template.html'
outputDir='public'
assetDir='source/static'
pagesDir='source/pages'
ecsDir='source/ecs'
docsDir='source/docs'
attributesDir='source/attributes'
eventsDir='source/events'
jsAPIDir='source/js-api'
jsAPIExtrasDir='source/js-api-extras'
jsAPIUtilsDir='source/js-api-utils'
current_year=$(date +"%Y")
#run main action
mkdir -p "$outputDir"
rm -rf "${outputDir}"/*
echo -e "🧹 Cleaned up /$outputDir/ folder"
if [[ "$assetDir" ]]; then
rsync -a "$assetDir" "${outputDir}/"
echo "📦️ Copied /$assetDir/ assets folder"
fi
# Function to process files
extract_metadata() {
local directory=$1
# local files=($(ls -f "${directory}"/*.md))
local files=($(find "${directory}" -maxdepth 1 -name "*.md" -print | sort))
for file in "${files[@]}"
do
# Extract the file name
local base_file=$(basename -- "$file")
# Get the part before the .md extension
local title=${base_file%.*}
# Remove the leading numbers (used for sorting)
title=$(echo -e "$title" | sed 's/^[0-9]*//')
# Make the slug lowercase
local slug=$(echo -e "$title" | tr '[:upper:]' '[:lower:]')
# Replace spaces with "-" in the slug
slug=${slug// /-}
# Add the entry to the YAML doc
docsYAML+=" - title: \"$title\"\n"
docsYAML+=" slug: \"$slug\"\n"
echo -e "🔎 Extracted metadata for $title"
done
}
# Function to process markdown files and convert them to HTML
process_markdown() {
local source_dir=$1
local github_path_prefix=$2
local output_subdir=$3
# local files=($(ls -f "${source_dir}"/*.md))
local files=($(find "${source_dir}" -maxdepth 1 -name "*.md" -print | sort))
for file in "${files[@]}"
do
# --- handling the file for creation to the public folder --- #
# Extract the file name
local base_file=$(basename -- "$file")
# Get the part before the .md extension
local title=${base_file%.*}
# Remove the leading numbers (used for sorting)
title=$(echo -e "$title" | sed 's/^[0-9]*//')
# Make the slug lowercase
local slug=$(echo -e "$title" | tr '[:upper:]' '[:lower:]')
# Replace spaces with "-" in the slug
slug=${slug// /-}
# Set path variables and create the folder
local page_url="${base_url}/${output_subdir}/${slug}/"
local github_path_auto="${github_base}/${github_path_prefix}/${base_file}"
mkdir -p "${outputDir}/${output_subdir}/${slug}"
# Convert the markdown to HTML
pandoc "$file" \
--template "$templateHTML" \
--metadata current-year="$current_year" \
--metadata site-name="$site_name" \
--metadata page-url="$page_url" \
--metadata base-url="$base_url" \
--metadata github-path-auto="$github_path_auto" \
--metadata title="$title" \
--metadata slug="$slug" \
--metadata title-prefix="$site_name" \
--metadata-file="${outputDir}/docs.yaml" \
--lua-filter colgroups.lua \
--lua-filter anchorlinks.lua \
--highlight-style pygments \
--wrap=none \
-f commonmark_x \
-s -p \
-o "${outputDir}/${output_subdir}/${slug}/index.html"
echo -e "🌟 Generated page for $title"
done
}
# Initialize YAML header
docsYAML="---\n"
######################################
# Process "General" pages
docsYAML+="pages:\n"
extract_metadata "$pagesDir"
# Process "Entity Component System" pages
docsYAML+="ecs:\n"
extract_metadata "$ecsDir"
# Process "HTML tags" pages
docsYAML+="docs:\n"
extract_metadata "$docsDir"
# Process "MRjs Events" pages
docsYAML+="events:\n"
extract_metadata "$eventsDir"
# Process "Data attributes" pages
docsYAML+="attributes:\n"
extract_metadata "$attributesDir"
# Process "JavaScript API" pages
docsYAML+="js-api:\n"
extract_metadata "$jsAPIDir"
# Process "JavaScript API Extras" pages
docsYAML+="js-api-extras:\n"
extract_metadata "$jsAPIExtrasDir"
# Process "JavaScript API Utils" pages
docsYAML+="js-api-utils:\n"
extract_metadata "$jsAPIUtilsDir"
######################################
# Finalize and write to file
docsYAML+="---"
echo -e "$docsYAML" > "${outputDir}/docs.yaml"
# Process page files
process_markdown "$pagesDir" "pages" ""
# Process ecs files
process_markdown "$ecsDir" "ecs" "ecs"
# Process doc files
process_markdown "$docsDir" "docs" "doc"
# Process data events files
process_markdown "$eventsDir" "events" "events"
# Process data attributes files
process_markdown "$attributesDir" "attributes" "attributes"
# Process javascript API files
process_markdown "$jsAPIDir" "js-api" "js-api"
process_markdown "$jsAPIExtrasDir" "js-api-extras" "js-api-extras"
process_markdown "$jsAPIUtilsDir" "js-api-utils" "js-api-utils"
# --metadata base-url="$base_url" \
# --metadata github-path="https://github.com/Volumetrics-io/mrjs/edit/main/README.md" \
pandoc "${templateDir}/index.md" \
--template $templateHTML \
--metadata current-year="$current_year" \
--metadata site-name="$site_name" \
--metadata page-url="$base_url" \
--metadata base-url="$base_url" \
--metadata github-path-auto="https://github.com/Volumetrics-io/mrjs/edit/main/README.md" \
--metadata title="$site_name" \
--metadata slug="" \
--metadata-file="${outputDir}/docs.yaml" \
--lua-filter colgroups.lua \
--lua-filter anchorlinks.lua \
--highlight-style pygments \
--wrap=none \
-f commonmark_x \
-s -p \
-o "${outputDir}/index.html"
IFS="$OLDIFS"
echo -e "🎀 Website smooshed!\n"