diff options
-rwxr-xr-x | gen | 49 | ||||
-rwxr-xr-x | ssg5 | 4 | ||||
-rwxr-xr-x | tools/rssg | 189 |
3 files changed, 44 insertions, 198 deletions
diff --git a/gen b/gen index 04ac0cc..fd94db9 100755 --- a/gen +++ b/gen @@ -1,13 +1,36 @@ #!/bin/sh +TITLE="19 PDH Puszcza" +URL="https://nojs--api-puszcza.netlify.app" +DESCRIPTION="" + rm -r dest || true mkdir dest # This is useful when deploying on netlify. Thanks to storing compiled binaries # in this folder they will be cached and restored. -export PATH="$PWD/.jekyll-cache:$PATH" +export PATH="$PWD/.jekyll-cache:$PWD/tools:$PATH" ./tools/compile +post_rss() { + path="$URL$1" + title=$2 + photo=$3 + description=$4 + file=$5 + date=`git log -n 1 --date="format:%Y-%m-%dT%H:%M:%SZ" --pretty=format:'%ad' -- $file` + cat << EOF + <item> + <guid>$path</guid> + <link>$path</link> + <pubDate>$date</pubDate> + <title>$title</title> + <description><![CDATA[ + $(lowdown-f $file) + ]]></description> + </item> +EOF +} post_link() { path=$1 @@ -33,10 +56,22 @@ cat > wpisy/kronika.html << EOF <link href="/kronika.css" rel="stylesheet"> <h2>Ostatnie wpisy</h2> -<a href="rss.xml"><img alt="" src="/assets/rss.svg" style="height:1em">RSS</a> +<a href="/kronika/rss.xml"><img alt="" src="/assets/rss.svg" style="height:1em">RSS</a> <div class="content post-list"> EOF +mkdir -p dest/kronika +cat > dest/kronika/rss.xml << EOF +<?xml version="1.0" encoding="UTF-8"?> +<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> +<channel> +<atom:link href="$URL/kronika/rss.xml" rel="self" type="application/rss+xml" /> +<title>$TITLE</title> +<description>$DESCRIPTION</description> +<link>$URL</link> +<lastBuildDate>$(date -R)</lastBuildDate> +EOF + i=0 for f in `find wpisy/kronika/20* -name '*.md' | sort -r`; do path=`echo $f | sed 's/wpisy//;s/.md//'` @@ -45,12 +80,14 @@ for f in `find wpisy/kronika/20* -name '*.md' | sort -r`; do [ -z $photo ] && photo="/assets/default_tree.jpg" description=`grep -E "^[A-Z]" $f | grep -v "|" | head -n 1 | cut -d" " -f1-30` post_link "$path" "$title" "$photo" "$description" >> wpisy/kronika.html - [ $i -lt 4 ] && \ + [ $i -lt 20 ] && \ + post_rss "$path" "$title" "$photo" "$description" "$f" >> dest/kronika/rss.xml + # [ $i -lt 4 ] && \ # post_link "$path" "$title" "$photo" "$description" >> wpisy/index.md && \ - i=$(($i+1)) + i=$(($i+1)) done echo "</div>" >> wpisy/kronika.html +echo "</channel></rss>" >> dest/kronika/rss.xml -./ssg5 wpisy dest "19 PDH Puszcza" "https://19.niedzwiedzinski.cyou" +./ssg5 wpisy dest "$TITLE" "$URL" cp -r static/* dest -./tools/rssg dest/kronika/index.html "19 PDH Puszcza" > dest/rss.xml diff --git a/ssg5 b/ssg5 index 84311e4..67736d6 100755 --- a/ssg5 +++ b/ssg5 @@ -201,9 +201,7 @@ render_md_files_lowdown() { echo "<article class="kronika">" > $in || \ echo "<article>" > $in - # Filter out frontmatter - tail -n +$(($(sed -n '/---/,/---/p' $1/$f | wc -l)+1)) $1/$f | \ - lowdown --html-no-skiphtml --html-no-escapehtml >> $in && \ + lowdown-f "$1/$f" >> $in && \ echo "</article>" >> $in cat "$in" | diff --git a/tools/rssg b/tools/rssg deleted file mode 100755 index 52031e7..0000000 --- a/tools/rssg +++ /dev/null @@ -1,189 +0,0 @@ -#!/bin/sh -# -# https://www.romanzolotarev.com/bin/rssg -# Copyright 2018 Roman Zolotarev <hi@romanzolotarev.com> -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# -set -e - - -main () { - test -n "$1" || usage - test -n "$2" || usage - test -f "$1" || no_file "$1" - - - index_file=$(readlink -f "$1") - test -z "${index_file##*html}" && html=$(cat "$index_file") - test -z "${index_file##*md}" && html=$(md_to_html "$index_file") - test -n "$html" || usage - - base="${index_file%/*}" - base_url="$(echo "$html" | get_url | sed 's#\(.*\)/[^/]*#\1#')" - - url=$( echo "$html" | get_url) - - title="$2" - - description=$( echo "$html" | get_description | - remove_tags | - remove_nbsp ) - - items=$( echo "$html" | get_items) - - rss=$( echo "$items" | - render_items "$base" "$base_url" | - render_feed "$url" "$title" "$description") - - >&2 echo "[rssg] ${index_file##$(pwd)/} $(echo "$rss" | grep -c '<item>') items" - echo "$rss" -} - - -usage() { - echo "usage: ${0##*/} index.{html,md} title > rss.xml" >&2 - exit 1 -} - - -no_file() { - echo "${0##*/}: $1: No such file" >&2 - exit 2 -} - - -md_to_html() { - test -x "$(which lowdown)" || exit 3 - lowdown \ - -D html-skiphtml \ - -D smarty \ - -d metadata \ - -d autolink "$1" -} - - -get_title() { - awk 'tolower($0)~/^<h1/{gsub(/<[^>]*>/,"",$0);print;exit}' -} - - -get_url() { - grep -i '<a .*rss.xml"' | head -1 | - sed 's#.*href="\(.*\)".*#\1#' -} - - -get_items() { - grep -i 'href=".*" title="' | - sed 's#.*href="\(.*\)" title="\(.*\)">\(.*\)</a>.*#\1 \2 \3#' -} - - -get_description() { - start='sub("^.*<"s"*"t"("s"[^>]*)?>","")' - stop='sub("</"s"*"t""s"*>.*","")&&x=1' - awk -v 's=[[:space:]]' -v 't=[Pp]' "$start,$stop;x{exit}" -} - -remove_tags() { - sed 's#<[^>]*>##g;s#</[^>]*>##g' -} - - -remove_nbsp() { - sed 's#\ # #g' -} - - -rel_to_abs_urls() { - site_url="$1" - base_url="$2" - - abs='s#(src|href)="/([^"]*)"#\1="'"$site_url"/'\2"#g' - rel='s#(src|href)="([^:/"]*)"#\1="'"$base_url"/'\2"#g' - sed -E "$abs;$rel" -} - - -date_rfc_822() { - date -j '+%a, %d %b %Y %H:%M:%S %z' \ - "$(echo "$1"| tr -cd '[:digit:]')0000" -} - - -render_items() { - while read -r i - do render_item "$1" "$2" "$i" - done -} - - -render_item() { - base="$1" - base_url="$2" - item="$3" - - site_url="$(echo "$base_url"| sed 's#\(.*//.*\)/.*#\1#')" - - date=$(echo "$item"|awk '{print$2}') - url=$(echo "$item"|awk '{print$1}') - - f="$base/$url" - test -f "$f" && html=$(cat "$f") - test -f "${f%\.html}.md" && html=$(md_to_html "${f%\.html}.md") - - description=$( - echo "$html" | - rel_to_abs_urls "$site_url" "$base_url" | - remove_nbsp - ) - title=$(echo "$description" | get_title) - guid="$base_url/$(echo "$url" | sed 's#^/##')" - - echo ' -<item> -<guid>'"$guid"'</guid> -<link>'"$guid"'</link> -<pubDate>'"$(date_rfc_822 "$date")"'</pubDate> -<title>'"$title"'</title> -<description><![CDATA[ - -'"$description"' - -]]></description> -</item>' -} - - -render_feed() { - url="$1" - title=$(echo "$2" | remove_nbsp) - description="$3" - - base_url="$(echo "$url" | cut -d '/' -f1-3)" - - echo '<?xml version="1.0" encoding="UTF-8"?> -<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> -<channel> -<atom:link href="'"$url"'" rel="self" type="application/rss+xml" /> -<title>'"$title"'</title> -<description>'"$description"'</description> -<link>'"$base_url"'/</link> -<lastBuildDate>'"$(date_rfc_822 date)"'</lastBuildDate> -'"$(cat)"' -</channel></rss>' -} - - -main "$@" |