FIX generation from markdown

This commit is contained in:
Josemar Lohn 2021-03-12 09:13:56 +00:00
parent 26468aec34
commit e12648d054
No known key found for this signature in database
GPG Key ID: BE6B8FD676E471E4
21 changed files with 116 additions and 86 deletions

View File

@ -47,6 +47,8 @@ create_html_page() {
file_url=${filename#./} file_url=${filename#./}
file_url=${file_url%.rebuilt} # Get the correct URL when rebuilding file_url=${file_url%.rebuilt} # Get the correct URL when rebuilding
file_url=${file_url%.html}
file_url=${file_url%.md}.html # Get the correct link
# one blog entry # one blog entry
if [[ $index == no ]]; then if [[ $index == no ]]; then
echo '<!-- entry begin -->' # marks the beginning of the whole post echo '<!-- entry begin -->' # marks the beginning of the whole post

View File

@ -77,7 +77,10 @@ do_main() {
all_posts all_posts
all_tags all_tags
make_rss make_rss
echo 'making gophermap'
make_gophermap make_gophermap
echo 'making geminicapsule'
make_gemini make_gemini
echo 'deleting includes'
delete_includes delete_includes
} }

View File

@ -12,11 +12,12 @@
# "keep" to keep old filename # "keep" to keep old filename
# "full" to edit full HTML, and not only text part (keeps 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) # 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() { 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 printf "Can't edit post \"%s.html\", did you mean to use \"bb.sh post <draft_file>\"?\\n" "${1%%.*}" && exit 1

View File

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

View File

@ -3,6 +3,8 @@
# Return the post author # Return the post author
# #
# $1 the html file # $1 the html file
declare global_author
get_post_author() { get_post_author() {
awk '/<div class="subtitle">.+/, /<!-- text begin -->/{if (!/<div class="subtitle">.+/ && !/<!-- text begin -->/) print}' "$1" | sed 's/<\/div>//g' # awk '/<div class="subtitle">.+/, /<!-- text begin -->/{if (!/<div class="subtitle">.+/ && !/<!-- text begin -->/) print}' "$1" | sed 's/<\/div>//g'
echo $global_author
} }

View File

@ -8,19 +8,17 @@
# #
# Return 0 (bash return value 'true') if the input file is an index, feed, etc # 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 # 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() { 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#./} name=${1#./}
# First check against user-defined non-blogpost pages # First check against user-defined non-blogpost pages
for item in "${non_blogpost_files[@]}"; do for item in "${non_blogpost_files[@]}"; do

View File

@ -3,14 +3,14 @@
# Displays a list of the tags # Displays a list of the tags
# #
# $2 if "-n", tags will be sorted by number of posts # $2 if "-n", tags will be sorted by number of posts
list_tags() { declare prefix_tags
declare prefix_tags declare template_tags_posts_singular
declare template_tags_posts_singular declare template_tags_posts
declare template_tags_posts list_tags() {
if [[ $2 == -n ]]; then do_sort=1; else do_sort=0; fi 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 echo "No posts yet. Use '$0 post' to create one" && return
fi fi
lines="" lines=""

View File

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

View File

@ -1,7 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
declare gophermap
make_gophermap() { make_gophermap() {
declare gophermap
if [ ! -d "${HOME}/public_gopher" ]; then if [ ! -d "${HOME}/public_gopher" ]; then
printf "Creating gopher hole\\n" printf "Creating gopher hole\\n"
mkdir "${HOME}/public_gopher" mkdir "${HOME}/public_gopher"
@ -23,5 +22,5 @@ make_gophermap() {
EOF EOF
chmod +x "${HOME}/public_html/blog/${gophermap}" chmod +x "${HOME}/public_html/blog/${gophermap}"
fi fi
chmod 644 "./*.md" chmod 644 ./*.md
} }

View File

@ -1,15 +1,16 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Generate the feed file # 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() { 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 " echo -n "Making RSS "
rssfile=$blog_feed.$RANDOM rssfile=$blog_feed.$RANDOM

View File

@ -8,11 +8,11 @@
# note that although timestamp is optional, something must be provided at its # note that although timestamp is optional, something must be provided at its
# place if destination file name is provided, i.e: # place if destination file name is provided, i.e:
# parse_file source.txt "" destination.html # parse_file source.txt "" destination.html
declare convert_filename
declare template_tags_line_header
declare prefix_tags
declare global_author
parse_file() { 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 # Read for the title and check that the filename is ok
title="" title=""
while IFS='' read -r line; do while IFS='' read -r line; do

View File

@ -3,6 +3,7 @@
# Finds all posts referenced in a number of tags. # Finds all posts referenced in a number of tags.
# Arguments are tags # Arguments are tags
# Prints one line with space-separated tags to stdout # Prints one line with space-separated tags to stdout
declare prefix_tags
posts_with_tags() { posts_with_tags() {
(($# < 1)) && return (($# < 1)) && return
set -- "${@/#/$prefix_tags}" set -- "${@/#/$prefix_tags}"

View File

@ -2,13 +2,17 @@
# Regenerates all the single post entries, keeping the post content but modifying # Regenerates all the single post entries, keeping the post content but modifying
# the title, html structure, etc # the title, html structure, etc
#declare date_inpost
declare date_format_full
declare date_format_timestamp
declare markdown_bin
declare template_tags_line_header
declare prefix_tags
rebuild_all_entries() { rebuild_all_entries() {
declare date_inpost
declare date_format_full
declare date_format_timestamp
echo -n "Rebuilding all entries " echo -n "Rebuilding all entries "
for i in ./*.html; do for i in ./*.md; do
is_boilerplate_file "$i" && continue; is_boilerplate_file "$i" && continue;
contentfile=.tmp.$RANDOM contentfile=.tmp.$RANDOM
while [[ -f $contentfile ]]; do contentfile=.tmp.$RANDOM; done while [[ -f $contentfile ]]; do contentfile=.tmp.$RANDOM; done
@ -16,22 +20,42 @@ rebuild_all_entries() {
echo -n "." echo -n "."
# Get the title and entry, and rebuild the html structure from scratch (divs, title, description...) # Get the title and entry, and rebuild the html structure from scratch (divs, title, description...)
title=$(get_post_title "$i") title=$(get_post_title "$i")
$markdown_bin <"$i" >> "$contentfile"
get_html_file_content 'text' 'text' <"$i" >> "$contentfile"
#Get Tags
while IFS='' read -r line; do
if [[ $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"
echo -n "<p>$template_tags_line_header " >> "${contentfile}.tmp"
for item in "${array[@]}"; do
echo -n "<a href='$prefix_tags$item.html'>$item</a>, "
done | sed 's/, $/<\/p>/g' >> "${contentfile}.tmp"
else
echo "$line" >> "${contentfile}.tmp"
fi
done < "$contentfile"
cp "${contentfile}" "$contentfile.old"
mv "${contentfile}.tmp" "$contentfile"
# Read timestamp from post, if present, and sync file timestamp # Read timestamp from post, if present, and sync file timestamp
timestamp=$(awk '/<!-- '"$date_inpost"': .+ -->/ { print }' "$i" | cut -d '#' -f 2)
[[ -n $timestamp ]] && touch -t "$timestamp" "$i" #timestamp=$(awk '/<!-- '"$date_inpost"': .+ -->/ { print }' "$i" | cut -d '#' -f 2)
#[[ -n $timestamp ]] && touch -t "$timestamp" "$i"
# Read timestamp from file in correct format for 'create_html_page' # Read timestamp from file in correct format for 'create_html_page'
timestamp=$(LC_ALL=C date -r "$i" +"$date_format_full") timestamp=$(LC_ALL=C date -r "$i" +"$date_format_full")
create_html_page "$contentfile" "$i.rebuilt" no "$title" "$timestamp" "$(get_post_author "$i")" create_html_page "$contentfile" "$i.rebuilt" no "$title" "$timestamp" "$(get_post_author "$i")"
# keep the original timestamp! # keep the original timestamp!
timestamp=$(LC_ALL=C date -r "$i" +"$date_format_timestamp") timestamp=$(LC_ALL=C date -r "$i" +"$date_format_timestamp")
mv "$i.rebuilt" "$i" newfile=${i%.md}.html
chmod 644 "$i" mv "$i.rebuilt" "$newfile"
touch -t "$timestamp" "$i" chmod 644 "$newfile"
rm "$contentfile" touch -t "$timestamp" "$newfile"
#rm "$contentfile"
done done
echo "" echo ""
} }

View File

@ -1,21 +1,22 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Generate the index.html with the content of the latest posts # 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() { 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 " echo -n "Rebuilding the index "
newindexfile=$index_file.$RANDOM newindexfile=$index_file.$RANDOM
contentfile=$newindexfile.content contentfile=$newindexfile.content

View File

@ -9,14 +9,15 @@
# example: # example:
# rebuild_tags "one_post.html another_article.html" "example-tag another-tag" # rebuild_tags "one_post.html another_article.html" "example-tag another-tag"
# mind the quotes! # 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() { 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 if (($# < 2)); then
# will process all files and tags # will process all files and tags
files=$(ls -t ./*.html) files=$(ls -t ./*.html)

View File

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

View File

@ -7,12 +7,8 @@ declare global_url
declare convert_filename declare convert_filename
write_entry() { write_entry() {
f=$2 f=$2
extension=${f##*.} if [[ -n $f ]]; then
if [[ $extension != md ]]; then if [[ ! -f $f ]]; then
f=${f}.md
fi
if [[ -n $f ]]; thenq
if [[ -f $f ]]; then
echo "The file $f doesn't exist" echo "The file $f doesn't exist"
delete_includes delete_includes
exit exit

View File

@ -6,6 +6,6 @@
# Based on md2html by Jesus Galan (yiyus) 2009 # Based on md2html by Jesus Galan (yiyus) 2009
# #
# #
# Usage: md2gemini.awk file.md > file.html # Usage: md2gemini.awk file.md > file.gmi
1 1

View File

@ -6,7 +6,7 @@
# Based on md2html by Jesus Galan (yiyus) 2009 # Based on md2html by Jesus Galan (yiyus) 2009
# #
# #
# Usage: md2gopher.awk file.md > file.html # Usage: md2gopher.awk file.md > file.txt
function eschtml(t) { function eschtml(t) {
#gsub("&", "\\&amp;", t); #gsub("&", "\\&amp;", t);

View File

@ -1,9 +1,9 @@
#!/bin/awk -f #!/bin/awk -f
# #
# by: Josemar Lohn <j@lo.hn> # by: Jesus Galan (yiyus) 2009
# lo.hn on www/gemini/gopher
# #
# Based on md2html by Jesus Galan (yiyus) 2009 # Updated By Josemar Lohn <j@lo.hn>
# lo.hn on www/gemini/gopher
# #
# #
# Usage: md2html.awk file.md > file.html # Usage: md2html.awk file.md > file.html

View File

@ -7,7 +7,7 @@ Describe 'do_main()'
It 'Call function do_main without paramenters' It 'Call function do_main without paramenters'
When call do_main When call do_main
The line 1 of output should eq "You're not in your blog directory. Moving you there now" The line 1 of output should eq "You're not in your blog directory. Moving you there now"
#The line 2 of output should eq "tildelog 0.1" The line 2 of output should eq "tildelog 0.1"
#The line 3 of output should eq "usage: ./tildelog.sh command [filename]" #The line 3 of output should eq "usage: ./tildelog.sh command [filename]"
End End
End End