chore: remove ppp submodule
continuous-integration/drone/push Build was killed Details

This commit is contained in:
ktyl 2024-06-08 16:15:02 +01:00
parent 2471160986
commit 49333b641e
3 changed files with 86 additions and 4 deletions

View File

@ -45,10 +45,10 @@ deploy:
ssh $(HOST) "sudo $(REMOTE_SCRIPT)" ssh $(HOST) "sudo $(REMOTE_SCRIPT)"
$(OUT_DIR)/%.html: $(ROOT_DIR)/%.html $(HTML_INCLUDES) $(BLOG_INDEX) | $(OUT_DIR) $(OUT_DIR)/%.html: $(ROOT_DIR)/%.html $(HTML_INCLUDES) $(BLOG_INDEX) | $(OUT_DIR)
python ppp/ppp.py $< $(HTML_INCLUDES) $(BLOG_INDEX) > $@ python ppp.py $< $(HTML_INCLUDES) $(BLOG_INDEX) > $@
$(OUT_DIR)/%.css: $(ROOT_DIR)/%.css $(CSS_INCLUDES) | $(OUT_DIR) $(OUT_DIR)/%.css: $(ROOT_DIR)/%.css $(CSS_INCLUDES) | $(OUT_DIR)
python ppp/ppp.py $< $(CSS_INCLUDES) > $@ python ppp.py $< $(CSS_INCLUDES) > $@
$(OUT_DIR): $(OUT_DIR):
mkdir -p $@ mkdir -p $@
@ -63,7 +63,7 @@ blog: $(HTML_INCLUDES) $(CSS_TARGETS)
make --directory $(BLOG_BASE_DIR) html make --directory $(BLOG_BASE_DIR) html
cp -r $(BLOG_BUILD_DIR)/* $(BLOG_OUT_DIR) cp -r $(BLOG_BUILD_DIR)/* $(BLOG_OUT_DIR)
for page in `find "$(BLOG_OUT_DIR)" -wholename "*.html"`; do \ for page in `find "$(BLOG_OUT_DIR)" -wholename "*.html"`; do \
pipenv run python ppp/ppp.py $$page $(HTML_INCLUDES) > temp ; \ python ppp.py $$page $(HTML_INCLUDES) > temp ; \
mv temp $$page ; \ mv temp $$page ; \
cp $(CSS_TARGETS) $(IMG_DIR)/*.ico `dirname $$page` ; \ cp $(CSS_TARGETS) $(IMG_DIR)/*.ico `dirname $$page` ; \
done done

1
ppp

@ -1 +0,0 @@
Subproject commit 2253d24ad239afe2b4fe2cf53471bcc3414879cd

83
ppp.py Normal file
View File

@ -0,0 +1,83 @@
import sys
import os.path
import re
err = False
paths = []
def print_usage():
print("\nusage: python ppp.py ROOT TEMPLATES [...]")
# check arguments
argc = len(sys.argv)
if argc < 3:
print_usage()
sys.exit(1)
includes = sys.argv[2:]
# figure out src dir from root argument
sep="/"
src_dir = sep.join(sys.argv[2].split(sep)[:-1])
# regex patterns
p_var = re.compile(r'(#.+?\.css)')
def preprocess_file(path):
lines=0
with open(path) as f:
content = f.readlines()
content = [x.strip('\n') for x in content]
lines=len(content)
for l in content:
# replace lines that start with #include with the contents of a file
if l.startswith("#include"):
include_path = l.split(" ")[1]
# prepend directory
#include_path = "/".join([src_dir, include_path])
for inc in includes:
if os.path.basename(inc) == include_path:
include_path = inc
break
preprocess_file(include_path)
continue
# inline replace any occurrence of #filename with the contents of that file
match = re.search(p_var, l)
if match:
path = "/".join([src_dir, match.group(0)[1:]])
with open(path) as var_file:
var_content = var_file.read().strip()
l = re.sub(p_var, var_content, l)
print(l)
for i in range(1,argc):
path = sys.argv[i]
if not os.path.isfile(path):
print(path + " is not a file")
err = True
continue
if path in paths:
# ignore duplicates
continue
paths.append(path)
if err:
print_usage()
sys.exit(1)
preprocess_file(sys.argv[1])
sys.exit(0)