41 lines
1.4 KiB
Bash
41 lines
1.4 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
# 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
|
|
|
|
rebuild_all_entries() {
|
|
|
|
echo -n "Rebuilding all entries "
|
|
|
|
for i in ./*.html; do
|
|
is_boilerplate_file "$i" && continue
|
|
contentfile=.tmp.$RANDOM
|
|
while [[ -f $contentfile ]]; do contentfile=.tmp.$RANDOM; done
|
|
|
|
echo -n "."
|
|
# Get the title and entry, and rebuild the html structure from scratch (divs, title, description...)
|
|
title=$(get_post_title "$i")
|
|
|
|
get_html_file_content 'text' 'text' <"$i" >>"$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"
|
|
# 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"
|
|
done
|
|
echo ""
|
|
}
|