First tests

This commit is contained in:
Josemar Lohn 2021-02-10 20:48:40 +00:00
parent adfc0fdde1
commit 26468aec34
10 changed files with 87 additions and 100 deletions

View File

@ -1,16 +1,16 @@
#!/usr/bin/env bash
# Create an index page with all the posts
declare archive_index
declare template_archive_index_page
declare template_archive_title
declare date_allposts_header
declare date_format
declare date_locale
declare index_file
declare global_title
declare global_author
all_posts() {
declare archive_index
declare template_archive_index_page
declare template_archive_title
declare date_allposts_header
declare date_format
declare date_locale
declare index_file
declare global_title
declare global_author
echo -n "Creating an index page with all the posts "
contentfile=$archive_index.$RANDOM
while [[ -f $contentfile ]]; do

View File

@ -1,17 +1,17 @@
#!/usr/bin/env bash
# Create an index page with all the tags
declare tags_index
declare template_tags_posts
declare template_tags_posts_singular
declare template_tags_posts_2_4
declare template_tags_title
declare prefix_tags
declare index_file
declare template_archive_index_page
declare global_author
declare global_title
all_tags() {
declare tags_index
declare template_tags_posts
declare template_tags_posts_singular
declare template_tags_posts_2_4
declare template_tags_title
declare prefix_tags
declare index_file
declare template_archive_index_page
declare global_author
declare global_title
echo -n "Creating an index page with all the tags "
contentfile=$tags_index.$RANDOM
while [[ -f $contentfile ]]; do

View File

@ -12,14 +12,14 @@
# $4 title for the html header
# $5 original blog timestamp
# $6 post author
declare body_begin_file
declare date_inpost
declare date_locale
declare date_format
declare date_format_timestamp
declare global_url
declare body_end_file
create_html_page() {
declare body_begin_file
declare date_inpost
declare date_locale
declare date_format
declare date_format_timestamp
declare global_url
declare body_end_file
content=$1
filename=$2
index=$3

View File

@ -1,21 +1,21 @@
#!/usr/bin/env bash
# generate headers, footers, etc
declare global_author
declare global_author_url
declare global_description
declare global_email
declare global_feedburner
declare global_license
declare global_title
declare global_url
declare index_file
declare header_file
declare css_include
declare template_subscribe_browser_button
declare blog_feed
declare footer_file
create_includes() {
declare global_author
declare global_author_url
declare global_description
declare global_email
declare global_feedburner
declare global_license
declare global_title
declare global_url
declare index_file
declare header_file
declare css_include
declare template_subscribe_browser_button
declare blog_feed
declare footer_file
{
echo "<h1 class=\"nomargin\"><a class=\"ablack\" href=\"$global_url/$index_file\">$global_title</a></h1>"
echo "<div id=\"description\">$global_description</div>"

View File

@ -1,8 +1,8 @@
#!/usr/bin/env bash
# Detects if GNU date is installed
declare date_format_full
date_version_detect() {
declare date_format_full
if ! stat -c"%U" /dev/null >/dev/null 2>&1 ; then
# BSD environment
if command -v gdate >/dev/null 2>&1 ; then

View File

@ -37,19 +37,19 @@ do_main() {
if [[ $1 == edit ]]; then
if (($# < 2)) || [[ ! -f ${!#} ]]; then
echo "Please enter a valid .md or .html file to edit"
echo "Please enter a valid .md file to edit"
exit
fi
fi
# Test for existing html files
if ls ./*.html &> /dev/null; then
if ls ./*.md &> /dev/null; then
# We're going to back up just in case
tar -c -z -f ".backup.tar.gz" -- *.html &&
chmod 600 ".backup.tar.gz"
elif [[ $1 == rebuild ]]; then
echo "Can't find any html files, nothing to rebuild"
return
chmod 600 ".backup.tar.gz"
elif [[ $1 == rebuild ]]; then
echo "Can't find any html files, nothing to rebuild"
return
fi
# Keep first backup of this day containing yesterday's version of the blog

View File

@ -4,5 +4,6 @@
#
# $1 the html file
get_post_title() {
awk '/<h3><a class="ablack" href=".+">/, /<\/a><\/h3>/{if (!/<h3><a class="ablack" href=".+">/ && !/<\/a><\/h3>/) print}' "$1"
#awk '/<h3><a class="ablack" href=".+">/, /<\/a><\/h3>/{if (!/<h3><a class="ablack" href=".+">/ && !/<\/a><\/h3>/) print}' "$1"
head -1 $1
}

View File

@ -9,6 +9,8 @@
# Return 0 (bash return value 'true') if the input file is an index, feed, etc
# or 1 (bash return value 'false') if it is a blogpost
is_boilerplate_file() {
return 1 ### Ugly Hack to Temporally disable the verification
declare non_blogpost_files
declare index_file
declare archive_index

View File

@ -1,13 +1,14 @@
#!/usr/bin/env bash
# Displays a list of the posts
declare date_format
declare date_locale
list_posts() {
declare date_format
declare date_locale
if ls ./*.html > /dev/null; then
echo "No posts yet. Use 'bb.sh post' to create one" && return
fi
ls ./*.md &> /dev/null
(($? != 0)) &&
echo "No posts yet. Use '$0 post' to create one" &&
return
lines=""
n=1
while IFS='' read -r i; do
@ -15,7 +16,6 @@ list_posts() {
line="$n # $(get_post_title "$i") # $(LC_ALL=$date_locale date -r "$i" +"$date_format")"
lines+=$line\\n
n=$(( n + 1 ))
done < <(ls -t ./*.html)
done < <(ls -t ./*.md)
echo -e "$lines" | column -t -s "#"
}

View File

@ -2,46 +2,26 @@
# Manages the creation of the text file and the parsing to html file
# also the drafts
declare template_tags_line_header
declare global_url
declare convert_filename
write_entry() {
declare template_tags_line_header
declare global_url
declare convert_filename
declare save_markdown
test_markdown && fmt=md || fmt=html
f=$2
[[ $2 == -html ]] && fmt=html && f=$3
if [[ -n $f ]]; then
TMPFILE=$f
if [[ ! -f $TMPFILE ]]; then
echo "The file doesn't exist"
extension=${f##*.}
if [[ $extension != md ]]; then
f=${f}.md
fi
if [[ -n $f ]]; thenq
if [[ -f $f ]]; then
echo "The file $f doesn't exist"
delete_includes
exit
fi
# guess format from TMPFILE
extension=${TMPFILE##*.}
[[ $extension == md || $extension == html ]] && fmt=$extension
# but let user override it (`bb.sh post -html file.md`)
[[ $2 == -html ]] && fmt=html
# Test if Markdown is working before re-posting a .md file
if [[ $extension == md ]]; then
if test_markdown; then
echo "Markdown is not working, please edit HTML file directly."
exit
fi
fi
else
TMPFILE=.entry-$RANDOM.$fmt
echo -e "Title on this line\n" >> "$TMPFILE"
[[ $fmt == html ]] && cat << EOF >> "$TMPFILE"
<p>The rest of the text file is an <b>html</b> blog post. The process will continue as soon
as you exit your editor.</p>
<p>$template_tags_line_header keep-this-tag-format, tags-are-optional, example</p>
EOF
[[ $fmt == md ]] && cat << EOF >> "$TMPFILE"
cat << EOF >> "$TMPFILE"
The rest of the text file is a **Markdown** blog post. The process will continue
as soon as you exit your editor.
@ -54,21 +34,29 @@ EOF
filename=""
while [[ $post_status != "p" && $post_status != "P" ]]; do
[[ -n $filename ]] && rm "$filename" # Delete the generated html file, if any
$EDITOR "$TMPFILE"
if [[ $fmt == md ]]; then
html_from_md=$(mrkdwn "$TMPFILE")
parse_file "$html_from_md"
rm "$html_from_md"
else
parse_file "$TMPFILE" # this command sets $filename as the html processed file
fi
html_from_md=$(mrkdwn "$TMPFILE")
parse_file "$html_from_md"
rm "$html_from_md"
chmod 644 "$filename"
[[ -n $preview_url ]] || preview_url=$global_url
echo "To preview the entry, open $preview_url/$filename in your browser"
echo -n "[P]ost this entry, [E]dit again, [D]raft for later? (p/E/d) "
echo -n "[P]ost this entry, [E]dit again, [D]raft for later, [C]ancel and quit? (p/e/d/c) "
read -r post_status
#Case user cancelled
if [[ $post_status == c || $post_status == C ]]; then
rm "$TMPFILE"
delete_includes
echo "Your draft was erased. Nothing was changed in your blog."
exit
fi
#Case User choose post
if [[ $post_status == d || $post_status == D ]]; then
mkdir -p "drafts/"
chmod 700 "drafts/"
@ -87,11 +75,7 @@ EOF
fi
done
if [[ $fmt == md && -n $save_markdown ]]; then
mv "$TMPFILE" "${filename%%.*}.md"
else
rm "$TMPFILE"
fi
mv "$TMPFILE" "${filename%%.*}.md"
chmod 644 "$filename"
echo "Posted $filename"
relevant_tags=$(tags_in_post "$filename")