41 lines
No EOL
1 KiB
Bash
41 lines
No EOL
1 KiB
Bash
#!/bin/bash
|
|
#Name : gatsbyfeed
|
|
#Usage : Extract jsonfeed from gatsbyjs agenda
|
|
#Url example : https://example.com/page-data/actualites/page-data.json
|
|
|
|
function to_feed(){
|
|
home_page_url=$(echo "$link" | sed -E 's|^(https?://[^/]+).*|\1|')
|
|
title=$(echo "$home_page_url" | sed -E 's|https?://||; s|www\.||; s|\..*||' | tr '[:lower:]' '[:upper:]')
|
|
|
|
|
|
curl -s "$link" | jq --arg home_page_url "$home_page_url" --arg title "$title" '
|
|
{
|
|
version: "https://jsonfeed.org/version/1.1",
|
|
title: $title,
|
|
home_page_url: $home_page_url,
|
|
feed_url: "\($home_page_url)/feed.json",
|
|
items: [.result.data.allNodeActualites.edges[] | {
|
|
title: .node.title,
|
|
url: "\($home_page_url)\(.node.path.alias)",
|
|
content_html: .node.body.processed
|
|
}]
|
|
}
|
|
'
|
|
}
|
|
|
|
while [[ $# -gt 0 ]]
|
|
do
|
|
case "$1" in
|
|
https://*.json|http://*.json)
|
|
link="$1"
|
|
;;
|
|
--help|*)
|
|
echo "gatsbyfeed : URL manquante"
|
|
echo "Usage : gatsbyfeed URL"
|
|
exit 1
|
|
;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
to_feed "$link" |