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,10 +1,13 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Create the css file from scratch # Create the css file from scratch
declare css_include
create_css() { create_css() {
# To avoid overwriting manual changes. However it is recommended that # To avoid overwriting manual changes. However it is recommended that
# this function is modified if the user changes the blog.css file # this function is modified if the user changes the blog.css file
(( ${#css_include[@]} > 0 )) && return || css_include=('main.css' 'blog.css')
((${#css_include} > 0)) && return || css_include=('main.css' 'blog.css')
if [[ ! -f blog.css ]]; then if [[ ! -f blog.css ]]; then
# blog.css directives will be loaded after main.css and thus will prevail # blog.css directives will be loaded after main.css and thus will prevail
echo '#title{font-size: x-large;} echo '#title{font-size: x-large;}

View File

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

View File

@ -30,13 +30,9 @@ edit() {
filename=$1 filename=$1
else else
if [[ ${1##*.} == md ]]; then if [[ ${1##*.} == md ]]; then
if test_markdown; then
echo "Markdown is not working, please edit HTML file directly."
exit
fi
# editing markdown file # editing markdown file
$EDITOR "$1" $EDITOR "$1"
TMPFILE=$(mrkdwn "$1") TMPFILE=$(make_html "$1")
filename=${1%%.*}.html filename=${1%%.*}.html
else else
# Create the content file # Create the content file

View File

@ -5,5 +5,5 @@
# $1 the html file # $1 the html file
get_post_title() { 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 head -1 "$1"
} }

View File

@ -13,7 +13,6 @@ global_config=".tildelog"
global_variables() { global_variables() {
global_software_name="tildelog" global_software_name="tildelog"
global_software_version="0.1" global_software_version="0.1"
# Blog title # Blog title
global_title="my tildelog" global_title="my tildelog"
# The typical subtitle for each blog # 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 # CC by-nc-nd is a good starting point, you can change this to "&copy;" for Copyright
global_license="CC by-nc-nd" 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 # or change it to your own URL
global_feedburner="" global_feedburner=""
@ -73,8 +71,6 @@ global_variables() {
# Regexp matching the HTML line where to do the cut # Regexp matching the HTML line where to do the cut
# note that slash is regexp separator so you need to prepend it with backslash # note that slash is regexp separator so you need to prepend it with backslash
cut_line='<hr ?\/?>' 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 # prefix for tags/categories files
# please make sure that no other html file starts with this prefix # please make sure that no other html file starts with this prefix
prefix_tags="tag_" prefix_tags="tag_"
@ -149,17 +145,17 @@ global_variables() {
# Markdown location. Trying to autodetect by default. # Markdown location. Trying to autodetect by default.
# The invocation must support the signature 'markdown_bin in.md > out.html' # The invocation must support the signature 'markdown_bin in.md > out.html'
# shellcheck disable=SC2016
markdown_bin=$(which md2html.awk) md2html_bin='awk "$md2html_awk"'
} }
# Check for the validity of some variables # Check for the validity of some variables
# DO NOT EDIT THIS FUNCTION unless you know what you're doing # DO NOT EDIT THIS FUNCTION unless you know what you're doing
global_variables_check() { global_variables_check() {
[[ $header_file == .header.html ]] && \ [[ $header_file == .header.html ]] &&
echo "Please check your configuration. '.header.html' is not a valid value for the setting 'header_file'" && \ echo "Please check your configuration. '.header.html' is not a valid value for the setting 'header_file'" &&
exit exit
[[ $footer_file == .footer.html ]] && \ [[ $footer_file == .footer.html ]] &&
echo "Please check your configuration. '.footer.html' is not a valid value for the setting 'footer_file'" && \ echo "Please check your configuration. '.footer.html' is not a valid value for the setting 'footer_file'" &&
exit exit
} }

View File

@ -26,12 +26,14 @@ is_boilerplate_file() {
done done
case $name in case $name in
( "$index_file" | "$archive_index" | "$gophermap" | "$gemini_index" | "$tags_index" | "$footer_file" | "$header_file" | "$prefix_tags"* ) "$index_file" | "$archive_index" | "$gophermap" | "$gemini_index" | "$tags_index" | "$footer_file" | "$header_file" | "$prefix_tags"*)
return 0 ;; return 0
( * ) # Check for excluded ;;
*) # Check for excluded
for excl in "${html_exclude[@]}"; do for excl in "${html_exclude[@]}"; do
[[ $name == "$excl" ]] && return 0 [[ $name == "$excl" ]] && return 0
done done
return 1 ;; return 1
;;
esac esac
} }

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

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

View File

@ -1,4 +1,4 @@
#!/bin/awk -f #!/usr/bin/awk -f
# #
# by: Jesus Galan (yiyus) 2009 # 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

@ -29,7 +29,7 @@ rebuild_index() {
{ {
n=0 n=0
while IFS='' read -r i; do 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 >= number_of_index_articles)); then break; fi
if [[ -n $cut_do ]]; then 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" 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

@ -16,8 +16,8 @@ declare template_read_more
declare template_tag_title declare template_tag_title
declare global_title declare global_title
declare global_author declare global_author
rebuild_tags() {
rebuild_tags() {
if (($# < 2)); then if (($# < 2)); then
# will process all files and tags # will process all files and tags
files=$(ls -t ./*.html) files=$(ls -t ./*.html)
@ -43,7 +43,7 @@ rebuild_tags() {
tmpfile=tmp.$RANDOM tmpfile=tmp.$RANDOM
while [[ -f $tmpfile ]]; do tmpfile=tmp.$RANDOM; done while [[ -f $tmpfile ]]; do tmpfile=tmp.$RANDOM; done
while IFS='' read -r i; do while IFS='' read -r i; do
is_boilerplate_file "$i" && continue; is_boilerplate_file "$i" && continue
echo -n "." echo -n "."
if [[ -n $cut_do ]]; then 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" 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 #!/usr/bin/env bash
# Delete all generated content, leaving only this script # Delete all generated content, leaving only this script
reset() { reset() {
echo "Are you sure you want to delete all blog entries? Please write \"Yes, I am!\" " echo "Are you sure you want to delete all blog entries? Please write \"Yes, I am!\" "
read -r line read -r line

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 # $1 the post file
# $2 the title # $2 the title
twitter_card() {
declare global_twitter_username declare global_twitter_username
declare template_tags_line_header declare template_tags_line_header
declare global_url declare global_url
@ -12,6 +12,9 @@ twitter_card() {
declare template_twitter_button declare template_twitter_button
declare template_twitter_comment declare template_twitter_comment
declare template_comments declare template_comments
twitter_card() {
[[ -z $global_twitter_username ]] && return [[ -z $global_twitter_username ]] && return
echo "<meta name='twitter:card' content='summary'>" 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 "<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>" echo "<a href='$search_engine""$1'><span id='count-$id'></span></a>&nbsp;</p>"
return; return
else else
echo "<p id='twitter'>$template_comments&nbsp;"; echo "<p id='twitter'>$template_comments&nbsp;"
fi fi
echo "<a href=\"https://twitter.com/share\" class=\"twitter-share-button\" data-text=\"$template_twitter_comment\" data-url=\"$1\"" 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 #!/usr/bin/env bash
# Displays the help
declare global_software_name declare global_software_name
declare global_software_version declare global_software_version
# Displays the help
usage() { usage() {
echo "$global_software_name $global_software_version" echo "$global_software_name $global_software_version"
echo "usage: $0 command [filename]" echo "usage: $0 command [filename]"

View File

@ -2,9 +2,11 @@
# Manages the creation of the text file and the parsing to html file # Manages the creation of the text file and the parsing to html file
# also the drafts # also the drafts
declare template_tags_line_header declare template_tags_line_header
declare global_url declare global_url
declare convert_filename declare convert_filename
write_entry() { write_entry() {
f=$2 f=$2
if [[ -n $f ]]; then if [[ -n $f ]]; then
@ -14,9 +16,8 @@ write_entry() {
exit exit
fi fi
else else
TMPFILE=.entry-$RANDOM.$fmt TMPFILE=.entry-$RANDOM.md
echo -e "Title on this line\n" >>"$TMPFILE" echo -e "Title on this line\n" >>"$TMPFILE"
cat <<EOF >>"$TMPFILE" cat <<EOF >>"$TMPFILE"
The rest of the text file is a **Markdown** blog post. The process will continue The rest of the text file is a **Markdown** blog post. The process will continue
as soon as you exit your editor. as soon as you exit your editor.
@ -33,12 +34,10 @@ EOF
$EDITOR "$TMPFILE" $EDITOR "$TMPFILE"
html_from_md=$(mrkdwn "$TMPFILE") html_from_md=$(make_html "$TMPFILE")
parse_file "$html_from_md" parse_file "$html_from_md"
rm "$html_from_md" rm "$html_from_md"
chmod 644 "$filename" chmod 644 "$filename"
[[ -n $preview_url ]] || preview_url=$global_url [[ -n $preview_url ]] || preview_url=$global_url
echo "To preview the entry, open $preview_url/$filename in your browser" 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 $convert_filename ]] && title=$(echo "$title" | eval "$convert_filename")
[[ -n $title ]] || title=$RANDOM [[ -n $title ]] || title=$RANDOM
draft=drafts/$title.$fmt draft=drafts/$title.md
mv "$TMPFILE" "$draft" mv "$TMPFILE" "$draft"
chmod 600 "$draft" chmod 600 "$draft"
rm "$filename" rm "$filename"

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 #!/usr/bin/env bash
# shellcheck disable=SC1091
# shellcheck disable=SC2034
# TildeLog, a not-so-simple blog/gemlog/phlog system made for tilde.team # TildeLog, a not-so-simple blog/gemlog/phlog system made for tilde.team
# By Josemar Lohn <j@lo.hn> # By Josemar Lohn <j@lo.hn>
# #
# Heavily based on BashBlog, by Carlos Fenollosa <carlos.fenollosa@gmail.com> # 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_posts.sh
source ./lib/all_tags.sh source ./lib/all_tags.sh
source ./lib/create_css.sh source ./lib/create_css.sh
@ -26,7 +32,7 @@ source ./lib/list_tags.sh
source ./lib/make_gemini.sh source ./lib/make_gemini.sh
source ./lib/make_gophermap.sh source ./lib/make_gophermap.sh
source ./lib/make_rss.sh source ./lib/make_rss.sh
source ./lib/mrkdwn.sh source ./lib/make_html.sh
source ./lib/parse_file.sh source ./lib/parse_file.sh
source ./lib/posts_with_tags.sh source ./lib/posts_with_tags.sh
source ./lib/rebuild_all_entries.sh source ./lib/rebuild_all_entries.sh
@ -34,7 +40,6 @@ source ./lib/rebuild_index.sh
source ./lib/rebuild_tags.sh source ./lib/rebuild_tags.sh
source ./lib/reset.sh source ./lib/reset.sh
source ./lib/tags_in_post.sh source ./lib/tags_in_post.sh
source ./lib/test_markdown.sh
source ./lib/twitter_card.sh source ./lib/twitter_card.sh
source ./lib/usage.sh source ./lib/usage.sh
source ./lib/write_entry.sh source ./lib/write_entry.sh