-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert_markdown_to_html.py
executable file
·38 lines (32 loc) · 1.25 KB
/
convert_markdown_to_html.py
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
#!/usr/bin/env python
import os
import subprocess
# Function to convert Markdown to HTML if Markdown file is newer
def convert_markdown_to_html_if_newer(markdown_file):
html_file0 = os.path.splitext(markdown_file)[0] + ".html"
html_file = html_file0[:2]+"HTML/"+html_file0[2:]
# Check if HTML file exists and compare modification timestamps
if not os.path.exists(html_file) or os.path.getmtime(markdown_file) > os.path.getmtime(html_file):
subprocess.run(
[
"pandoc",
"-s",
"--katex",
"--lua-filter",
"fix-links-multiple-files.lua",
"-o",
html_file,
markdown_file,
]
)
#print(f"Converted {markdown_file} to {html_file}")
#else:
#print(f"{markdown_file} is up to date. Skipping conversion.")
# Define the root directory where your Markdown files are located
root_directory = "./"
# Recursively iterate through all Markdown files in the root directory
for root, _, files in os.walk(root_directory):
for file in files:
if file.endswith(".md"):
markdown_file = os.path.join(root, file)
convert_markdown_to_html_if_newer(markdown_file)