Compare commits

..

No commits in common. "1bb05ad1fc9b5dc0d56e400e339b0890c9b7645b" and "a13d4dd824aafcbbffc4715c9fd8c322f4f771ce" have entirely different histories.

2 changed files with 11 additions and 43 deletions

View File

@ -1,24 +1,13 @@
# The Music in Noise (Source Code)
This is the source code for my personal website, [The Music in
Noise](https://themusicinnoise.net/). The website is statically generated in
spite of being written in PHP and is compiled with a helpful little script I
wrote, `phpsg.sh`, which compiles all the code to a static website.
## Building
Dependencies:
- Bash
- PHP
- GNU Parallel
Build using the `phpsg.sh` script.
Noise](https://themusicinnoise.net/).
## Licensing
All documents generated by the website are licensed [CC-BY-ND 4.0
International](https://creativecommons.org/licenses/by-nd/4.0/deed.en). The
source code itself is All Rights Reserved unless otherwise specified (e.g. the
build script). The main reason I publish this is so people can see _how_ I make
my website and (if they are so inspired) copy the model, _not the content_.
build script). The main reason I publish this is so people can see __how__ I
make my website and (if they are so inspired) copy the model, __not the
content__.

View File

@ -22,17 +22,14 @@
# 3. This notice may not be removed or altered from any source
# distribution.
set -euo pipefail
SOURCE_DIR="src"
OUTPUT_DIR="output"
JOBS=1
function print_usage() {
echo "$0 [-o <output dir>] [-s <source dir>] [-j <num>]"
echo "$0 [-o <output dir>] [-s <source dir>]"
}
while getopts "o:s:j:h" opt
while getopts "o:s:h" opt
do
case "$opt" in
o)
@ -41,15 +38,6 @@ do
s)
SOURCE_DIR="${OPTARG}"
;;
j)
JOBS="${OPTARG}"
if ! [[ $JOBS =~ ^[0-9]+$ ]]
then
>&2 echo "Jobs option '$JOBS' is not an integer."
print_usage
exit 1
fi
;;
h)
print_usage
exit
@ -61,10 +49,6 @@ do
esac
done
# Make these variables visible within parallel
export OUTPUT_DIR
export SOURCE_DIR
while IFS= read -r -d '' dir
do
OUT_DIR="${OUTPUT_DIR}/${dir:${#SOURCE_DIR}}"
@ -74,14 +58,14 @@ do
fi
done < <(find "$SOURCE_DIR" -mindepth 1 -type d -print0)
function process_file() {
file="$1"
while IFS= read -r -d '' file
do
if [[ $file = *.php ]]
then
DEST_FILE="${OUTPUT_DIR}/${file:${#SOURCE_DIR}:-4}"
if ! [ "$file" -nt "$DEST_FILE" ]
then
return
continue
fi
echo -n "Generating $DEST_FILE ... "
php "$file" > "$DEST_FILE"
@ -90,15 +74,10 @@ function process_file() {
DEST_FILE="${OUTPUT_DIR}/${file:${#SOURCE_DIR}}"
if ! [ "$file" -nt "$DEST_FILE" ]
then
return
continue
fi
echo -n "Copying target $DEST_FILE ... "
cp "$file" "$DEST_FILE"
echo "done"
fi
}
# Make function usable to parallel
export -f process_file
find "$SOURCE_DIR" -type f -not -name '*.cfg.php' |
parallel -j"${JOBS}" process_file
done < <(find "$SOURCE_DIR" -type f -not -name '*.cfg.php' -print0)