X-Git-Url: https://projects.mako.cc/source/pyblosxom2wxr/blobdiff_plain/b718cd1999414cb05ab40db5a1cf106dc4521935..9066cfd27ee72987b460abed6f27c5b820915c6c:/pyblosxom2wxr.sh
diff --git a/pyblosxom2wxr.sh b/pyblosxom2wxr.sh
index c3218d7..4e91ef5 100755
--- a/pyblosxom2wxr.sh
+++ b/pyblosxom2wxr.sh
@@ -26,6 +26,10 @@ if [[ $# = "0" || $1 = "--help" ]]; then
exit 1
fi
+# category
+all_categories=""
+all_tags=""
+
# comment id sequence number
commentid=1
@@ -52,46 +56,23 @@ cat << EOF
1.0
-
-
EOF
-# convert comments
+
+# convert blog posts
for file in "$@"; do
+ creator="mako"
fullname=`basename "$file" .txt`
dir=`dirname "$file"`
+ commentdir="$(dirname "$file")/comments"
title=`head -n 1 "$file"`
+ type="post"
- # TODO: make this easier to customize
- date_re="[0-9]{4}-[0-9]{2}-[0-9]{2}"
- time_re="([0-9]{2})-([0-9]{2})"
-
- # my pyblosxom posts have a date prefix, e.g. 2010-03-13. my pages don't.
- if [[ "$fullname" =~ ^${date_re} ]]; then
- type=post
- name=${fullname:11}
- datestr="${fullname::10} 00:00:00 -0800"
- else
- type=page
- name=${fullname}
-
- timestamp_file=${dir}/../timestamps
- datestr=`grep --max-count=1 -E \
- "^${date_re}-${time_re} (.+/)?${fullname}.txt\$" ${timestamp_file} | \
- cut -f1 -d' ' | \
- sed -r "s/-${time_re}\$/ \1:\2 -0500/"`
-
- if [[ ${datestr} == '' ]]; then
- datestr=`stat --format=%y "$file"`
- fi
- fi
-
- pubDate=`date -uR -d "$datestr"`
- date=`date -d "$datestr" +'%F %T'`
- dateGmt=`date -u -d "$datestr" +'%F %T'`
+ name=${fullname}
- # TODO: category support
- category="uncategorized"
+ pubDate=$(date -uR -r $file)
+ date=$(date -r "$file" +'%F %T')
+ dateGmt=$(date -u -r "$file" +'%F %T')
if grep -q ']]>' "$file"; then
echo "WARNING: $file contains the string ]]>, which makes its CDATA " \
@@ -102,10 +83,9 @@ for file in "$@"; do
-
${title}
${pubDate}
- $category
/${fullname}
-
+
${date}
${dateGmt}
open
@@ -117,16 +97,27 @@ for file in "$@"; do
${type}
0
+ ${creator}
EOF
+
+ # split the tags
+ raw_tags=$(grep '#tags' "$file" |perl -pe 's/.tags // '|tr ',' "\n")
+ for tag in $raw_tags; do
+ echo "${tag}"
+ #echo "$category"
+ done;
+ all_tags="$all_tags$raw_tags"
+
+ # category="uncategorized"
+ # $category
# other possible elements:
# /${fullname}
#
#
-# ${creator}
- for cmtfile in ${dir}/"$fullname"-{all,[0-9]*}.cmt; do
+ for cmtfile in ${commentdir}/"$fullname"-{all,[0-9]*}.cmt; do
if [[ -e "$cmtfile" ]]; then
set +e # because the perl script below uses a non-zero exit code
tail -q -n +2 "$cmtfile" | \
@@ -163,6 +154,22 @@ EOF
EOF
done
+index=2
+#for category in $(echo "$all_categories"|sort|uniq); do
+# cat << EOF
+# ${index}${category}
+#EOF
+# index=$(expr $index + 1)
+#done
+
+for tag in $(echo "$all_tags"|sort|uniq); do
+ cat << EOF
+ ${index}${tag}${tag}
+EOF
+ index=$(expr $index + 1)
+done
+
+
# output footer
cat << EOF