~nytpu/public-inbox

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH v2] Make the script POSIX-compliant (or at least functional in dash on Debian and ksh on OpenBSD), fix the ':z'-in-updated-tags bug, remove name collision with the toot utility, and submit the user's gemlog's URL to Atenna rather than nytpu's gemlog URL.

Details
Message ID
<20211119213838.11643-1-sr.ht@lyk.so>
DKIM signature
pass
Download raw message
Patch: +33 -27
---
Noticed the hardcoded URL at the end of the script and figured that should be fixed as well.

 gemlog.sh | 60 ++++++++++++++++++++++++++++++-------------------------
 1 file changed, 33 insertions(+), 27 deletions(-)

diff --git a/gemlog.sh b/gemlog.sh
index 09aed60..2c821a2 100755
--- a/gemlog.sh
+++ b/gemlog.sh
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env sh

# Copyright 2020 nytpu
#
@@ -14,6 +14,7 @@
#
# You should have received a copy of the GNU Affero General Public License
# Header and footer file locations can be relative to directory where gemlog.sh is run, or absolute.

export header_file="_header.gmi"
export footer_file="_footer.gmi"
#export header_file="~/.config/gemlog.sh/header.gmi"
@@ -22,27 +23,27 @@ export footer_file="_footer.gmi"
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

make_globals() {
	if [[ -f "$HOME/.config/gemlog.sh/config.sh" ]]; then
		source "$HOME/.config/gemlog.sh/config.sh"
	elif [[ -f "./config.sh" ]]; then
		source "./config.sh"
	if [ -f "$HOME/.config/gemlog.sh/config.sh" ]; then
		. "$HOME/.config/gemlog.sh/config.sh"
	elif [ -f "./config.sh" ]; then
		. "./config.sh"
	else
		printf "No config file!\n"
		exit
	fi

	if [[ ! -f $header_file ]]; then
		printf "No header file matching config.sh value: $header_file"
	if [ ! -f $header_file ]; then
		printf "No header file matching config.sh value: $header_file\n"
		exit
	elif [[ ! -f $footer_file ]]; then
		printf "No footer file matching config.sh value: $footer_file"
	elif [ ! -f $footer_file ]; then
		printf "No footer file matching config.sh value: $footer_file\n"
		exit
	fi


	date_format_8601="+%Y-%m-%dT%H:%M:%S%:z" # *formal* ISO-8601 format including time zone
	date_format_8601_timeless="+%Y-%m-%dT12:00:00%:z" # *formal* ISO-8601 format with fixed preset time
	monthnames=( "invalid" "January" "February" "March" "April" "May" "June" "July" "August" "September" "October" "November" "December" )
	date_format_8601="+%Y-%m-%dT%H:%M:%S%z" # *formal* ISO-8601 format including time zone
	date_format_8601_timeless="+%Y-%m-%dT12:00:00%z" # *formal* ISO-8601 format with fixed preset time
	monthnames="invalid January February March April May June July August September October November December"
}

get_post_title() {
@@ -53,7 +54,7 @@ make_atom() {
	echo "Bulding atom feed..."

	atomfile="$gemlog_feed.$RANDOM"
	while [[ -f $atomfile ]]; do atomfile="$gemlog_feed.$RANDOM"; done
	while [ -f $atomfile ]; do atomfile="$gemlog_feed.$RANDOM"; done

	{
		pubdate=$(date "$date_format_8601")
@@ -75,18 +76,20 @@ make_atom() {
  <rights>© $global_author - $global_license</rights>
EOF
		n=0
		while IFS='' read -r i; do
			((n >= $number_of_feed_articles)) && break
		tz="$(date +%z)"
		find * -type f -name "[[:digit:]]*.gmi" | sort -r \
		| while IFS='' read -r i; do
			expr "$n" '>=' "$number_of_feed_articles" > /dev/null && break
			printf "\n  <entry>\n    <title>"
			get_post_title "$i" | tr -d '\n'
			printf "</title>\n    <id>$global_url${i#'./'}</id>\n"
			printf "    <link rel='alternate' href='$global_url${i#'./'}'/>\n    <updated>"
			echo "$i" | perl -ne '/^(\d{4}-\d{2}-\d{2}).*/; print "$1T12:00:00:z"' | tr -d '\n'
			echo "$i" | perl -ne '/^(\d{4}-\d{2}-\d{2}).*/; print "$1T12:00:00"' | tr -d '\n' | sed "s/\$/$tz/"
			# change or remove the <summary></summary> block if you want a different description or no description at all
			printf "</updated>\n    <summary>You need a gemini client to view this post. $global_url${i#'./'}</summary>\n  </entry>\n"

			n=$(( n + 1 ))
		done < <(find * -type f -name "[[:digit:]]*.gmi" | sort -r)
			n=$(expr "$n" '+' 1)
		done

		printf "</feed>\n"
	} 3>&1 >"$atomfile"
@@ -99,14 +102,15 @@ build_entries() {
	echo "Building index..."

	indexfile="$index.$RANDOM"
	while [[ -f $indexfile ]]; do indexfile="$index.$RANDOM"; done
	while [ -f $indexfile ]; do indexfile="$index.$RANDOM"; done

	{
		# header of the page (above the posts list)
		perl -pe 's/\$(\w+)/$ENV{$1}/g' "$header_file"
		curyear=""
		curmonth=""
		while IFS='' read -r i; do
		find * -type f -name "[[:digit:]]*.gmi" | sort -r \
		| while IFS='' read -r i; do
			post=$(basename $i)
			title=$(get_post_title "$i")
			pubdate=$(echo $i | perl -ne '/^(\d{4}-\d{2}-\d{2}).*/; print $1')
@@ -121,13 +125,13 @@ build_entries() {
				if $use_month_divider_nl; then
					printf "\n"
				elif $use_month_divider_hd; then
					printf "\n### ${monthnames[${newcurmonth#0}]}\n\n"
					printf "\n### $(echo "$monthnames" | cut -d' ' -f${newcurmonth#0})\n\n"
				fi
				curmonth="$newcurmonth"
			fi

			printf "=> $post $pubdate — $title\n"
		done < <(find * -type f -name "[[:digit:]]*.gmi" | sort -r)
		done

		# footer of the page (below the list of posts)
		perl -pe 's/\$(\w+)/$ENV{$1}/g' "$footer_file"
@@ -137,11 +141,12 @@ build_entries() {
	chmod 644 "$index"
}

toot() {
toot_prompt() {
	filename=$(find * -type f -name "[[:digit:]]*.gmi" | sort -r | head -n 1 | xargs basename)
	title=$(get_post_title "$filename")
	read -r -p "do you want to toot the newest post? [y/N] " response
	if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]
	printf "do you want to toot the newest post? [y/N] "
	read response
	if echo "$response" | grep -Eqi '^yes$|^y$'
	then
		echo "tooting..."
		# change this if you want the toot to have different content
@@ -152,6 +157,7 @@ toot() {
make_globals
make_atom
build_entries
toot
toot_prompt

gemget -o - "gemini://warmedal.se/~antenna/submit?gemini%3A%2F%2Fnytpu.com%2Fgemlog%2F"
urlencoded="$(echo -n "$global_url" | perl -MURI::Escape -ne 'print uri_escape($_)')"
gemget -o - "gemini://warmedal.se/~antenna/submit?$urlencoded"
-- 
2.33.1
Details
Message ID
<20211120151705.cv4bfpsujfi4im3u@GLaDOS.local>
In-Reply-To
<20211119213838.11643-1-sr.ht@lyk.so> (view parent)
DKIM signature
pass
Download raw message
I've been meaning to update it myself for some time but knowing how
personal projects go it probably would've been far into the future, so
this is much appreciated!  Thanks so much!

~nytpu

-- 
Alex // nytpu
alex@nytpu.com
gpg --locate-external-key alex@nytpu.com
Reply to thread Export thread (mbox)