This commit is contained in:
Simon Petit 2024-10-26 16:39:45 +02:00
parent 9257373163
commit 191c3a78e5
6 changed files with 93 additions and 29 deletions

1
.gitignore vendored
View File

@ -5,4 +5,3 @@ bash
posts
*.conf
index.html
README.html

View File

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

61
bob2
View File

@ -16,7 +16,7 @@ usage()
echo
echo "bob commands :"
echo " help display this help"
echo " init initiate the blog"
echo " init initiate a blog"
echo " publish publish the blog"
}
@ -25,31 +25,60 @@ init()
{
echo Name of the author of the blog :
read author
echo "author:$author" > .blog.conf
echo "author=$author" > .blog.conf
echo Name of the blog :
read blog
echo "blog:$blog" >> .blog.conf
echo "Language of the blog : (en)"
echo "blog=$blog" >> .blog.conf
echo "Language of the blog : [en]"
read lang
if [ -z $lang ]; then
lang=en
fi
echo "lang:$lang" >> .blog.conf
echo "lang=$lang" >> .blog.conf
echo "Activate dark mode : (y/N)"
read dark
if [ -z $dark ]; then
dark=n
fi
echo "dark:$dark" >> .blog.conf
echo "dark=$dark" >> .blog.conf
mkdir drafts
mkdir bases
# mkdir templates
mkdir posts
mkdir css
_init_css
_index "$blog" "$lang" "$dark"
# mkdir css
# _init_css
# _index "$blog" "$lang" "$dark"
}
update_index()
{
ls -t ./posts | awk '
BEGIN {
print "<ul>"
}
{
ref=$0
gsub(".html","",ref)
gsub(/[_-]/, " ", ref)
print "<li><a href=\"./posts/" $0 "\">" ref "</a></li>"
}
END {
print "</ul>"
}'
}
publish()
{
post=$(awk -f lib/markdown.awk ./drafts/$1.md)
template="./lib/template/post.html"
awk -v content="$post" '{gsub(/{{article}}/, content); print}' "$template" > "./posts/$1.html"
mv ./drafts/$1.md ./drafts/published/$1.md
}
unpublish()
{
rm ./posts/$1.html
mv ./drafts/published/$1.md ./drafts/$1.md
}
if [[ $# -eq 0 ]]; then
usage
@ -60,7 +89,17 @@ elif [[ "$1" == "usage" ]]; then
elif [[ "$1" == "init" ]]; then
init
elif [[ "$1" == "publish" ]]; then
publish
if [[ $# -eq 1 ]]; then
echo "Usage : bob publish <draft_name>"
else
publish $2
fi
elif [[ "$1" == "unpublish" ]]; then
if [[ $# -eq 1 ]]; then
echo "Usage : bob unpublish <post_name>"
else
unpublish $2
fi
elif [[ "$1" == "help" ]]; then
usage
fi

View File

@ -1,16 +1,19 @@
<!DOCTYPE html>
<html lang="fr" dir="ltr">
<head>
<head>
<meta charset="utf-8">
<title>simpet</title>
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<link href="https://fonts.googleapis.com/css?family=Cutive+Mono|IBM+Plex+Mono&display=swap" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="./css/indexstyle.css">
</head>
<body>
<link rel="stylesheet" type="text/css" href="../css/indexstyle.css">
</head>
<body>
<h1 class='title'>simpet</h1>
<article>
{{article}}
</article>
</body>
</body>
</html>

0
test/bob/test_init.sh Normal file
View File

View File

@ -8,4 +8,26 @@ NC='\033[0m' # No Color (reset)
echo -e "${YELLOW}Testing markown parser :${NC}\n"
./parser/test_md_parser.sh ../lib/markdown.awk awk
./test/parser/test_md_parser.sh ./lib/markdown.awk awk
echo -e "${YELLOW}Testing bob init :${NC}\n"
author="author"
blog="blog"
lang="fr"
dark="y"
./bob2 init << EOF
$author
$blog
$lang
$dark
EOF
conf_author=$(grep "^author=" .blog.conf | cut -d '=' -f 2)
conf_blog=$(grep "^blog=" .blog.conf | cut -d '=' -f 2)
conf_lang=$(grep "^lang=" .blog.conf | cut -d '=' -f 2)
conf_dark=$(grep "^dark=" .blog.conf | cut -d '=' -f 2)
rm -r posts
rm -r drafts