JAQ?=jaq

subscriptions.txt: subscriptions.json
	$(JAQ) --raw-output '.[]' subscriptions.json > $@

subscriptions.curl: subscriptions.json
	$(JAQ) --raw-output '.[] | (split("/") | last) as $$name | "url \(.)\noutput \($$name).html"' subscriptions.json > $@

fetch: subscriptions.curl
	curl --location --output-dir html --create-dirs --rate 1/s --config subscriptions.curl

channel-json: subscriptions.txt
	# nproc is not portable :-/
	xargs -n1 --max-procs=$$(nproc) --arg-file subscriptions.txt --verbose ./generate-json-opml

# turn all the channel json files into an OPML file
subscriptions.opml:
	./generate-opml > $@

.PHONY: channel-json subscriptions.opml