Update rss feed title
This commit is contained in:
parent
ba1765bb95
commit
c097fffa8a
1 changed files with 68 additions and 68 deletions
136
bin/rss.sh
136
bin/rss.sh
|
@ -21,101 +21,101 @@ date_to_rfc_822() {
|
||||||
}
|
}
|
||||||
|
|
||||||
get_header() {
|
get_header() {
|
||||||
HFILE="$1"
|
HFILE="$1"
|
||||||
HEADER="$2"
|
HEADER="$2"
|
||||||
|
|
||||||
FILTER="{ \
|
FILTER="{ \
|
||||||
if (match(\$0, /^$HEADER: /)) {print substr(\$0, RLENGTH+1, length(\$0) - RLENGTH)}; \
|
if (match(\$0, /^$HEADER: /)) {print substr(\$0, RLENGTH+1, length(\$0) - RLENGTH)}; \
|
||||||
if (\$0~/^$/) {exit}; \
|
if (\$0~/^$/) {exit}; \
|
||||||
if (!\$0~/^[^ ]*: .*$/) {exit}; \
|
if (!\$0~/^[^ ]*: .*$/) {exit}; \
|
||||||
}"
|
}"
|
||||||
|
|
||||||
awk "$FILTER" "$HFILE"
|
awk "$FILTER" "$HFILE"
|
||||||
}
|
}
|
||||||
|
|
||||||
list_items() {
|
list_items() {
|
||||||
DIR="$1"
|
DIR="$1"
|
||||||
|
|
||||||
pushd "$DIR" > /dev/null
|
pushd "$DIR" > /dev/null
|
||||||
find . ! -path . -type d | while read -r FN
|
find . ! -path . -type d | while read -r FN
|
||||||
do
|
do
|
||||||
PAGE="$(echo "$FN" | sed 's/^\.\///g')"
|
PAGE="$(echo "$FN" | sed 's/^\.\///g')"
|
||||||
#echo "FILE: $PAGE"
|
#echo "FILE: $PAGE"
|
||||||
|
|
||||||
MD="$PAGE/note.md"
|
MD="$PAGE/note.md"
|
||||||
if [ ! -f "$MD" ]; then
|
if [ ! -f "$MD" ]; then
|
||||||
echo "$MD doesn't exist"
|
echo "$MD doesn't exist"
|
||||||
exit 1;
|
exit 1;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
SUBJECT="$(get_header "$MD" "Subject")"
|
SUBJECT="$(get_header "$MD" "Subject")"
|
||||||
FDATE="$(get_header "$MD" "X-Date" | sed 's/T.*$//g')"
|
FDATE="$(get_header "$MD" "X-Date" | sed 's/T.*$//g')"
|
||||||
|
|
||||||
if [ -z "$SUBJECT" ]; then
|
if [ -z "$SUBJECT" ]; then
|
||||||
echo "No subject in $MD"
|
echo "No subject in $MD"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$FDATE" ] && [ "$NODATE" == "0" ]; then
|
if [ -z "$FDATE" ] && [ "$NODATE" == "0" ]; then
|
||||||
echo "No date in $MD"
|
echo "No date in $MD"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "$FDATE $PAGE $SUBJECT"
|
echo "$FDATE $PAGE $SUBJECT"
|
||||||
done
|
done
|
||||||
popd > /dev/null
|
popd > /dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
render_item() {
|
render_item() {
|
||||||
base_url="$1"
|
base_url="$1"
|
||||||
item="$2"
|
item="$2"
|
||||||
|
|
||||||
site_url="$(echo "$base_url"| sed 's#\(.*//.*\)/.*#\1#')"
|
site_url="$(echo "$base_url"| sed 's#\(.*//.*\)/.*#\1#')"
|
||||||
|
|
||||||
date=$(echo "$item"|awk '{print $1}')
|
date=$(echo "$item"|awk '{print $1}')
|
||||||
url=$(echo "$item"|awk '{print $2}')
|
url=$(echo "$item"|awk '{print $2}')
|
||||||
title=$(echo "$item"| cut -d ' ' -f 3- )
|
title=$(echo "$item"| cut -d ' ' -f 3- )
|
||||||
|
|
||||||
guid="$base_url/$(echo "$url" | sed 's#^/##')"
|
guid="$base_url/$(echo "$url" | sed 's#^/##')"
|
||||||
|
|
||||||
cat <<-EOF
|
cat <<-EOF
|
||||||
<item>
|
<item>
|
||||||
<guid>$guid</guid>
|
<guid>$guid</guid>
|
||||||
<link>$guid</link>
|
<link>$guid</link>
|
||||||
<pubDate>$(date_to_rfc_822 "$date")</pubDate>
|
<pubDate>$(date_to_rfc_822 "$date")</pubDate>
|
||||||
<title>$title</title>
|
<title>$title</title>
|
||||||
</item>
|
</item>
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
render_items() {
|
render_items() {
|
||||||
base_url="$1"
|
base_url="$1"
|
||||||
|
|
||||||
while read -r i
|
while read -r i
|
||||||
do render_item "$1" "$i"
|
do render_item "$1" "$i"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
render_feed() {
|
render_feed() {
|
||||||
url="$1"
|
url="$1"
|
||||||
title=$(echo "$2" | remove_nbsp)
|
title=$(echo "$2" | remove_nbsp)
|
||||||
description="$3"
|
description="$3"
|
||||||
|
|
||||||
base_url="$(echo "$url" | cut -d '/' -f1-3)"
|
base_url="$(echo "$url" | cut -d '/' -f1-3)"
|
||||||
|
|
||||||
cat <<-EOF
|
cat <<-EOF
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
||||||
<channel>
|
<channel>
|
||||||
<atom:link href="$url" rel="self" type="application/rss+xml" />
|
<atom:link href="$url" rel="self" type="application/rss+xml" />
|
||||||
<title>$title</title>
|
<title>$title</title>
|
||||||
<description>$description</description>
|
<description>$description</description>
|
||||||
<link>$base_url/</link>
|
<link>$base_url/</link>
|
||||||
<lastBuildDate>$(date_rfc_822)</lastBuildDate>
|
<lastBuildDate>$(date_rfc_822)</lastBuildDate>
|
||||||
$(cat)
|
$(cat)
|
||||||
</channel></rss>
|
</channel></rss>
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
list_items "$1" | sort | render_items "$2$3" | render_feed "$2" "Konstantin Nazarov" "test"
|
list_items "$1" | sort | render_items "$2$3" | render_feed "$2" "Konstantin Nazarov" "Konstantin Nazarov's blog"
|
||||||
|
|
Loading…
Reference in a new issue