improving installation + adding variable to execute awk script

This commit is contained in:
Simon Petit 2024-10-28 22:06:49 +01:00
parent 5234e54a81
commit 029a99216d
3 changed files with 14 additions and 8 deletions

2
.gitignore vendored
View File

@ -4,4 +4,4 @@ css
bash bash
posts posts
*.conf *.conf
index.html ./index.html

View File

@ -1,14 +1,13 @@
install: install:
@echo "Installing bob" @echo "Installing bob"
cp bob /usr/local/bin cp bob /usr/local/bin
cp bob2 /usr/local/bin mkdir -p /usr/local/lib/bob/template
cp -r lib/template /usr/local/lib/bob/template cp lib/template/* /usr/local/lib/bob/template
cp lib/*.awk /usr/local/lib/bob cp lib/*.awk /usr/local/lib/bob
uninstall: uninstall:
@echo "Uninstalling bob" @echo "Uninstalling bob"
rm /usr/local/bin/bob rm /usr/local/bin/bob
rm /usr/local/bin/bob2
rm -rf /usr/local/lib/bob rm -rf /usr/local/lib/bob
.PHONY: test # Declare 'test' as a phony target .PHONY: test # Declare 'test' as a phony target

15
bob
View File

@ -1,5 +1,11 @@
#!/usr/bin/env bash #!/usr/bin/env bash
if [ -z "${BOB_LIB}" ]; then
BOB_LIB=/usr/local/lib/bob
else
BOB_LIB=./lib
fi
usage() usage()
{ {
echo echo
@ -66,15 +72,15 @@ update_index()
print "</ul>" print "</ul>"
}') }')
template="./lib/template/index.html" template="${BOB_LIB}/template/index.html"
awk -v content="$posts" '{gsub(/{{articles}}/, content); print}' "$template" > "./index.html" awk -v content="$posts" '{gsub(/{{articles}}/, content); print}' "$template" > "./index.html"
} }
publish() publish()
{ {
post=$(awk -f lib/markdown.awk ./drafts/$1.md) post=$(awk -f ${BOB_LIB}/markdown.awk ./drafts/$1.md)
template="./lib/template/post.html" template="${BOB_LIB}/template/post.html"
awk -v content="$post" '{gsub(/{{article}}/, content); print}' "$template" > "./posts/$1.html" awk -v content="$post" '{gsub(/{{article}}/, content); print}' "$template" > "./posts/$1.html"
mv ./drafts/$1.md ./drafts/published/$1.md mv ./drafts/$1.md ./drafts/published/$1.md
@ -92,11 +98,12 @@ unpublish()
unpublish_all() unpublish_all()
{ {
rm ./posts/* rm ./posts/*
mv ./drafts/published/* ./drafts/
} }
deploy() deploy()
{ {
scp echo "TODO"
} }
if [[ $# -eq 0 ]]; then if [[ $# -eq 0 ]]; then