feed-the-void/dd-progress-to-html.py

16 lines
837 B
Python
Raw Permalink Normal View History

2024-01-02 22:26:36 -06:00
#!/usr/bin/env python3
# From https://stackoverflow.com/a/25755038
from subprocess import Popen, PIPE, STDOUT
from os import remove, system
BASE_DIR = '/data'
SITE_FILES_DIR = f'{BASE_DIR}/site-files'
system(f'pandoc -f markdown-smart --data-dir . --template {SITE_FILES_DIR}/template.html -t html -o {SITE_FILES_DIR}/tmp.html {SITE_FILES_DIR}/index.md --metadata title="$(grep -m 1 -oP \'(?<=^# ).*\' {SITE_FILES_DIR}/index.md | cat)"')
system(f'sed -i "s/sourceCode /language-/g" {SITE_FILES_DIR}/tmp.html')
shell = Popen(['dd', 'if=/dev/zero', 'of=/dev/null', 'status=progress'],
stdout=PIPE, stderr=STDOUT, universal_newlines=True, bufsize=1)
for line in iter(shell.stdout.readline, b''):
system(f'sed "s/output here/{line.strip().replace("/", "\\/")}/g" {SITE_FILES_DIR}/tmp.html >{SITE_FILES_DIR}/index.html')