mirror of
https://github.com/mrrpnya/lipu-sona.git
synced 2025-02-13 16:44:39 +00:00
made blogindex also do rss
This commit is contained in:
parent
a4bae01ca1
commit
2362f9fef6
3 changed files with 58 additions and 102 deletions
2
Makefile
2
Makefile
|
@ -50,7 +50,7 @@ $(OUTDIR)/blog/index.html: $(_BLOG_PAGES) $(TPLDIR)/blog_header.md $(TPLDIR)/blo
|
|||
|
||||
$(OUTDIR)/blog/main.rss: $(_BLOG_PAGES)
|
||||
@mkdir -p $(@D)
|
||||
./blogrss.sh > $@
|
||||
./blogindex.sh -r > $@
|
||||
|
||||
$(OUTDIR)/text/%.txt: $(PAGEDIR)/text/%.txt
|
||||
@mkdir -p $(@D)
|
||||
|
|
64
blogindex.sh
64
blogindex.sh
|
@ -1,5 +1,15 @@
|
|||
#!/bin/bash
|
||||
|
||||
RSSMODE=
|
||||
|
||||
while getopts r name
|
||||
do
|
||||
case $name in
|
||||
r) RSSMODE=1;;
|
||||
?) printf "Usage: %s [-r]\n" $0; exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
DIRECTORY="pages/blog"
|
||||
|
||||
FILES=`ls $DIRECTORY/*.md -1 | sort`
|
||||
|
@ -12,7 +22,7 @@ function printcut {
|
|||
CUT=`grep -m 1 -n '<!--[[:space:]]*cut[[:space:]]*-->[[:space:]]*' $1`
|
||||
if [ -n "$CUT" ]; then
|
||||
CUTLINE=`echo "$CUT" | cut -d ':' -f 1`
|
||||
head -n $(($CUTLINE - 1)) $1 | grep -v '^%' | sed 's/^/> /'
|
||||
head -n $(($CUTLINE - 1)) $1 | grep -v '^%'
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
|
@ -48,7 +58,20 @@ done
|
|||
# resort by resulting times
|
||||
FILES=`cat blogdates.txt | sort -nr | cut -f 2-`
|
||||
|
||||
cat tpl/blog_header.md
|
||||
if [ $RSSMODE ]; then
|
||||
cat << RSSHEADER
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<rss version="2.0">
|
||||
<channel>
|
||||
<title>rnd's blog</title>
|
||||
<link>https://rnd.neocities.org/blog</link>
|
||||
<description>The RSS feed of articles published on the blog thingy</description>
|
||||
RSSHEADER
|
||||
|
||||
else
|
||||
cat tpl/blog_header.md
|
||||
fi
|
||||
|
||||
|
||||
for f in $FILES; do
|
||||
|
||||
|
@ -61,13 +84,40 @@ for f in $FILES; do
|
|||
OUTPAGE=${f%.md}.html
|
||||
OUTPAGE=${OUTPAGE#pages/blog/}
|
||||
|
||||
if [ $MTIME -gt 0 ]; then
|
||||
echo " * [$TITLE]($OUTPAGE) (`date -d "@$MTIME" "+%Y-%m-%d"`)"
|
||||
if [ $RSSMODE ]; then
|
||||
echo "<item>"
|
||||
echo "<title>$TITLE</title>"
|
||||
echo "<link>https://rnd.neocities.org/blog/$OUTPAGE</link>"
|
||||
|
||||
if [ $MTIME -gt 0 ]; then
|
||||
RDATE=`date -R -u -d @$MTIME`
|
||||
if [[ "$RDATE" == *UTC ]]; then
|
||||
RDATE="${RDATE%UTC}+0000"
|
||||
fi
|
||||
echo "<pubdate>$RDATE</pubdate>"
|
||||
fi
|
||||
DESCRIPTION="`printcut $f`"
|
||||
if [ $? -eq 0 ]; then
|
||||
DESC_HTML=`echo "$DESCRIPTION" | markdown`
|
||||
echo "<description>$DESC_HTML</description>"
|
||||
fi
|
||||
echo "</item>"
|
||||
else
|
||||
echo " * [$TITLE]($OUTPAGE)"
|
||||
if [ $MTIME -gt 0 ]; then
|
||||
echo " * [$TITLE]($OUTPAGE) (`date -d "@$MTIME" "+%Y-%m-%d"`)"
|
||||
else
|
||||
echo " * [$TITLE]($OUTPAGE)"
|
||||
fi
|
||||
|
||||
printcut $f | sed 's/^/> /'
|
||||
fi
|
||||
|
||||
printcut $f
|
||||
done
|
||||
|
||||
if [ $RSSMODE ]; then
|
||||
cat << RSSFOOTER
|
||||
</channel>
|
||||
</rss>
|
||||
RSSFOOTER
|
||||
else
|
||||
cat tpl/blog_footer.md
|
||||
fi
|
||||
|
|
94
blogrss.sh
94
blogrss.sh
|
@ -1,94 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
DIRECTORY="pages/blog"
|
||||
|
||||
FILES=`ls $DIRECTORY/*.md -1 | sort`
|
||||
|
||||
RETURNDATE=""
|
||||
|
||||
function printcut {
|
||||
# argument 1: filename
|
||||
|
||||
CUT=`grep -m 1 -n '<!--[[:space:]]*cut[[:space:]]*-->[[:space:]]*' $1`
|
||||
if [ -n "$CUT" ]; then
|
||||
CUTLINE=`echo "$CUT" | cut -d ':' -f 1`
|
||||
head -n $(($CUTLINE - 1)) $1 | grep -v '^%'
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# date is read from the 3rd %ed line of the document or from the git commit date
|
||||
function getdate {
|
||||
|
||||
FILEDATE=`grep "^%" $1 | sed '3q;d' | cut -d ' ' -f 2-`
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
FTIME=`date -u --date="$FILEDATE" "+%s"`
|
||||
else
|
||||
RETURNDATE=0
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
RETURNDATE=$FTIME
|
||||
return 0
|
||||
else
|
||||
RETURNDATE=0
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
echo -n > blogdates.txt
|
||||
for f in $FILES; do
|
||||
getdate $f
|
||||
printf "%d\t%s\n" $RETURNDATE $f >> blogdates.txt
|
||||
done
|
||||
|
||||
# resort by resulting times
|
||||
FILES=`cat blogdates.txt | sort -nr | cut -f 2-`
|
||||
|
||||
cat << RSSHEADER
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<rss version="2.0">
|
||||
<channel>
|
||||
<title>rnd's blog</title>
|
||||
<link>https://rnd.neocities.org/blog</link>
|
||||
<description>The RSS feed of articles published on the blog thingy</description>
|
||||
RSSHEADER
|
||||
|
||||
for f in $FILES; do
|
||||
|
||||
getdate $f
|
||||
MTIME=$RETURNDATE
|
||||
|
||||
TITLE=`head -n 1 $f`
|
||||
TITLE=${TITLE#"% "}
|
||||
|
||||
OUTPAGE=${f%.md}.html
|
||||
OUTPAGE=${OUTPAGE#pages/blog/}
|
||||
|
||||
echo "<item>"
|
||||
echo "<title>$TITLE</title>"
|
||||
echo "<link>https://rnd.neocities.org/blog/$OUTPAGE</link>"
|
||||
|
||||
if [ $MTIME -gt 0 ]; then
|
||||
RDATE=`date -R -u -d @$MTIME`
|
||||
if [[ "$RDATE" == *UTC ]]; then
|
||||
RDATE="${RDATE%UTC}+0000"
|
||||
fi
|
||||
echo "<pubdate>$RDATE</pubdate>"
|
||||
fi
|
||||
DESCRIPTION="`printcut $f`"
|
||||
if [ $? -eq 0 ]; then
|
||||
DESC_HTML=`echo "$DESCRIPTION" | markdown`
|
||||
echo "<description>$DESC_HTML</description>"
|
||||
fi
|
||||
echo "</item>"
|
||||
|
||||
done
|
||||
|
||||
cat << RSSFOOTER
|
||||
</channel>
|
||||
</rss>
|
||||
RSSFOOTER
|
Loading…
Add table
Reference in a new issue