-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtomd
executable file
·56 lines (41 loc) · 1.32 KB
/
tomd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/sh
# shell script to convert textile content to markdown using sed, awk and pandoc.
# copy this file and tomd_pre.awk and tomd_post.awk into your local jekyll project folder
# then `chmod +x tomd` and invoke with `tomd [_posts] [_old_posts]`
# remember to keep a backup of everything, and USE THIS AT YOUR OWN RISK.
set -e
set -o pipefail
# make sure the following exist
echo "checking for sed, awk, and pandoc"
which sed | sed '1 q'
awk --version | sed '1 q'
pandoc -v | sed '1 q'
# script dir
DIR=`dirname $0`
# posts dir
if [ $1 ] ; then
POSTSDIR=$1
else
POSTSDIR=_posts
fi
# archive dir
if [ $2 ] ; then
OLDDIR=$1
else
OLDDIR=_old_posts
fi
echo "looking for .textile files in $POSTSDIR moving them to $OLDDIR"
mkdir -p -v $OLDDIR
# find all the textile files
find $POSTSDIR -name \*.textile | sed 's/\.textile$//' >tomd_files.txt
while read foo; do
# save YAML header
sed -n '1,/^---/ p' $foo.textile >tomd_head.txt
# textile (minus header) | tomd_pre | pandoc | tomd_post
sed '1,/^---/ d' $foo.textile | awk -f $DIR/tomd_pre.awk | pandoc -B tomd_head.txt -f textile -t markdown_github | awk -f $DIR/tomd_post.awk >$foo.md
# archive
mv $foo.textile $OLDDIR
done <tomd_files.txt
echo `wc -l <tomd_files.txt` textile files converted
# clean up
rm -f tomd_files.txt tomd_head.txt tomd-include-*.txt