aboutsummaryrefslogtreecommitdiff
path: root/phlogthis
blob: 08410e13d82ba59c1dcda0e1796499dba8ae5913 (plain)
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
#!/bin/bash

# create phlog entry, rebuild gophermap
# requires par for text formatting


root=$HOME/src/gopher/phlog

mkdir -p $HOME/.tmp
pushd "$(pwd)"  
cd $HOME/.tmp || exit
editfile="phlogtmp.txt"
articledate="$(date -R)"
filedate="$(date +%Y-%m-%d-%H-%I)"

read -r -p "Enter title: " title

filetitle=$(echo $title | sed 's/ /-/g' | sed 's/[^A-Za-z0-9._-]//g')
article=$filedate-$filetitle.txt

dest="$root/$article"

micro +4:1 "$editfile"

# article
cat "$editfile" | par -jw67 >> "$article"

header="title:$title\ndate:$articledate\n\n" 
sed -i "1s/^/$header/" $article

mv "$article" "$dest"
rm $editfile
echo "Article saved as $dest"

# create gophermap

cd $root

echo "╔═══════════════════════════════════╗" > gophermap
echo "║ Phil's Phlog                      ║" >> gophermap
echo "╚═══════════════════════════════════╝" >> gophermap
echo "" >> gophermap
echo "0[Rss feed]	/phlog/rss.xml	spike.nagatha.fr	70" >> gophermap
echo "" >> gophermap


files=($(ls -1r *.txt))
for file in "${files[@]}"; do
    echo -e "0$(head -n 1 $file | sed s/title://g)\t/phlog/$file\tspike.nagatha.fr\t70" >> gophermap
done

popd
exit 0