summaryrefslogtreecommitdiff
path: root/justfile
diff options
context:
space:
mode:
authorAndrew Guschin <guschin@altlinux.org>2024-02-29 13:28:19 +0400
committerAndrew Guschin <guschin@altlinux.org>2024-02-29 13:28:19 +0400
commitda1d503b85112c22c17d142d0b05974ec38ebcf2 (patch)
tree16a13b24bf4ebff8ed04551cbfcd3d8e82f50af3 /justfile
parent3038bbfc64924bce04f06665f89acdc5df05b20e (diff)
fix: рецепт format переписан на python
На разных устройствах возникали какие-то проблемы с тем, что index.html файл почему-то оказывался пустым. Так как от python уже зависит другой рецепт, то ситуацию это не должно ухудшить никаким образом (только если для локального хостинга мы заменим встроенный в python вебсервер, в чём я сомневаюсь).
Diffstat (limited to 'justfile')
-rw-r--r--justfile14
1 files changed, 10 insertions, 4 deletions
diff --git a/justfile b/justfile
index d344180..be83f99 100644
--- a/justfile
+++ b/justfile
@@ -1,7 +1,13 @@
-format $filename:
- #!/bin/sh
- title=`sed -n 's/^# \(.*\)/\1/p' $filename | head -n1`
- printf "$(< template.html)\n" "$title" "$filename" > index.html
+format filename:
+ #!/usr/bin/env python3
+ import re
+ with open("{{filename}}") as f:
+ m = re.search("^# (.*)", f.read())
+ title = "Презентация" if m is None else m.group(1)
+ with open("template.html") as f:
+ template = f.read()
+ with open("index.html", "w") as f:
+ f.write(template % (title, "{{filename}}"))
serve filename port="8000": (format filename)
python3 -m http.server {{port}}