diff options
| author | Paul Buetow <git@mx.buetow.org> | 2021-05-25 22:10:09 +0100 |
|---|---|---|
| committer | Paul Buetow <git@mx.buetow.org> | 2021-05-25 22:10:09 +0100 |
| commit | 2a3fa5b8c749e631d2d7ed1bb01300f023c4b9ea (patch) | |
| tree | 46761b18297bc50e70fb61bef6031b33d5e31db5 /lib/gemfeed.source.sh | |
| parent | b7489882bc82e4266e9cb9845604acdf20857c23 (diff) | |
rename packages to lib1.0.0
Diffstat (limited to 'lib/gemfeed.source.sh')
| -rw-r--r-- | lib/gemfeed.source.sh | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/gemfeed.source.sh b/lib/gemfeed.source.sh new file mode 100644 index 0000000..c842bb1 --- /dev/null +++ b/lib/gemfeed.source.sh @@ -0,0 +1,54 @@ +# Filter out blog posts from other files in the gemfeed dir. +gemfeed::get_posts () { + local -r gemfeed_dir="$CONTENT_BASE_DIR/gemtext/gemfeed" + local -r gmi_pattern='^[0-9]{4}-[0-9]{2}-[0-9]{2}-.*\.gmi$' + local -r draft_pattern='\.draft\.gmi$' + + ls "$gemfeed_dir" | + $GREP -E "$gmi_pattern" | + $GREP -E -v "$draft_pattern" | + sort -r +} + +# Add the links from gemfeed/index.gmi to the main index site. +gemfeed::updatemainindex () { + local -r index_gmi="$CONTENT_BASE_DIR/gemtext/index.gmi" + local -r gemfeed_dir="$CONTENT_BASE_DIR/gemtext/gemfeed" + + log VERBOSE "Updating $index_gmi with posts from $gemfeed_dir" + + # Remove old gemfeeds from main index + $SED '/^=> .\/gemfeed\/[0-9].* - .*/d;' "$index_gmi" > "$index_gmi.tmp" + # Add current gemfeeds to main index + $SED -n '/^=> / { s| ./| ./gemfeed/|; p; }' "$gemfeed_dir/index.gmi" >> "$index_gmi.tmp" + + mv "$index_gmi.tmp" "$index_gmi" + git::add gemtext "$index_gmi" +} + +# Generate a index.gmi in the ./gemfeed subdir. +gemfeed::generate () { + local -r gemfeed_dir="$CONTENT_BASE_DIR/gemtext/gemfeed" + log INFO "Generating Gemfeed index for $gemfeed_dir" + +cat <<GEMFEED > "$gemfeed_dir/index.gmi.tmp" +# $DOMAIN's Gemfeed + +## $SUBTITLE + +GEMFEED + + gemfeed::get_posts | while read -r gmi_file; do + # Extract first heading as post title. + local title=$($SED -n '/^# / { s/# //; p; q; }' "$gemfeed_dir/$gmi_file" | tr '"' "'") + # Extract the date from the file name. + local filename_date=$(basename "$gemfeed_dir/$gmi_file" | cut -d- -f1,2,3) + + echo "=> ./$gmi_file $filename_date - $title" >> "$gemfeed_dir/index.gmi.tmp" + done + + mv "$gemfeed_dir/index.gmi.tmp" "$gemfeed_dir/index.gmi" + git::add gemtext "$gemfeed_dir/index.gmi" + + gemfeed::updatemainindex +} |
