MAJOR Completing the header with a link to the main page + changing the command lines arguments

This commit is contained in:
Simon Petit 2019-07-05 12:21:30 +02:00
parent 5de38b8d5b
commit be57278e8a

134
bob
View File

@ -35,10 +35,10 @@ _get_blog_lang()
_add_header() _add_header()
{ {
post_name=$1 post_name=$1
lang=$2 blog_name=$2
dark=$3 lang=$3
dark=$4
css="../css/poststyle.css" css="../css/poststyle.css"
if [[ $dark =~ "y" ]]; then if [[ $dark =~ "y" ]]; then
@ -57,6 +57,9 @@ _add_header()
</head> </head>
<body> <body>
<article class='post'> <article class='post'>
<header>
<h2><a href="../index.html">$blog_name</a></h2>
</header>
EOF EOF
} }
@ -66,6 +69,7 @@ _add_footer()
cat >> ./posts/$post_name.html << EOF cat >> ./posts/$post_name.html << EOF
</article> </article>
<footer> <footer>
<span>generated by <a href="https://www.github.com/SiwonP/bob">bob</a></span>
</footer> </footer>
</body> </body>
</html> </html>
@ -114,7 +118,7 @@ publish()
# Append the names to the array # Append the names to the array
posts_names+=(${BASH_REMATCH[1]}) posts_names+=(${BASH_REMATCH[1]})
fi fi
_create_posts "./drafts/${list[i]}" "$lang" "$dark" _create_posts "./drafts/${list[i]}" "$blog_name" "$lang" "$dark"
done done
# function to update the index.html # function to update the index.html
@ -125,15 +129,16 @@ publish()
_create_posts() _create_posts()
{ {
draft=$1 draft=$1
lang=$2 blog_name=$2
dark=$3 lang=$3
dark=$4
# Convert the markdown file $draft into html # Convert the markdown file $draft into html
# and store the result in $content # and store the result in $content
content=`multimarkdown --nolabels $draft` content=`multimarkdown --nolabels $draft`
# Regex to extract the simple post name # Regex to extract the simple post name
md_regex="([a-zA-Z]+)\.(md|markdown)" md_regex="([a-zA-Z\-]+)\.(md|markdown)"
if [[ $draft =~ $md_regex ]]; then if [[ $draft =~ $md_regex ]]; then
# If the file have md or markdown extension, cut it # If the file have md or markdown extension, cut it
@ -142,9 +147,8 @@ _create_posts()
# if not and it has no extension, keep it this way # if not and it has no extension, keep it this way
post_name=$draft post_name=$draft
fi fi
# Integrate the html converted content into a proper html file # Integrate the html converted content into a proper html file
_build_post "$post_name" "$content" "$lang" "$dark" _build_post "$post_name" "$blog_name" "$content" "$lang" "$dark"
} }
_build_post() _build_post()
@ -152,11 +156,12 @@ _build_post()
# Create the html file of the post $post_name with the # Create the html file of the post $post_name with the
# previsouly converted markdown to html $content # previsouly converted markdown to html $content
post_name=$1 post_name=$1
content=$2 blog_name=$2
lang=$3 content=$3
dark=$4 lang=$4
dark=$5
_add_header "$post_name" "$lang" "$dark" _add_header "$post_name" "$blog_name" "$lang" "$dark"
echo $content >> ./posts/$post_name.html echo $content >> ./posts/$post_name.html
_add_footer "$post_name" _add_footer "$post_name"
} }
@ -201,7 +206,7 @@ then
fi fi
# Regex to extract just the name of the post # Regex to extract just the name of the post
post_regex="([a-zA-Z]+)\.md" post_regex="([a-zA-Z\-]+)\.(md|markdown)"
for (( i=0; i<${#drafts_list[@]}; i++ )); for (( i=0; i<${#drafts_list[@]}; i++ ));
do do
@ -240,6 +245,7 @@ _add_post_link()
url=$1 url=$1
post_name=$2 post_name=$2
date=$3 date=$3
post_name=${post_name//\-/ }
echo "<li class='post'>" >> index.html echo "<li class='post'>" >> index.html
echo "<a href="$url">$post_name</a>" >> index.html echo "<a href="$url">$post_name</a>" >> index.html
echo "<span class='date'>$date</span>" >> index.html echo "<span class='date'>$date</span>" >> index.html
@ -361,11 +367,27 @@ cat > ./css/poststyle.css << EOF
body { body {
font-family: 'IBM Plex Mono', monospace; font-family: 'IBM Plex Mono', monospace;
} }
header a {
text-decoration: none;
}
header a:hover {
text-decoration: underline;
}
header {
margin-bottom: 6vh;
}
.post { .post {
width: 70vw; width: 70vw;
margin-right: auto; margin-right: auto;
margin-left: auto; margin-left: auto;
} }
footer {
width: 70vw;
margin-top: 6vh;
margin-right: auto;
margin-left: auto;
font-size: 1.3vh;
}
EOF EOF
cat > ./css/poststyle.dark.css << EOF cat > ./css/poststyle.dark.css << EOF
@ -374,11 +396,29 @@ body {
background: #222; background: #222;
color: #e1e1e1; color: #e1e1e1;
} }
header a {
color: #777;
text-decoration: none;
}
header a:hover {
text-decoration: underline;
color: #e1e1e1;
}
header {
margin-bottom: 6vh;
}
.post { .post {
width: 70vw; width: 70vw;
margin-right: auto; margin-right: auto;
margin-left: auto; margin-left: auto;
} }
footer {
width: 70vw;
margin-top: 6vh;
margin-right: auto;
margin-left: auto;
font-size: 1.3vh;
}
EOF EOF
} }
@ -419,6 +459,12 @@ change_mode()
delete_posts() delete_posts()
{ {
# posts=`ls ./posts/`
# echo $posts/
# if [ "$posts" == "/" ]; then
# echo empty
# fi
rm ./posts/*.html rm ./posts/*.html
} }
@ -447,28 +493,38 @@ usage()
echo " -l change the language of the blog (not implemented yet)" echo " -l change the language of the blog (not implemented yet)"
} }
while getopts ":ihpdm" opt; do # while getopts ":ihpdm" opt; do
case ${opt} in # case ${opt} in
i ) # i )
init # init
;; # ;;
p ) # p )
publish # publish
;; # ;;
h ) # h )
usage # usage
;; # ;;
m ) # m )
change_mode # change_mode
;; # ;;
d ) # d )
delete_posts # delete_posts
;; # ;;
\? ) # \? )
usage # usage
;; # ;;
: ) # : )
usage # usage
;; # ;;
esac # esac
done # done
if [[ $# -eq 0 ]]; then
usage
elif [[ "$1" == "init" ]]; then
init
elif [[ "$1" == "publish" ]]; then
publish
elif [[ "$1" == "help" ]]; then
usage
fi