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=${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
if [[ $index == no ]]; then
echo '<!-- entry begin -->' # marks the beginning of the whole post

View File

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

View File

@ -12,11 +12,12 @@
# "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" ]] && \
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 -->
# note that this does not remove <hr /> line itself,
# 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() {
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/){

View File

@ -3,6 +3,8 @@
# Return the post author
#
# $1 the html file
declare global_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
# 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

View File

@ -3,14 +3,14 @@
# 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
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
echo "No posts yet. Use 'bb.sh post' to create one" && return
echo "No posts yet. Use '$0 post' to create one" && return
fi
lines=""

View File

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

View File

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

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

View File

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

View File

@ -3,6 +3,7 @@
# 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,13 +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
declare markdown_bin
declare template_tags_line_header
declare prefix_tags
rebuild_all_entries() {
declare date_inpost
declare date_format_full
declare date_format_timestamp
echo -n "Rebuilding all entries "
for i in ./*.html; do
for i in ./*.md; do
is_boilerplate_file "$i" && continue;
contentfile=.tmp.$RANDOM
while [[ -f $contentfile ]]; do contentfile=.tmp.$RANDOM; done
@ -16,22 +20,42 @@ rebuild_all_entries() {
echo -n "."
# Get the title and entry, and rebuild the html structure from scratch (divs, title, description...)
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
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'
timestamp=$(LC_ALL=C date -r "$i" +"$date_format_full")
create_html_page "$contentfile" "$i.rebuilt" no "$title" "$timestamp" "$(get_post_author "$i")"
# keep the original timestamp!
timestamp=$(LC_ALL=C date -r "$i" +"$date_format_timestamp")
mv "$i.rebuilt" "$i"
chmod 644 "$i"
touch -t "$timestamp" "$i"
rm "$contentfile"
newfile=${i%.md}.html
mv "$i.rebuilt" "$newfile"
chmod 644 "$newfile"
touch -t "$timestamp" "$newfile"
#rm "$contentfile"
done
echo ""
}

View File

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

View File

@ -9,14 +9,15 @@
# 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)

View File

@ -3,7 +3,7 @@
# 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

@ -7,12 +7,8 @@ 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 [[ -f $f ]]; then
if [[ -n $f ]]; then
if [[ ! -f $f ]]; then
echo "The file $f doesn't exist"
delete_includes
exit

View File

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

View File

@ -6,7 +6,7 @@
# 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) {
#gsub("&", "\\&amp;", t);

View File

@ -1,9 +1,9 @@
#!/bin/awk -f
#
# by: Josemar Lohn <j@lo.hn>
# lo.hn on www/gemini/gopher
# by: Jesus Galan (yiyus) 2009
#
# 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

View File

@ -7,7 +7,7 @@ Describe 'do_main()'
It 'Call function do_main without paramenters'
When call do_main
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]"
End
End