website/bin/openring-create
Gabriel Arazas 98124f0479 Update a bunch of stuff
* The 'Moving into NixOS' post has been restructured.
* The images folder is now referred to as the assets folder as it can
contain other than images. (Why didn't I think about this before?)
* 'bin/openring-create' is revamped.
* Minor styling tweaks.
* The Makefile has been updated to reflect the change of
'bin/openring-create'.
2020-11-10 01:53:52 +08:00

80 lines
1.7 KiB
Bash

#!/usr/bin/env bash
function help() {
cat << HELP
Simply creates an output from an openring template.
Usage: [options] [input_file]
Options:
-h, --help Help.
-l, --limit The number of posts to be shown.
-d, --data The file path of a JSON file containing an
array of URLs (as strings).
-o, --output The output file path.
If there's no output value given, the resulting
output name will be '\$INPUT.out'.
-i, --input The input file path.
HELP
}
# The default values.
LIMIT=5
INPUT_TEMPLATE="./assets/templates/openring-input.html"
input_file=$(basename "$INPUT_TEMPLATE")
input_file_ext="${input_file##*.}"
input_file="${input_file%.*}"
OUTPUT="$input_file.out.$input_file_ext"
DATA="data/blogs.json"
while [[ "$#" -gt 0 ]]; do
case "$1" in
-h|--help)
help
exit 0
;;
-l|--limit)
LIMIT="$2"
shift
shift
;;
-d|--data)
DATA="$2"
shift
shift
;;
-o|--output)
OUTPUT="$2"
shift
shift
;;
-i|--input)
INPUT_TEMPLATE="$2"
shift
shift
;;
*)
INPUT_TEMPLATE="$1"
shift
;;
esac
done
# Checks whether it is locally compiled or not.
if [[ -a ./openring ]]; then
OPENRING="./openring/openring";
else
OPENRING="openring";
fi
for feed in $(jq ".[]" "$DATA" | shuf --head-count $LIMIT); do
OPENRING="$OPENRING -s $feed";
done
OPENRING="$OPENRING -n $LIMIT < $INPUT_TEMPLATE > $OUTPUT"
echo "$OPENRING"
eval $OPENRING