главная|main page

состояние|status

блог|blog

файлы|files

программы|software

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--[-rwxr-xr-x]bb.sh45
1 files changed, 29 insertions, 16 deletions
diff --git a/bb.sh b/bb.sh
index af6fbdd..6beda86 100755..100644
--- a/bb.sh
+++ b/bb.sh
@@ -346,11 +346,12 @@ edit() {
twitter_card() {
[[ -z $global_twitter_username ]] && return
- echo "<meta name='twitter:card' content='summary' />"
- echo "<meta name='twitter:site' content='@$global_twitter_username' />"
- echo "<meta name='twitter:title' content='$2' />" # Twitter truncates at 70 char
+
+ echo "<meta name='twitter:card' content='summary'>"
+ echo "<meta name='twitter:site' content='@$global_twitter_username'>"
+ echo "<meta name='twitter:title' content='$2'>" # Twitter truncates at 70 char
description=$(grep -v "^<p>$template_tags_line_header" "$1" | sed -e 's/<[^>]*>//g' | tr '\n' ' ' | sed "s/\"/'/g" | head -c 250)
- echo "<meta name='twitter:description' content=\"$description\" />"
+ echo "<meta name='twitter:description' content=\"$description\">"
# For the image we try to locate the first image in the article
image=$(sed -n '2,$ d; s/.*<img.*src="\([^"]*\)".*/\1/p' "$1")
@@ -363,7 +364,7 @@ twitter_card() {
# Final housekeeping
[[ $image =~ ^https?:// ]] || image=$global_url/$image # Check that URL is absolute
- echo "<meta name='twitter:image' content='$image' />"
+ echo "<meta name='twitter:image' content='$image'>"
}
# Adds the code needed by the twitter button
@@ -671,6 +672,9 @@ all_posts() {
while IFS='' read -r i; do
is_boilerplate_file "$i" && continue
echo -n "." 1>&3
+ # Read timestamp from post, and sync file timestamp
+ timestamp=$(awk '/<!-- '$date_inpost': .+ -->/ { print }' "$i" | cut -d '#' -f 2)
+ [[ -n $timestamp ]] && touch -t "$timestamp" "$i"
# Month headers
month=$(LC_ALL=$date_locale date -r "$i" +"$date_allposts_header")
if [[ $month != "$prev_month" ]]; then
@@ -685,7 +689,7 @@ all_posts() {
# Date
date=$(LC_ALL=$date_locale date -r "$i" +"$date_format")
echo " $date</li>"
- done < <(ls -t ./*.html)
+ done < <(list_html_by_timestamp)
echo "" 1>&3
echo "</ul>"
echo "<div id=\"all_posts\"><a href=\"./$index_file\">$template_archive_index_page</a></div>"
@@ -755,7 +759,7 @@ rebuild_index() {
fi
echo -n "." 1>&3
n=$(( n + 1 ))
- done < <(ls -t ./*.html) # sort by date, newest first
+ done < <(list_html_by_timestamp) # sort by file timestamp, newest first
feed=$blog_feed
if [[ -n $global_feedburner ]]; then feed=$global_feedburner; fi
@@ -873,7 +877,7 @@ list_tags() {
[[ -f "$i" ]] || break
nposts=$(grep -c "<\!-- text begin -->" "$i")
tagname=${i#"$prefix_tags"}
- tagname=${tagname#.html}
+ tagname=${tagname%.html}
((nposts > 1)) && word=$template_tags_posts || word=$template_tags_posts_singular
line="$tagname # $nposts # $word"
lines+=$line\\n
@@ -983,15 +987,15 @@ create_includes() {
if [[ -f $header_file ]]; then cp "$header_file" .header.html
else {
- echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
- echo '<html xmlns="http://www.w3.org/1999/xhtml"><head>'
- echo '<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />'
- echo '<meta name="viewport" content="width=device-width, initial-scale=1.0" />'
- printf '<link rel="stylesheet" href="%s" type="text/css" />\n' "${css_include[@]}"
+ echo '<!DOCTYPE html>'
+ echo '<html><head>'
+ echo '<meta charset="UTF-8">'
+ echo '<meta name="viewport" content="width=device-width, initial-scale=1.0">'
+ printf '<link rel="stylesheet" href="%s" type="text/css">\n' "${css_include[@]}"
if [[ -z $global_feedburner ]]; then
- echo "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"$template_subscribe_browser_button\" href=\"$blog_feed\" />"
+ echo "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"$template_subscribe_browser_button\" href=\"$blog_feed\">"
else
- echo "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"$template_subscribe_browser_button\" href=\"$global_feedburner\" />"
+ echo "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"$template_subscribe_browser_button\" href=\"$global_feedburner\">"
fi
} > ".header.html"
fi
@@ -1000,7 +1004,7 @@ create_includes() {
else {
protected_mail=${global_email//@/&#64;}
protected_mail=${protected_mail//./&#46;}
- echo "<div id=\"footer\">$global_license <a href=\"$global_author_url\">$global_author</a> &mdash; <a href=\"mailto:$protected_mail\">$protected_mail</a><br/>"
+ echo "<div id=\"footer\">$global_license <a href=\"$global_author_url\">$global_author</a> &mdash; <a href=\"mailto:$protected_mail\">$protected_mail</a><br>"
echo 'Generated with <a href="https://github.com/cfenollosa/bashblog">bashblog</a>, a single bash script to easily create blogs like this one</div>'
} >> ".footer.html"
fi
@@ -1156,6 +1160,15 @@ date_version_detect() {
fi
}
+# Lists html files in directory ordering by their timestamps
+# instead of modified date
+list_html_by_timestamp() {
+ grep "$date_inpost" ./*.html \
+ | sed -nr 's/<!-- '"$date_inpost"': #(.*)# -->$/\1/p' \
+ | sort --field-separator=: --key=2 --stable --reverse \
+ | sed -nr 's/^(.*):.*$/\1/p'
+}
+
# Main function
# Encapsulated on its own function for readability purposes
#