commit 8d1aabd995ed7ada5ce5286217af6b6c80db779d
parent ed7e3b581eb13308b67c85654b6632de6fa7429a
Author: St John Karp <contact@stjo.hn>
Date: Sat, 30 May 2020 06:24:53 -0500
Handle files that have no headers
Fixed handling of files that have no headers. Only split the
file at the first new line if headers are detected. Created a
function for recombining the two.
Diffstat:
1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/squeeze.sh b/squeeze.sh
@@ -5,6 +5,18 @@ SOURCE_DIR=source
SITE_PATH=$1
+combine_headers () {
+ read -d "" HTML
+
+ if [ "$1" = "" ]; then
+ echo "$HTML"
+ else
+ echo "$1"
+ echo ""
+ echo "$HTML"
+ fi
+}
+
# Copy everything that's not Markdown or HTML.
# This will also create the folder structure for the destination Markdown files.
rsync --archive --delete --verbose --exclude "*.md" --exclude "*.html" --exclude "feeds" "$SITE_PATH/$SOURCE_DIR/" "$SITE_PATH/$OUTPUT_DIR/"
@@ -29,12 +41,21 @@ find "$SITE_PATH/$SOURCE_DIR" -type f -name "*.md" |
# Only process files whose destination doesn't exist, or which has been recently changed.
if [ ! -f "$NEW_PATH" ] || [[ $(find "$file" -mtime -7) ]]; then
echo "$file"
+
# Get everything after the metadata.
- sed "1,/^$/d" "$file" |
+ if grep -q "^Title: " "$file"; then
+ HEADERS=$(sed "/^$/q" "$file")
+ MARKDOWN=$(sed "1,/^$/d" "$file")
+ else
+ HEADERS=""
+ MARKDOWN=$(cat "$file")
+ fi
+
+ echo "$MARKDOWN" |
# Convert Markdown to HTML.
markdown |
# Recombine with the metadata and hand it to Prolog.
- (sed "/^$/q" "$file" && cat) |
+ combine_headers "$HEADERS" |
#gprolog --consult-file parse_entry.pl --consult-file "$SITE_PATH/site.pl" --entry-goal "generate_entry" |
swipl --traditional --quiet -l parse_entry.pl -g "consult('$SITE_PATH/site.pl'), generate_entry." |
# Some Prolog variants will output banners and "compiling" output no matter how nicely you ask them not to.