Compare commits

...

3 Commits

Author SHA1 Message Date
veclav talica
0c89da7c3d host.sh: automatically open the page 2024-02-16 20:04:09 +05:00
veclav talica
41b18b8b05 new-article.sh: utility for creation of article stub in cli 2024-02-16 20:00:26 +05:00
veclav talica
d7a434ea11 fix the_line_after_metadata() 2024-02-16 19:59:57 +05:00
3 changed files with 43 additions and 3 deletions

View File

@ -1,3 +1,3 @@
#!/usr/bin/env bash #!/usr/bin/env bash
python3 -m http.server --directory ./html/ python3 -m http.server --directory ./html/ & xdg-open http://0.0.0.0:8000/

40
new-article.sh Executable file
View File

@ -0,0 +1,40 @@
#!/usr/bin/env bash
set +e
printf "%s" "Enter title: "
read title
printf "%s" "Enter directory name: "
read directory
if [ -d "./articles/$directory/" ]; then
echo "Directory already exists, aborted."
exit
fi
printf "%s" "Enter brief: "
read brief
printf "%s" "Enter tags: "
read tags
mkdir "./articles/$directory/"
mask=$(cat <<-format
Title: %s
Brief: %s
Date: %s
Tags: %s
CSS: /style.css
format
)
date=$(date +%s)
printf "$mask" "$title" "$brief" "$date" "$tags" \
> "./articles/$directory/page.mmd"
if which xdg-open &> /dev/null; then
xdg-open "./articles/$directory/page.mmd"
fi

View File

@ -2,7 +2,7 @@ import time, subprocess
def the_line_after_metadata(lines: []) -> int: def the_line_after_metadata(lines: []) -> int:
i = 0 i = 0
while lines[i].strip(): while i < len(lines) and lines[i].strip():
i += 1 i += 1
return i return i
@ -19,7 +19,7 @@ def parse_metadata(filepath: str) -> {}:
result["Date"] = time.gmtime(int(val)) result["Date"] = time.gmtime(int(val))
elif key == "Tags": elif key == "Tags":
result["Tags"] = [v.strip() for v in val.split(",")] result["Tags"] = [v.strip() for v in val.split(",")]
else: elif val:
result[key] = val result[key] = val
result["Last Edit"] = time.gmtime(int(subprocess.getoutput(r"stat -c %Y " + filepath))) result["Last Edit"] = time.gmtime(int(subprocess.getoutput(r"stat -c %Y " + filepath)))