CS-Coursework/documentation/markdown-to-html.sh

52 lines
1.2 KiB
Bash
Raw Normal View History

2024-03-21 17:13:37 +00:00
#!/bin/bash
# HTML structure
html_start='
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="github-markdown.css">
</head>
<body class="markdown-body">
<style>
.markdown-body {
box-sizing: border-box;
min-width: 200px;
max-width: 980px;
margin: 0 auto;
padding: 45px;
}
2024-03-21 17:13:37 +00:00
@media (max-width: 767px) {
.markdown-body {
padding: 15px;
}
}
</style>
'
2024-03-21 17:13:37 +00:00
html_end='
</body>
</html>
'
2024-03-21 17:13:37 +00:00
# Iterate over each markdown file in the current directory
for file in *.md; do
# Read markdown content from file
markdown_content=$(cat "$file")
# Convert markdown to HTML
html_content=$(gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/markdown \
-f text="$markdown_content"
)
# Write HTML content to a new file
html_file="./html/${file%.md}.html"
echo "$html_start$html_content$html_end" > "$html_file"
echo "Conversion completed. HTML content written to $html_file"
done