From da1d503b85112c22c17d142d0b05974ec38ebcf2 Mon Sep 17 00:00:00 2001 From: Andrew Guschin Date: Thu, 29 Feb 2024 13:28:19 +0400 Subject: =?UTF-8?q?fix:=20=D1=80=D0=B5=D1=86=D0=B5=D0=BF=D1=82=20format=20?= =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=BF=D0=B8=D1=81=D0=B0=D0=BD=20=D0=BD?= =?UTF-8?q?=D0=B0=20python?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit На разных устройствах возникали какие-то проблемы с тем, что index.html файл почему-то оказывался пустым. Так как от python уже зависит другой рецепт, то ситуацию это не должно ухудшить никаким образом (только если для локального хостинга мы заменим встроенный в python вебсервер, в чём я сомневаюсь). --- justfile | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'justfile') 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}} -- cgit v1.2.3