From 676ebc1e4478f422f980c264d38154a43f28e531 Mon Sep 17 00:00:00 2001 From: Tracey Jaquith Date: Sun, 14 Jul 2024 18:07:06 -0400 Subject: [PATCH] better/more jq usage --- bin/sitemap | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bin/sitemap b/bin/sitemap index 562d3b0..e0814a2 100755 --- a/bin/sitemap +++ b/bin/sitemap @@ -96,18 +96,18 @@ function rss() { # xxx using snippet?? function comments() { + # this helps with efficiency but could be replaced with a lot of requests at runtime in the browser ( mkdir -p comments cd comments find . -mindepth 1 -type d |cut -b3- |sort -o index.txt for DIR in $(cat index.txt); do OUT=$DIR/index.json - echo '[' >| $OUT - for JSON in $(ls $DIR | grep -Ev '^index.json$'); do - cat "$DIR/$JSON" >> $OUT - echo ",\n" >> $OUT - done - echo "\n{}\n]" >> $OUT + rm -f $OUT + jq -rs '. | map(.)' $DIR/*.json \ + | jq '.[] | del(.replyThread) | with_entries(if .key == "_id" then .key = "id" else . end)' \ + | jq -s 'flatten(1)' \ + > $OUT done ) }