FIX generation from markdown (merge)

This commit is contained in:
Josemar Lohn 2021-03-12 09:21:43 +00:00
commit 3ed87d6bc6
No known key found for this signature in database
GPG Key ID: BE6B8FD676E471E4
29 changed files with 293 additions and 220 deletions

View File

@ -1,11 +1,14 @@
#!/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 +22,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 +46,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"
@ -83,4 +83,4 @@ do_main() {
make_gemini
echo 'deleting includes'
delete_includes
}
}

View File

@ -22,7 +22,7 @@ edit() {
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
@ -30,21 +30,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

@ -19,4 +19,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

@ -26,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

@ -24,9 +24,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

@ -12,7 +12,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 +24,4 @@ make_gemini() {
EOF
chmod +x "${HOME}/public_gemini/blog/${gemini_index}"
fi
}
}

View File

@ -11,7 +11,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' .)
@ -23,4 +23,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

@ -18,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>"
@ -31,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>'
@ -49,4 +49,4 @@ make_rss() {
mv "$rssfile" "$blog_feed"
chmod 644 "$blog_feed"
}
}

View File

@ -22,40 +22,40 @@ function oprint(t){
}
# https://unix.stackexchange.com/a/94751
function centralize(t,c){
L = col - c - length(t);
function centralize(text, border , margin){
L = col - border - margin - length(text);
#print("====" length(t) "=====" t "=====\n")
for(i=1; i<=int(L/2); i++)
t = " "t;
for(i=1; i<=int(L/2+.5); i++)
t = t " "
return t
for(i=1; i<=(int(L/2) + margin) ; i++)
text = " "text;
for(i=1; i<=int(L/2+.5) ; i++)
text = text " "
return text
}
# function from https://unix.stackexchange.com/a/282338
function justify(t,i,nbchar,nbspc,spaces,spcpf,r){
$0=t
if (NF <= 1) { return t }
function justify(text, margin, j, nbchar, wreturn, spcpf, spaces, nbspc){
$0=text
if (NF <= 1) { return text }
else {
nbchar = 0
for (i = 1; i <= NF; i++) {
nbchar += length($i)
}
nbspc = col - nbchar
nbspc = (col - margin) - nbchar - 1
spcpf = int(nbspc / (NF - 1))
for (i = 1; i < NF; i++) {
r = r $i
wreturn = wreturn $i
spaces = (NF == 2 || i == NF - 1) ? nbspc : spcpf
if (spaces < 1) spaces = 1
for (j = 0; j < spaces; j++) {
r = r " "
wreturn = wreturn " "
}
nbspc -= spaces
}
r = r $NF
wreturn = wreturn $NF
}
return r
return wreturn
}
function subref(id){
@ -104,6 +104,7 @@ function nextil(t) {
}
ilcode = !ilcode;
return t1 tag nextil(t2);
return t1 tag nextil(t2);
}
if(tag == "<"){
# Autolinks
@ -240,7 +241,8 @@ function nextil(t) {
else
stag[++ns] = ntag;
tag = "<" tag ">";
return t1 tag nextil(t2);
#return t1 tag nextil(t2);
return t1 nextil(t2);
}
}
@ -253,22 +255,29 @@ function inline(t) {
}
#https://unix.stackexchange.com/a/337656
function wrap(t,align,q,y,z,final) {
function wrap(t,align) {
final=""
z=""
y=0
margin_spaces=""
localmargin = blockquote * 5
for(c = 0; c < localmargin; c++)
margin_spaces = " " margin_spaces
while (t)
{
q = match(t, / |$/); y += q
if (y > col) {
if (y > col - localmargin) {
#print "|"localmargin"|"blockquote"|"nnl"|"
if (align != 0)
{
if (align=="c")
#print "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
final = final centralize(z) RS
if (align=="c")
final = final margin_spaces centralize(z,localmargin) RS
if (align=="j")
final = final justify(z) RS
final = final margin_spaces justify(z,localmargin) RS
}
else
{
final = final z RS
final = final z RS
}
y = q - 1
z = ""
@ -279,10 +288,10 @@ function wrap(t,align,q,y,z,final) {
}
if (align=="c")
{
final = final centralize(z)
final = final margin_spaces centralize(z, localmargin)
}
else {
final = final z
final = final margin_spaces z
}
return final
}
@ -309,10 +318,12 @@ BEGIN {
html = 0;
nl = 0;
nr = 0;
margin = 0;
otext = "";
text = "";
par = "p";
col=70;
listitem=0;
c=0; do { lineheader = "=" lineheader; c++ } while ( c < col )
c=0; do { lineheadersmall = "-" lineheadersmall; c++ } while ( c < col )
}
@ -347,38 +358,6 @@ BEGIN {
next;
}
# html
!html && /^<(address|blockquote|center|dir|div|dl|fieldset|form|h[1-6r]|\
isindex|menu|noframes|noscript|ol|p|pre|table|ul|!--)/ {
if(code)
oprint("</pre></code>");
for(; !text && block[nl] == "blockquote"; nl--)
oprint("</blockquote>");
match($0, /^<(address|blockquote|center|dir|div|dl|fieldset|form|h[1-6r]|\
isindex|menu|noframes|noscript|ol|p|pre|table|ul|!--)/);
htag = substr($0, 2, RLENGTH - 1);
if(!match($0, "(<\\/" htag ">)|((^<hr ?\\/?)|(--)>$)"))
html = 1;
if(html && match($0, /^<hr/))
hr = 1;
oprint($0);
next;
}
html && (/(^<\/(address|blockquote|center|dir|div|dl|fieldset|form|h[1-6r]|\
isindex|menu|noframes|noscript|ol|p|pre|table|ul).*)|(--)>$/ ||
(hr && />$/)) {
html = 0;
hr = 0;
oprint($0);
next;
}
html {
oprint($0);
next;
}
# List and quote blocks
# Remove indentation
@ -393,12 +372,13 @@ nnl < nl && !blank && text && ! /^ ? ? ?([*+-]|([0-9]+\.)+)( +| )/ { nnl = nl; }
{
while(sub(/^> /, ""))
nblock[++nnl] = "blockquote";
blockquote = nnl;
}
# Horizontal rules
{ hr = 0; }
(blank || (!text && !code)) && /^ ? ? ?([-*_][ ]*)([-*_][ ]*)([-*_][ ]*)+$/ {
if(code){
oprint("</pre></code>");
#oprint("</pre></code>");
code = 0;
}
blank = 0;
@ -415,12 +395,15 @@ block[nl] ~ /[ou]l/ && /^$/ {
sub(/^ ? ? ?[*+-]( +| )/, "");
nnl++;
nblock[nnl] = "ul";
listtype="ul";
newli = 1;
}
(nnl != nl || !text || block[nl] ~ /[ou]l/) && /^ ? ? ?([0-9]+\.)+( +| )/ {
sub(/^ ? ? ?([0-9]+\.)+( +| )/, "");
nnl++;
nblock[nnl] = "ol";
listtype="ol";
listitem++
newli = 1;
}
newli {
@ -429,7 +412,12 @@ newli {
blank = 0;
printp(par);
if(nnl == nl && block[nl] == nblock[nl])
oprint("</li><li>");
#oprint("</li><li>");
if(listtype == "ul")
printf "- ";
if(listtype == "ol")
printf "%s - ", listitem;
}
blank && ! /^$/ {
if(match(block[nnl], /[ou]l/) && !par)
@ -442,26 +430,36 @@ blank && ! /^$/ {
# Close old blocks and open new ones
nnl != nl || nblock[nl] != block[nl] {
if(code){
oprint("</pre></code>");
#oprint("</pre></code>");
code = 0;
}
printp(par);
b = (nnl > nl) ? nblock[nnl] : block[nnl];
par = (match(b, /[ou]l/)) ? "" : "p";
}
nnl < nl || (nnl == nl && nblock[nl] != block[nl]) {
for(; nl > nnl || (nnl == nl && pblock[nl] != block[nl]); nl--){
if(match(block[nl], /[ou]l/))
oprint("</li>");
oprint("</" block[nl] ">");
#oprint("</li>");
printf ""
#oprint("</" block[nl] ">");
#if(listtype == "ol")
# listitem = 0;
}
}
nnl > nl {
for(; nl < nnl; nl++){
block[nl + 1] = nblock[nl + 1];
oprint("<" block[nl + 1] ">");
#oprint("<" block[nl + 1] ">");
if(match(block[nl + 1], /[ou]l/))
oprint("<li>");
#oprint("<li>");
if(listtype == "ul")
printf "- ";
#if(listtype == "ol")
#printf "%s - ", listitem;
#listitem=0
}
}
hr {
@ -476,19 +474,20 @@ code && /^$/ {
blank = 1;
next;
}
!text && sub(/^( | )/, "") {
if(blanK)
oprint("");
blank = 0;
if(!code)
oprint("<code><pre>");
#if(!code)
# oprint("<code><pre>");
code = 1;
$0 = eschtml($0);
oprint($0);
next;
}
code {
oprint("</pre></code>");
#oprint("</pre></code>");
code = 0;
}
@ -512,7 +511,7 @@ text && /^-+$/ {printp("h2"); next;}
next;
}
if (n == 3) {
oprint(text centralize($0) "\n" lineheadersmall "\n")
oprint("\n" text centralize($0) "\n" lineheadersmall "\n")
next;
}
if (n > 3) {
@ -539,15 +538,16 @@ function alen(a, ix, k) {
END {
if(code){
oprint("</pre></code>");
# oprint("</pre></code>");
code = 0;
}
printp(par);
for(; nl > 0; nl--){
if(match(block[nl], /[ou]l/))
oprint("</li>");
oprint("</" block[nl] ">");
}
#printp(par);
#for(; nl > 0; nl--){
# if(match(block[nl], /[ou]l/))
# listitem=0
#oprint("</li>");
# oprint("</" block[nl] ">");
#}
gsub(/<<[^"]*/, "", otext);
print(otext);

View File

@ -1,4 +1,4 @@
#!/bin/awk -f
#!/usr/bin/awk -f
#
# by: Jesus Galan (yiyus) 2009
#

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

@ -36,18 +36,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

@ -8,5 +8,5 @@ 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

@ -58,4 +58,4 @@ rebuild_all_entries() {
#rm "$contentfile"
done
echo ""
}
}

View File

@ -20,7 +20,7 @@ rebuild_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
@ -29,7 +29,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"
@ -37,7 +37,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
@ -51,4 +51,4 @@ rebuild_index() {
rm "$contentfile"
mv "$newindexfile" "$index_file"
chmod 644 "$index_file"
}
}

View File

@ -16,8 +16,8 @@ declare template_read_more
declare template_tag_title
declare global_title
declare global_author
rebuild_tags() {
rebuild_tags() {
if (($# < 2)); then
# will process all files and tags
files=$(ls -t ./*.html)
@ -32,10 +32,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
@ -43,7 +43,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"
@ -52,10 +52,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
@ -65,4 +65,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

@ -6,4 +6,4 @@
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,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,9 +2,11 @@
# 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
@ -14,10 +16,9 @@ write_entry() {
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.
@ -33,12 +34,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"
@ -61,7 +60,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"
@ -80,4 +79,4 @@ EOF
relevant_posts="$(posts_with_tags $relevant_tags) $filename"
rebuild_tags "$relevant_posts" "$relevant_tags"
fi
}
}

83
spec/test.md Normal file
View File

@ -0,0 +1,83 @@
# A First Level Header
## A Second Level Header
Now is the time for all good men to come to
the aid of their country. This is just a
regular paragraph.
The quick brown fox jumped over the lazy
dog's back.
### Header 3
> This is a blockquote.
>
> This is the second paragraph in the blockquote. This is the second paragraph in the blockquote. This is the second paragraph in the blockquote.
>
> This is a test
>
>> Blockcode level2
>>
>> level2
Some of these words *are emphasized*.
Some of these words _are emphasized also_.
Use two asterisks for **strong emphasis**.
Or, if you prefer, __use two underscores instead__.
* Candy.
* Gum.
* Booze.
1. Candy.
2. Gum.
3. Booze.
- Candy.
- Gum.
- Booze.
1. Red
2. Green
3. Blue
* A list item.
With multiple paragraphs.
* Another item in the list.
This is an [example link](http://example.com/).
This is an [example link](http://example.com/ "With a Title").
I get 10 times more traffic from [Google][1] than from
[Yahoo][2] or [MSN][3].
[1]: http://google.com/ "Google"
[2]: http://search.yahoo.com/ "Yahoo Search"
[3]: http://search.msn.com/ "MSN Search"
I start my morning with a cup of coffee and
[The New York Times][NY Times].
[ny times]: http://www.nytimes.com/
![alt text](/path/to/img.jpg "Title")
![alt text][id]
[id]: /path/to/img.jpg "Title"
I strongly recommend against using any `<blink>` tags.
I wish SmartyPants used named entities like `&mdash;`
instead of decimal-encoded entites like `&#8212;`.

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: