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,6 +1,7 @@
#!/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

View File

@ -23,7 +23,7 @@ do_main() {
# 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
EDITOR=vim
# Check for validity of argument
[[ $1 != "reset" && $1 != "post" && $1 != "rebuild" && $1 != "list" && $1 != "edit" && $1 != "delete" && $1 != "tags" ]] &&

View File

@ -12,12 +12,14 @@
# "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)
edit() {
declare date_format_full
declare date_format_timestamp
declare template_tags_line_header
declare prefix_tags
[[ ! -f "${1%%.*}.html" ]] && \
edit() {
[[ ! -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
@ -29,13 +31,9 @@ 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

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
get_html_file_content() {
declare cut_line cut_tags
declare template_tags_line_header
get_html_file_content() {
awk "/<!-- $1 begin -->/, /<!-- $2 end -->/{
if (!/<!-- $1 begin -->/ && !/<!-- $2 end -->/) print
if (\"$3\" == \"cut\" && /$cut_line/){

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,7 +13,6 @@ 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
@ -32,7 +31,6 @@ 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,
# 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_"
@ -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,9 +8,6 @@
#
# 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
@ -21,6 +18,7 @@ is_boilerplate_file() {
declare header_file
declare prefix_tags
declare html_exclude
is_boilerplate_file() {
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
"$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 ;;
return 1
;;
esac
}

View File

@ -3,10 +3,12 @@
# Displays a list of the tags
#
# $2 if "-n", tags will be sorted by number of posts
list_tags() {
declare prefix_tags
declare template_tags_posts_singular
declare template_tags_posts
list_tags() {
if [[ $2 == -n ]]; then do_sort=1; else do_sort=0; fi
if ls "./${prefix_tags}"*.html >/dev/null; then

View File

@ -1,7 +1,9 @@
#!/usr/bin/env bash
make_gemini() {
declare gemini_index
make_gemini() {
return
if [ ! -d "${HOME}/public_gemini" ]; then
printf "Creating ~/public_gemini\\n"
mkdir "${HOME}/public_gemini"

View File

@ -1,7 +1,9 @@
#!/usr/bin/env bash
make_gophermap() {
declare gophermap
make_gophermap() {
return
if [ ! -d "${HOME}/public_gopher" ]; then
printf "Creating gopher hole\\n"
mkdir "${HOME}/public_gopher"

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,7 +1,6 @@
#!/usr/bin/env bash
# Generate the feed file
make_rss() {
declare blog_feed
declare date_format_full
declare global_title
@ -10,6 +9,8 @@ make_rss() {
declare index_file
declare number_of_feed_articles
declare cut_do
make_rss() {
echo -n "Making RSS "
rssfile=$blog_feed.$RANDOM

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
parse_file() {
declare convert_filename
declare template_tags_line_header
declare prefix_tags
declare global_author
parse_file() {
# Read for the title and check that the filename is ok
title=""
while IFS='' read -r line; do

View File

@ -3,6 +3,9 @@
# 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}"

View File

@ -2,14 +2,17 @@
# Regenerates all the single post entries, keeping the post content but modifying
# the title, html structure, etc
rebuild_all_entries() {
declare date_inpost
declare date_format_full
declare date_format_timestamp
rebuild_all_entries() {
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

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
# Generate the index.html with the content of the latest posts
rebuild_index() {
declare index_file
declare number_of_index_articles
declare cut_do
@ -16,6 +16,8 @@ rebuild_index() {
declare global_title
declare archive_index
declare tags_index
rebuild_index() {
echo -n "Rebuilding the index "
newindexfile=$index_file.$RANDOM
contentfile=$newindexfile.content
@ -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"

View File

@ -9,7 +9,7 @@
# example:
# rebuild_tags "one_post.html another_article.html" "example-tag another-tag"
# mind the quotes!
rebuild_tags() {
declare prefix_tags
declare cut_do
declare cut_line
@ -17,6 +17,8 @@ rebuild_tags() {
declare template_tag_title
declare global_title
declare global_author
rebuild_tags() {
if (($# < 2)); then
# will process all files and tags
files=$(ls -t ./*.html)
@ -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"

View File

@ -1,6 +1,7 @@
#!/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

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
tags_in_post() {
declare template_tags_line_header
tags_in_post() {
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,7 +4,7 @@
#
# $1 the post file
# $2 the title
twitter_card() {
declare global_twitter_username
declare template_tags_line_header
declare global_url
@ -12,6 +12,9 @@ twitter_card() {
declare template_twitter_button
declare template_twitter_comment
declare template_comments
twitter_card() {
[[ -z $global_twitter_username ]] && return
echo "<meta name='twitter:card' content='summary'>"
@ -38,9 +41,9 @@ 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;
return
else
echo "<p id='twitter'>$template_comments&nbsp;";
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\""

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,25 +2,27 @@
# 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
if [[ -n $f ]]; then
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
else
TMPFILE=.entry-$RANDOM.$fmt
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")
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"

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