X-Git-Url: https://projects.mako.cc/source/pyblosxom2wxr/blobdiff_plain/63b7950374b42e5bb351e534dfa3c150c3d5a285..f34e97609dfb44f29bfb8aceac0e1170707ba6e0:/pyblosxom2wxr.sh?ds=sidebyside diff --git a/pyblosxom2wxr.sh b/pyblosxom2wxr.sh deleted file mode 100755 index 4e91ef5..0000000 --- a/pyblosxom2wxr.sh +++ /dev/null @@ -1,177 +0,0 @@ -#!/bin/bash -# -# pyblosxom2wxr.sh -# http://snarfed.org/pyblosxom2wxr -# Ryan Barrett -# Version 0.2. This script is public domain. -# -# This script converts PyBlosxom posts and comments into a WXR (WordPress -# eXtensible RSS) XML file that can be imported into a WordPress blog. -# -# Example usage: -# -# $ ./pyblosxom2wxr.sh post1.txt post2.txt > posts.xml -# -# pyblosxom2wxr has been tested with PyBlosxom 1.4 and WordPress 2.9 and 3.0. It -# should work with other versions too, but your mileage may vary. -# -# TODO: comment ordering - -# exit on error -set -e - -# check args -if [[ $# = "0" || $1 = "--help" ]]; then - echo 'Usage: pyblosxom2wxr.sh FILES...' - exit 1 -fi - -# category -all_categories="" -all_tags="" - -# comment id sequence number -commentid=1 - -# output header -now=`date --rfc-3339=seconds` -cat << EOF - - - - - - - - - - - http://snarfed.org/pyblosxom2wxr?v=1.0 - en - 1.0 - - -EOF - - -# 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" - - name=${fullname} - - 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 " \ - "section invalid. WordPress handles this ok, but still, heads up." 1>&2 - fi - - cat << EOF - - ${title} - ${pubDate} - /${fullname} - - - ${date} - ${dateGmt} - open - open - ${name} - publish - 0 - 0 - ${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} -# -# - - - 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" | \ - sed -r ' - s/^$/\nX<\/wp:comment_id>/; - s/^<\/item>$/1<\/wp:comment_approved>\n<\/wp:comment>/; - s/<(\/)?author>/<\1wp:comment_author>/g; - s/<(\/)?link>/<\1wp:comment_author_url>/g; - s/<(\/)?ipaddress>/<\1wp:comment_author_IP>/g; - s/<(\/)?description>/<\1wp:comment_content>/g; - s/^<(ajax|cmt_date|email|openid_url|parent|post|secretToken|source|title|w3cdate)>.+$//; - s/^<\/?items>$//; - /^$/d' | \ - perl -pe 'use HTML::Entities; decode_entities($_)' | \ - perl -pe 'use POSIX qw(strftime); - s/^(.+)<\/pubDate>$/"" . (strftime "%Y-%m-%d %H:%M:%S", localtime($1)) . "<\/wp:comment_date>"/e;' | \ - perl -e ' - my $id = '${commentid}'; - while () { - s/^()X(<\/wp:comment_id>)$/$1 . $id++ . $2/e; - print $_; - } - exit $id - '${commentid}';' - # TODO: this is a hack since exit codes are only 8 bits unsigned. - # this will break on posts with >255 comments. - let commentid+=$? - set -e - fi - done - - cat << 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 - - -EOF