Last active
January 16, 2022 22:45
-
-
Save nmpowell/9fb5c1b39d5fbbc64fc557465fee611b to your computer and use it in GitHub Desktop.
Please BUILD rules for Hugo static site generation. See https://please.build/ for initial setup. Ensure hugo is on your PATH. Then use this file (name it BUILD) in the root of your Hugo project directory to build the site and copy files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Zipped | |
sh_cmd( | |
name = "build_hugo_zip_and_copy", | |
# srcs = [":hugo_public_zip"], | |
# Must escape newly defined env vars within the script to avoid Please expanding them at build time | |
cmd = [ | |
"DEST=/home/username/hugo_site.com", | |
"mkdir -p \\\$DEST", | |
"cp -r $(out_location :hugo_public_zip) \\\$DEST", | |
], | |
data = [":hugo_public_zip"], | |
) | |
# Unzipped | |
sh_cmd( | |
name = "build_hugo_and_copy", | |
# Must escape newly defined env vars within the script to avoid Please expanding them at build time | |
cmd = [ | |
"DEST=/home/username/hugo_site.com", | |
"mkdir -p \\\$DEST", | |
"cp -r $(out_location :hugo)/* \\\$DEST", | |
], | |
data = [":hugo"], | |
) | |
genrule( | |
name = "hugo_public_zip", | |
srcs = [":hugo|final"], # refer to specific OUT from the :hugo rule | |
outs = ["public.zip"], | |
cmd = "zip -r $OUTS $SRCS", | |
) | |
# Must ensure hugo is on your path | |
genrule( | |
name = "hugo", | |
srcs = glob( | |
["config.toml", "**/*"], | |
exclude = [".git*", "public"], | |
), | |
outs = { | |
"final": ["public"], | |
}, | |
tools = { | |
"hugo": [ | |
"hugo", | |
], | |
}, | |
# NB you can call the temp dir $OUT.temp or $.temp | |
# You can also join these commands with "&&" | |
cmd = [ | |
"mkdir -p $OUT.temp $OUTS_FINAL", | |
"cp -r --parents $SRCS $OUT.temp", | |
"cd $OUT.temp", | |
"$TOOLS_HUGO -D --source . --destination ../$OUTS_FINAL", | |
] | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment