gen-chroma-styles.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/bash
  2. set -eo pipefail
  3. HUGO="npx hugo"
  4. CHROMA_STYLE=tango
  5. DEST_DIR=assets/scss/td/chroma
  6. DEST_FILE=_light.scss
  7. DEST_PATH=/dev/null # Set in process_CLI_args
  8. function _usage() {
  9. cat <<EOS
  10. Usage: `basename $0` [options]
  11. Generate CSS for the named Chroma style using Hugo.
  12. -h Output this usage info.
  13. -o FILE Output file name relative to $DEST_DIR.
  14. Default: $DEST_FILE.
  15. -s STYLE Chroma style name from list at
  16. https://xyproto.github.io/splash/docs
  17. Default: $CHROMA_STYLE.
  18. EOS
  19. }
  20. function usage() {
  21. local status=${1:-0}
  22. _usage 1>&2
  23. exit $status
  24. }
  25. function process_CLI_args() {
  26. while getopts ":ho:s:" opt; do
  27. case $opt in
  28. h)
  29. usage
  30. ;;
  31. o)
  32. DEST_FILE="$OPTARG"
  33. ;;
  34. s)
  35. CHROMA_STYLE="$OPTARG"
  36. ;;
  37. \?)
  38. echo "ERROR: unrecognized flag: -$OPTARG"
  39. usage 1;
  40. ;;
  41. esac
  42. done
  43. shift $((OPTIND-1))
  44. if [ "$#" -gt 0 ]; then
  45. echo "ERROR: extra argument(s): $*" >&2
  46. usage 1;
  47. fi
  48. DEST_PATH="$DEST_DIR/$DEST_FILE"
  49. }
  50. function main() {
  51. process_CLI_args "$@"
  52. # For more options, see https://gohugo.io/commands/hugo_gen_chromastyles/
  53. local cmd="$HUGO gen chromastyles --style=$CHROMA_STYLE >> $DEST_PATH"
  54. echo "Generating $DEST_FILE using: $cmd"
  55. echo "/* Chroma style: $CHROMA_STYLE */" > $DEST_PATH
  56. eval "$cmd"
  57. }
  58. main "$@"