Fixed variables problem and removed html edit.

This commit is contained in:
Josemar Lohn 2021-02-11 03:44:09 -03:00
parent 26468aec34
commit e6161e9717
28 changed files with 223 additions and 213 deletions

View File

@ -1,11 +1,12 @@
#!/usr/bin/env bash
# Create the css file from scratch
declare css_include
create_css() {
# To avoid overwriting manual changes. However it is recommended that
# this function is modified if the user changes the blog.css file
(( ${#css_include[@]} > 0 )) && return || css_include=('main.css' 'blog.css')
if [[ ! -f blog.css ]]; then
((${#css_include[@]} > 0)) && return || css_include=('main.css' 'blog.css')
if [[ ! -f blog.css ]]; then
# blog.css directives will be loaded after main.css and thus will prevail
echo '#title{font-size: x-large;}
a.ablack{color:black !important;}
@ -19,14 +20,14 @@ create_css() {
h3{margin-top:42px;margin-bottom:8px;}
h4{margin-left:24px;margin-right:24px;}
img{max-width:100%;}
#twitter{line-height:20px;vertical-align:top;text-align:right;font-style:italic;color:#333;margin-top:24px;font-size:14px;}' > blog.css
#twitter{line-height:20px;vertical-align:top;text-align:right;font-style:italic;color:#333;margin-top:24px;font-size:14px;}' >blog.css
fi
# If there is a style.css from the parent page (i.e. some landing page)
# then use it. This directive is here for compatibility with my own
# home page. Feel free to edit it out, though it doesn't hurt
if [[ -f ../style.css ]] && [[ ! -f main.css ]]; then
ln -s "../style.css" "main.css"
ln -s "../style.css" "main.css"
elif [[ ! -f main.css ]]; then
echo 'body{font-family:Georgia,"Times New Roman",Times,serif;margin:0;padding:0;background-color:#F3F3F3;}
#divbodyholder{padding:5px;background-color:#DDD;width:100%;max-width:874px;margin:24px auto;}
@ -43,6 +44,6 @@ create_css() {
a:visited{text-decoration:none;color:#336699 !important;}
blockquote{background-color:#f9f9f9;border-left:solid 4px #e9e9e9;margin-left:12px;padding:12px 12px 12px 24px;}
blockquote img{margin:12px 0px;}
blockquote iframe{margin:12px 0px;}' > main.css
blockquote iframe{margin:12px 0px;}' >main.css
fi
}
}

View File

@ -18,16 +18,16 @@ do_main() {
# Load default configuration, then override settings with the config file
global_variables
# shellcheck disable=SC1090 # variable config file
[[ -f "$global_config" ]] && source "$global_config" &> /dev/null
[[ -f "$global_config" ]] && source "$global_config" &>/dev/null
global_variables_check
# Check for $EDITOR
[[ -z $EDITOR ]] &&
echo "Please set your \$EDITOR environment variable. For example, to use nano, add the line 'export EDITOR=nano' to your \$HOME/.bashrc file" && exit
[[ -z $EDITOR ]] &&
EDITOR=vim
# Check for validity of argument
[[ $1 != "reset" && $1 != "post" && $1 != "rebuild" && $1 != "list" && $1 != "edit" && $1 != "delete" && $1 != "tags" ]] &&
usage && return
[[ $1 != "reset" && $1 != "post" && $1 != "rebuild" && $1 != "list" && $1 != "edit" && $1 != "delete" && $1 != "tags" ]] &&
usage && return
[[ $1 == list ]] &&
list_posts && return
@ -43,10 +43,10 @@ do_main() {
fi
# Test for existing html files
if ls ./*.md &> /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"
chmod 600 ".backup.tar.gz"
elif [[ $1 == rebuild ]]; then
echo "Can't find any html files, nothing to rebuild"
return
@ -54,7 +54,7 @@ do_main() {
# Keep first backup of this day containing yesterday's version of the blog
[[ ! -f .yesterday.tar.gz || $(date -r .yesterday.tar.gz +'%d') != "$(date +'%d')" ]] &&
cp .backup.tar.gz .yesterday.tar.gz &> /dev/null
cp .backup.tar.gz .yesterday.tar.gz &>/dev/null
[[ $1 == reset ]] &&
reset && return
@ -63,7 +63,7 @@ do_main() {
create_includes
[[ $1 == post ]] && write_entry "$@"
[[ $1 == rebuild ]] && rebuild_all_entries && rebuild_tags
[[ $1 == delete ]] && rm "$2" &> /dev/null && rebuild_tags
[[ $1 == delete ]] && rm "$2" &>/dev/null && rebuild_tags
if [[ $1 == edit ]]; then
if [[ $2 == -n ]]; then
edit "$3"
@ -80,4 +80,4 @@ do_main() {
make_gophermap
make_gemini
delete_includes
}
}

View File

@ -12,16 +12,18 @@
# "keep" to keep old filename
# "full" to edit full HTML, and not only text part (keeps old filename)
# leave empty for default behavior (edit only text part and change name)
declare date_format_full
declare date_format_timestamp
declare template_tags_line_header
declare prefix_tags
edit() {
declare date_format_full
declare date_format_timestamp
declare template_tags_line_header
declare prefix_tags
[[ ! -f "${1%%.*}.html" ]] && \
[[ ! -f "${1%%.*}.html" ]] &&
printf "Can't edit post \"%s.html\", did you mean to use \"bb.sh post <draft_file>\"?\\n" "${1%%.*}" && exit 1
# Original post timestamp
edit_timestamp=$(LC_ALL=C date -r "${1%%.*}.html" +"$date_format_full" )
edit_timestamp=$(LC_ALL=C date -r "${1%%.*}.html" +"$date_format_full")
touch_timestamp=$(LC_ALL=C date -r "${1%%.*}.html" +"$date_format_timestamp")
tags_before=$(tags_in_post "${1%%.*}.html")
if [[ $2 == full ]]; then
@ -29,21 +31,17 @@ edit() {
filename=$1
else
if [[ ${1##*.} == md ]]; then
if test_markdown; then
echo "Markdown is not working, please edit HTML file directly."
exit
fi
# editing markdown file
$EDITOR "$1"
TMPFILE=$(mrkdwn "$1")
TMPFILE=$(make_html "$1")
filename=${1%%.*}.html
else
# Create the content file
TMPFILE=$(basename "$1").$RANDOM.html
# Title
get_post_title "$1" > "$TMPFILE"
get_post_title "$1" >"$TMPFILE"
# Post text with plaintext tags
get_html_file_content 'text' 'text' <"$1" | sed "/^<p>$template_tags_line_header/s|<a href='$prefix_tags\([^']*\).html'>\\1</a>|\\1|g" >> "$TMPFILE"
get_html_file_content 'text' 'text' <"$1" | sed "/^<p>$template_tags_line_header/s|<a href='$prefix_tags\([^']*\).html'>\\1</a>|\\1|g" >>"$TMPFILE"
$EDITOR "$TMPFILE"
filename=$1
fi

View File

@ -6,9 +6,9 @@
# $3 "cut" to remove text from <hr /> to <!-- text end -->
# note that this does not remove <hr /> line itself,
# so you can see if text was cut or not
declare cut_line cut_tags
declare template_tags_line_header
get_html_file_content() {
declare cut_line cut_tags
declare template_tags_line_header
awk "/<!-- $1 begin -->/, /<!-- $2 end -->/{
if (!/<!-- $1 begin -->/ && !/<!-- $2 end -->/) print
if (\"$3\" == \"cut\" && /$cut_line/){
@ -18,4 +18,4 @@ get_html_file_content() {
}
}
}"
}
}

View File

@ -5,5 +5,5 @@
# $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"
head -1 $1
}
head -1 "$1"
}

View File

@ -13,14 +13,13 @@ global_config=".tildelog"
global_variables() {
global_software_name="tildelog"
global_software_version="0.1"
# Blog title
global_title="my tildelog"
# The typical subtitle for each blog
global_description="a blog about tildes"
# The server base domain
global_domain="tilde.team"
# The public base URL for this blog
# The public base URL for this blog
global_url="https://${global_domain}/~$USER/blog"
# Your name
global_author="~$USER"
@ -32,8 +31,7 @@ global_variables() {
# CC by-nc-nd is a good starting point, you can change this to "&copy;" for Copyright
global_license="CC by-nc-nd"
# Leave this empty (i.e. "") if you don't want to use feedburner,
# Leave this empty (i.e. "") if you don't want to use feedburner,
# or change it to your own URL
global_feedburner=""
@ -73,8 +71,6 @@ global_variables() {
# Regexp matching the HTML line where to do the cut
# note that slash is regexp separator so you need to prepend it with backslash
cut_line='<hr ?\/?>'
# save markdown file when posting with "bb post -m". Leave blank to discard it.
save_markdown="yes"
# prefix for tags/categories files
# please make sure that no other html file starts with this prefix
prefix_tags="tag_"
@ -110,7 +106,7 @@ global_variables() {
template_tags_title="all tags"
# "posts" (on "All tags" page, text at the end of each tag line, like "2. Music - 15 posts")
template_tags_posts="posts"
template_tags_posts_2_4="posts" # Some slavic languages use a different plural form for 2-4 items
template_tags_posts_2_4="posts" # Some slavic languages use a different plural form for 2-4 items
template_tags_posts_singular="post"
# "Posts tagged" (text on a title of a page with index of one tag, like "My Blog - Posts tagged "Music"")
template_tag_title="posts tagged"
@ -149,17 +145,17 @@ global_variables() {
# Markdown location. Trying to autodetect by default.
# The invocation must support the signature 'markdown_bin in.md > out.html'
markdown_bin=$(which md2html.awk)
# shellcheck disable=SC2016
md2html_bin='awk "$md2html_awk"'
}
# Check for the validity of some variables
# DO NOT EDIT THIS FUNCTION unless you know what you're doing
global_variables_check() {
[[ $header_file == .header.html ]] && \
echo "Please check your configuration. '.header.html' is not a valid value for the setting 'header_file'" && \
[[ $header_file == .header.html ]] &&
echo "Please check your configuration. '.header.html' is not a valid value for the setting 'header_file'" &&
exit
[[ $footer_file == .footer.html ]] && \
echo "Please check your configuration. '.footer.html' is not a valid value for the setting 'footer_file'" && \
[[ $footer_file == .footer.html ]] &&
echo "Please check your configuration. '.footer.html' is not a valid value for the setting 'footer_file'" &&
exit
}
}

View File

@ -8,19 +8,17 @@
#
# 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
declare non_blogpost_files
declare index_file
declare archive_index
declare gophermap
declare gemini_index
declare tags_index
declare footer_file
declare header_file
declare prefix_tags
declare html_exclude
is_boilerplate_file() {
return 1 ### Ugly Hack to Temporally disable the verification
declare non_blogpost_files
declare index_file
declare archive_index
declare gophermap
declare gemini_index
declare tags_index
declare footer_file
declare header_file
declare prefix_tags
declare html_exclude
name=${1#./}
# First check against user-defined non-blogpost pages
for item in "${non_blogpost_files[@]}"; do
@ -28,12 +26,14 @@ is_boilerplate_file() {
done
case $name in
( "$index_file" | "$archive_index" | "$gophermap" | "$gemini_index" | "$tags_index" | "$footer_file" | "$header_file" | "$prefix_tags"* )
return 0 ;;
( * ) # Check for excluded
for excl in "${html_exclude[@]}"; do
[[ $name == "$excl" ]] && return 0
done
return 1 ;;
"$index_file" | "$archive_index" | "$gophermap" | "$gemini_index" | "$tags_index" | "$footer_file" | "$header_file" | "$prefix_tags"*)
return 0
;;
*) # Check for excluded
for excl in "${html_exclude[@]}"; do
[[ $name == "$excl" ]] && return 0
done
return 1
;;
esac
}
}

View File

@ -3,13 +3,15 @@
# Displays a list of the tags
#
# $2 if "-n", tags will be sorted by number of posts
declare prefix_tags
declare template_tags_posts_singular
declare template_tags_posts
list_tags() {
declare prefix_tags
declare template_tags_posts_singular
declare template_tags_posts
if [[ $2 == -n ]]; then do_sort=1; else do_sort=0; fi
if ls "./${prefix_tags}"*.html > /dev/null; then
if ls "./${prefix_tags}"*.html >/dev/null; then
echo "No posts yet. Use 'bb.sh post' to create one" && return
fi
@ -24,9 +26,9 @@ list_tags() {
lines+=$line\\n
done
if (( do_sort == 1 )); then
if ((do_sort == 1)); then
echo -e "$lines" | column -t -s "#" | sort -nrk 2
else
echo -e "$lines" | column -t -s "#"
echo -e "$lines" | column -t -s "#"
fi
}

View File

@ -1,7 +1,9 @@
#!/usr/bin/env bash
declare gemini_index
make_gemini() {
declare gemini_index
return
if [ ! -d "${HOME}/public_gemini" ]; then
printf "Creating ~/public_gemini\\n"
mkdir "${HOME}/public_gemini"
@ -12,7 +14,7 @@ make_gemini() {
fi
if [ ! -f "${HOME}/public_gemini/blog/$gemini_index" ]; then
cat <<- 'EOF' > "${HOME}/public_gemini/blog/${gemini_index}"
cat <<-'EOF' >"${HOME}/public_gemini/blog/${gemini_index}"
#!/usr/bin/env sh
printf "20 text/gemini\r\n"
printf "my bashblog posts\r\n"
@ -24,4 +26,4 @@ make_gemini() {
EOF
chmod +x "${HOME}/public_gemini/blog/${gemini_index}"
fi
}
}

View File

@ -1,7 +1,9 @@
#!/usr/bin/env bash
declare gophermap
make_gophermap() {
declare gophermap
return
if [ ! -d "${HOME}/public_gopher" ]; then
printf "Creating gopher hole\\n"
mkdir "${HOME}/public_gopher"
@ -12,7 +14,7 @@ make_gophermap() {
fi
if [ ! -f "${HOME}/public_gopher/blog/$gophermap" ]; then
cat <<- 'EOF' > "${HOME}/public_html/blog/${gophermap}"
cat <<-'EOF' >"${HOME}/public_html/blog/${gophermap}"
#!/usr/bin/env sh
printf "my bashblog posts\n"
user=$(stat -c '%U' .)
@ -24,4 +26,4 @@ EOF
chmod +x "${HOME}/public_html/blog/${gophermap}"
fi
chmod 644 "./*.md"
}
}

12
lib/make_html.sh Normal file
View File

@ -0,0 +1,12 @@
#!/usr/bin/env bash
# Parse a Markdown file into HTML and return the generated file
declare md2html_bin
make_html() {
out=${1%.md}.html
while [[ -f $out ]]; do
out=${out%.html}.$RANDOM.html
done
eval "$md2html_bin" "$1" >"$out"
echo "$out"
}

View File

@ -1,15 +1,16 @@
#!/usr/bin/env bash
# Generate the feed file
declare blog_feed
declare date_format_full
declare global_title
declare global_url
declare global_description
declare index_file
declare number_of_feed_articles
declare cut_do
make_rss() {
declare blog_feed
declare date_format_full
declare global_title
declare global_url
declare global_description
declare index_file
declare number_of_feed_articles
declare cut_do
echo -n "Making RSS "
rssfile=$blog_feed.$RANDOM
@ -17,8 +18,8 @@ make_rss() {
{
pubdate=$(LC_ALL=C date +"$date_format_full")
echo '<?xml version="1.0" encoding="UTF-8" ?>'
echo '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">'
echo '<?xml version="1.0" encoding="UTF-8" ?>'
echo '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">'
echo "<channel><title>$global_title</title><link>$global_url/$index_file</link>"
echo "<description>$global_description</description><language>en</language>"
echo "<lastBuildDate>$pubdate</lastBuildDate>"
@ -30,16 +31,16 @@ make_rss() {
is_boilerplate_file "$i" && continue
((n >= number_of_feed_articles)) && break # max 10 items
echo -n "." 1>&3
echo '<item><title>'
echo '<item><title>'
get_post_title "$i"
echo '</title><description><![CDATA['
echo '</title><description><![CDATA['
get_html_file_content 'text' 'entry' "$cut_do" <"$i"
echo "]]></description><link>$global_url/${i#./}</link>"
echo "<guid>$global_url/$i</guid>"
echo "<dc:creator>$(get_post_author "$i")</dc:creator>"
echo "]]></description><link>$global_url/${i#./}</link>"
echo "<guid>$global_url/$i</guid>"
echo "<dc:creator>$(get_post_author "$i")</dc:creator>"
echo "<pubDate>$(LC_ALL=C date -r "$i" +"$date_format_full")</pubDate></item>"
n=$(( n + 1 ))
n=$((n + 1))
done < <(ls -t ./*.html)
echo '</channel></rss>'
@ -48,4 +49,4 @@ make_rss() {
mv "$rssfile" "$blog_feed"
chmod 644 "$blog_feed"
}
}

View File

@ -1,4 +1,4 @@
#!/bin/awk -f
#!/usr/bin/awk -f
#
# by: Josemar Lohn <j@lo.hn>
# lo.hn on www/gemini/gopher

View File

@ -1,13 +0,0 @@
#!/usr/bin/env bash
# Parse a Markdown file into HTML and return the generated file
declare markdown_bin
mrkdwn() {
out=${1%.md}.html
while [[ -f $out ]]
do
out=${out%.md}.$RANDOM.html
done
$markdown_bin "$1" > "$out"
echo "$out"
}

View File

@ -8,11 +8,13 @@
# note that although timestamp is optional, something must be provided at its
# place if destination file name is provided, i.e:
# parse_file source.txt "" destination.html
declare convert_filename
declare template_tags_line_header
declare prefix_tags
declare global_author
parse_file() {
declare convert_filename
declare template_tags_line_header
declare prefix_tags
declare global_author
# Read for the title and check that the filename is ok
title=""
while IFS='' read -r line; do
@ -36,18 +38,18 @@ parse_file() {
# Parse possible tags
elif [[ $line == "<p>$template_tags_line_header"* ]]; then
tags=$(echo "$line" | cut -d ":" -f 2- | sed -e 's/<\/p>//g' -e 's/^ *//' -e 's/ *$//' -e 's/, /,/g')
IFS=, read -r -a array <<< "$tags"
IFS=, read -r -a array <<<"$tags"
echo -n "<p>$template_tags_line_header " >> "$content"
echo -n "<p>$template_tags_line_header " >>"$content"
for item in "${array[@]}"; do
echo -n "<a href='$prefix_tags$item.html'>$item</a>, "
done | sed 's/, $/<\/p>/g' >> "$content"
done | sed 's/, $/<\/p>/g' >>"$content"
else
echo "$line" >> "$content"
echo "$line" >>"$content"
fi
done < "$1"
done <"$1"
# Create the actual html page
create_html_page "$content" "$filename" no "$title" "$2" "$global_author"
rm "$content"
}
}

View File

@ -3,9 +3,12 @@
# Finds all posts referenced in a number of tags.
# Arguments are tags
# Prints one line with space-separated tags to stdout
declare prefix_tags
posts_with_tags() {
(($# < 1)) && return
set -- "${@/#/$prefix_tags}"
set -- "${@/%/.html}"
sed -n '/^<h3><a class="ablack" href="[^"]*">/{s/.*href="\([^"]*\)">.*/\1/;p;}' "$@" 2> /dev/null
}
sed -n '/^<h3><a class="ablack" href="[^"]*">/{s/.*href="\([^"]*\)">.*/\1/;p;}' "$@" 2>/dev/null
}

View File

@ -2,14 +2,17 @@
# Regenerates all the single post entries, keeping the post content but modifying
# the title, html structure, etc
declare date_inpost
declare date_format_full
declare date_format_timestamp
rebuild_all_entries() {
declare date_inpost
declare date_format_full
declare date_format_timestamp
echo -n "Rebuilding all entries "
for i in ./*.html; do
is_boilerplate_file "$i" && continue;
is_boilerplate_file "$i" && continue
contentfile=.tmp.$RANDOM
while [[ -f $contentfile ]]; do contentfile=.tmp.$RANDOM; done
@ -17,7 +20,7 @@ rebuild_all_entries() {
# Get the title and entry, and rebuild the html structure from scratch (divs, title, description...)
title=$(get_post_title "$i")
get_html_file_content 'text' 'text' <"$i" >> "$contentfile"
get_html_file_content 'text' 'text' <"$i" >>"$contentfile"
# Read timestamp from post, if present, and sync file timestamp
timestamp=$(awk '/<!-- '"$date_inpost"': .+ -->/ { print }' "$i" | cut -d '#' -f 2)
@ -34,4 +37,4 @@ rebuild_all_entries() {
rm "$contentfile"
done
echo ""
}
}

View File

@ -1,25 +1,27 @@
#!/usr/bin/env bash
# Generate the index.html with the content of the latest posts
declare index_file
declare number_of_index_articles
declare cut_do
declare cut_line
declare template_read_more
declare template_archive
declare template_subscribe
declare template_tags_title
declare blog_feed
declare global_author
declare global_feedburner
declare global_title
declare archive_index
declare tags_index
rebuild_index() {
declare index_file
declare number_of_index_articles
declare cut_do
declare cut_line
declare template_read_more
declare template_archive
declare template_subscribe
declare template_tags_title
declare blog_feed
declare global_author
declare global_feedburner
declare global_title
declare archive_index
declare tags_index
echo -n "Rebuilding the index "
newindexfile=$index_file.$RANDOM
contentfile=$newindexfile.content
while [[ -f $newindexfile ]]; do
while [[ -f $newindexfile ]]; do
newindexfile=$index_file.$RANDOM
contentfile=$newindexfile.content
done
@ -28,7 +30,7 @@ rebuild_index() {
{
n=0
while IFS='' read -r i; do
is_boilerplate_file "$i" && continue;
is_boilerplate_file "$i" && continue
if ((n >= number_of_index_articles)); then break; fi
if [[ -n $cut_do ]]; then
get_html_file_content 'entry' 'entry' 'cut' <"$i" | awk "/$cut_line/ { print \"<p class=\\\"readmore\\\"><a href=\\\"$i\\\">$template_read_more</a></p>\" ; next } 1"
@ -36,7 +38,7 @@ rebuild_index() {
get_html_file_content 'entry' 'entry' <"$i"
fi
echo -n "." 1>&3
n=$(( n + 1 ))
n=$((n + 1))
done < <(ls -t ./*.html) # sort by date, newest first
feed=$blog_feed
@ -50,4 +52,4 @@ rebuild_index() {
rm "$contentfile"
mv "$newindexfile" "$index_file"
chmod 644 "$index_file"
}
}

View File

@ -9,14 +9,16 @@
# example:
# rebuild_tags "one_post.html another_article.html" "example-tag another-tag"
# mind the quotes!
declare prefix_tags
declare cut_do
declare cut_line
declare template_read_more
declare template_tag_title
declare global_title
declare global_author
rebuild_tags() {
declare prefix_tags
declare cut_do
declare cut_line
declare template_read_more
declare template_tag_title
declare global_title
declare global_author
if (($# < 2)); then
# will process all files and tags
files=$(ls -t ./*.html)
@ -31,10 +33,10 @@ rebuild_tags() {
echo -n "Rebuilding tag pages "
#n=0
if [[ -n $all_tags ]]; then
rm ./"$prefix_tags"*.html &> /dev/null
rm ./"$prefix_tags"*.html &>/dev/null
else
for i in $tags; do
rm "./$prefix_tags$i.html" &> /dev/null
rm "./$prefix_tags$i.html" &>/dev/null
done
fi
# First we will process all files and create temporal tag files
@ -42,7 +44,7 @@ rebuild_tags() {
tmpfile=tmp.$RANDOM
while [[ -f $tmpfile ]]; do tmpfile=tmp.$RANDOM; done
while IFS='' read -r i; do
is_boilerplate_file "$i" && continue;
is_boilerplate_file "$i" && continue
echo -n "."
if [[ -n $cut_do ]]; then
get_html_file_content 'entry' 'entry' 'cut' <"$i" | awk "/$cut_line/ { print \"<p class=\\\"readmore\\\"><a href=\\\"$i\\\">$template_read_more</a></p>\" ; next } 1"
@ -51,10 +53,10 @@ rebuild_tags() {
fi >"$tmpfile"
for tag in $(tags_in_post "$i"); do
if [[ -n $all_tags || " $tags " == *" $tag "* ]]; then
cat "$tmpfile" >> "$prefix_tags$tag".tmp.html
cat "$tmpfile" >>"$prefix_tags$tag".tmp.html
fi
done
done <<< "$files"
done <<<"$files"
rm "$tmpfile"
# Now generate the tag files with headers, footers, etc
while IFS='' read -r i; do
@ -64,4 +66,4 @@ rebuild_tags() {
rm "$i"
done < <(ls -t ./"$prefix_tags"*.tmp.html 2>/dev/null)
echo
}
}

View File

@ -1,15 +1,16 @@
#!/usr/bin/env bash
# Delete all generated content, leaving only this script
reset() {
echo "Are you sure you want to delete all blog entries? Please write \"Yes, I am!\" "
read -r line
if [[ $line == "Yes, I am!" ]]; then
rm .*.html ./*.html ./*.css ./*.rss &> /dev/null
rm .*.html ./*.html ./*.css ./*.rss &>/dev/null
echo
echo "Deleted all posts, stylesheets and feeds."
echo "Kept your old '.backup.tar.gz' just in case, please delete it manually if needed."
else
echo "Phew! You dodged a bullet there. Nothing was modified."
fi
}
}

View File

@ -3,7 +3,9 @@
# Finds all tags referenced in one post.
# Accepts either filename as first argument, or post content at stdin
# Prints one line with space-separated tags to stdout
declare template_tags_line_header
tags_in_post() {
declare template_tags_line_header
sed -n "/^<p>$template_tags_line_header/{s/^<p>$template_tags_line_header//;s/<[^>]*>//g;s/[ ,]\+/ /g;p;}" "$1" | tr ', ' ' '
}
}

View File

@ -1,16 +0,0 @@
#!/usr/bin/env bash
# Test if the markdown script is working correctly
test_markdown() {
declare markdown_bin
if [[ -n $markdown_bin ]]; then
local m1; m1=$("$markdown_bin" <<< "$'line 1\n\nline 2'")
local m2; m2=$("$markdown_bin" <<< "$'line 1\n\nline 2'")
local c1=$'<p>line 1</p>\n\n<p>line 2</p>'
local c2=$'<p>line 1</p>\n<p>line 2</p>'
# shellcheck disable=SC22350 # must enforce order of operations
[[ "$m1" == "$c1" ]] || [[ "$m2" == "$c2" ]]
else
return 1
fi
}

View File

@ -4,20 +4,23 @@
#
# $1 the post file
# $2 the title
declare global_twitter_username
declare template_tags_line_header
declare global_url
declare global_twitter_cookieless
declare template_twitter_button
declare template_twitter_comment
declare template_comments
twitter_card() {
declare global_twitter_username
declare template_tags_line_header
declare global_url
declare global_twitter_cookieless
declare template_twitter_button
declare template_twitter_comment
declare template_comments
[[ -z $global_twitter_username ]] && return
echo "<meta name='twitter:card' content='summary'>"
echo "<meta name='twitter:site' content='@$global_twitter_username'>"
echo "<meta name='twitter:title' content='$2'>" # Twitter truncates at 70 char
description=$(grep -v "^<p>$template_tags_line_header" "$1" | sed -e 's/<[^>]*>//g' | head -c 250 | tr '\n' ' ' | sed "s/\"/'/g")
description=$(grep -v "^<p>$template_tags_line_header" "$1" | sed -e 's/<[^>]*>//g' | head -c 250 | tr '\n' ' ' | sed "s/\"/'/g")
echo "<meta name='twitter:description' content=\"$description\">"
image=$(sed -n 's/.*<img.*src="\([^"]*\)".*/\1/p' "$1" | head -n 1) # First image is fine
[[ -z $image ]] && return
@ -38,13 +41,13 @@ twitter() {
echo "<p id='twitter'><a href='http://twitter.com/intent/tweet?url=$1&text=$template_twitter_comment&via=$global_twitter_username'>$template_comments $template_twitter_button</a> "
echo "<a href='$search_engine""$1'><span id='count-$id'></span></a>&nbsp;</p>"
return;
else
echo "<p id='twitter'>$template_comments&nbsp;";
return
else
echo "<p id='twitter'>$template_comments&nbsp;"
fi
echo "<a href=\"https://twitter.com/share\" class=\"twitter-share-button\" data-text=\"$template_twitter_comment\" data-url=\"$1\""
echo " data-via=\"$global_twitter_username\""
echo ">$template_twitter_button</a> <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=\"//platform.twitter.com/widgets.js\";fjs.parentNode.insertBefore(js,fjs);}}(document,\"script\",\"twitter-wjs\");</script>"
echo "</p>"
}
}

View File

@ -1,8 +1,10 @@
#!/usr/bin/env bash
# Displays the help
declare global_software_name
declare global_software_version
# Displays the help
usage() {
echo "$global_software_name $global_software_version"
echo "usage: $0 command [filename]"

View File

@ -2,26 +2,28 @@
# 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() {
f=$2
extension=${f##*.}
if [[ $extension != md ]]; then
f=${f}.md
fi
if [[ -n $f ]]; thenq
if [[ -n $f ]]; then
extension=${f##*.}
if [[ $extension != md ]]; then
f=${f}.md
fi
if [[ -f $f ]]; then
echo "The file $f doesn't exist"
delete_includes
exit
fi
else
TMPFILE=.entry-$RANDOM.$fmt
echo -e "Title on this line\n" >> "$TMPFILE"
cat << EOF >> "$TMPFILE"
TMPFILE=.entry-$RANDOM.md
echo -e "Title on this line\n" >>"$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.
@ -37,12 +39,10 @@ EOF
$EDITOR "$TMPFILE"
html_from_md=$(mrkdwn "$TMPFILE")
parse_file "$html_from_md"
html_from_md=$(make_html "$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"
@ -65,7 +65,7 @@ EOF
[[ -n $convert_filename ]] && title=$(echo "$title" | eval "$convert_filename")
[[ -n $title ]] || title=$RANDOM
draft=drafts/$title.$fmt
draft=drafts/$title.md
mv "$TMPFILE" "$draft"
chmod 600 "$draft"
rm "$filename"
@ -84,4 +84,4 @@ EOF
relevant_posts="$(posts_with_tags $relevant_tags) $filename"
rebuild_tags "$relevant_posts" "$relevant_tags"
fi
}
}

View File

@ -1,12 +1,18 @@
#!/usr/bin/env bash
# shellcheck disable=SC1091
# shellcheck disable=SC2034
# TildeLog, a not-so-simple blog/gemlog/phlog system made for tilde.team
# By Josemar Lohn <j@lo.hn>
#
#
# Heavily based on BashBlog, by Carlos Fenollosa <carlos.fenollosa@gmail.com>
### BEGIN SOURCEFILES -> DO NOT REMOVE THIS LINE
md2html_awk=$(<lib/md2html.awk)
md2gemini_awk=$(<lib/md2gemini.awk)
md2gopher_awk=$(<lib/md2gopher.awk)
### BEGIN SOURCEFILES -> DO NOT REMOVE THIS LINE
source ./lib/all_posts.sh
source ./lib/all_tags.sh
source ./lib/create_css.sh
@ -26,7 +32,7 @@ source ./lib/list_tags.sh
source ./lib/make_gemini.sh
source ./lib/make_gophermap.sh
source ./lib/make_rss.sh
source ./lib/mrkdwn.sh
source ./lib/make_html.sh
source ./lib/parse_file.sh
source ./lib/posts_with_tags.sh
source ./lib/rebuild_all_entries.sh
@ -34,7 +40,6 @@ source ./lib/rebuild_index.sh
source ./lib/rebuild_tags.sh
source ./lib/reset.sh
source ./lib/tags_in_post.sh
source ./lib/test_markdown.sh
source ./lib/twitter_card.sh
source ./lib/usage.sh
source ./lib/write_entry.sh
@ -47,4 +52,4 @@ source ./lib/write_entry.sh
#
do_main "$@"
# vim: set shiftwidth=4 tabstop=4 expandtab:
# vim: set shiftwidth=4 tabstop=4 expandtab: