-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_xml.sh
29 lines (22 loc) · 1.29 KB
/
gen_xml.sh
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
# " --> "
# & --> &
# ' --> '
# < --> <
# > --> >
content="$(./hoedown "$1" | tail -n +2 | sed 's/</\<\;/g' | sed 's/>/\>\;/g')"
title=$(cat "$1" | head -n 1 | sed 's/# //' | sed -e 's/\r//g')
file=$(printf "$1" | sed 's/\.md$//' | sed 's/^\.\///')
config=$(cat ./config.txt)
url=$(printf "$config" | awk 'gsub(/^url:/,"")');
prime_folder=$(printf "$config" | awk 'gsub(/^prime_folder:/,"")');
post=$(printf "$config" | awk 'gsub(/^post:/,"")');
ftp=$(printf "$config" | awk 'gsub(/^ftp:/,"")');
user=$(printf "$config" | awk 'gsub(/^user:/,"")');
#f_end="$(cat ./$prime_folder/$post/index.xml | tail -n 2)"
#f_start=$(cat ./$prime_folder/$post/index.xml | awk -v RS="$f_end" 'NR==1{printf $0} NR!=1{printf "%s", $0}')
f_start=$(head -n 6 "./static/$prime_folder$post/index.xml")
f_end=$(tail -n +7 "./static/$prime_folder$post/index.xml")
pub_date=$(date '+%a, %d %b %Y %H:%M:%S %z')
f_out=$(printf "$f_start\n<item>\n\t<title>$title</title>\n\t<pubDate>$pub_date</pubDate>\n\t<link>$url/$prime_folder$post/$file/</link>\n\t<guid>$url/$prime_folder$post/$file/</guid>\n\t<description>$content</description>\n</item>\n$f_end" | awk -v chunk="$(date '+%B %d/%d/%Y %I:%M%p')" '{gsub("<DATE_POST>",chunk)}1')
printf "$f_out"
printf "$f_out" > "static/$prime_folder$post/index.xml"