Compare commits
4 Commits
a13d4dd824
...
1bb05ad1fc
Author | SHA1 | Date | |
---|---|---|---|
1bb05ad1fc | |||
e1b873a2c2 | |||
e489a39328 | |||
8621a25c08 |
19
README.md
19
README.md
@ -1,13 +1,24 @@
|
|||||||
# The Music in Noise (Source Code)
|
# The Music in Noise (Source Code)
|
||||||
|
|
||||||
This is the source code for my personal website, [The Music in
|
This is the source code for my personal website, [The Music in
|
||||||
Noise](https://themusicinnoise.net/).
|
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.
|
||||||
|
|
||||||
## Licensing
|
## Licensing
|
||||||
|
|
||||||
All documents generated by the website are licensed [CC-BY-ND 4.0
|
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
|
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
|
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
|
build script). The main reason I publish this is so people can see _how_ I make
|
||||||
make my website and (if they are so inspired) copy the model, __not the
|
my website and (if they are so inspired) copy the model, _not the content_.
|
||||||
content__.
|
|
||||||
|
35
phpsg.sh
35
phpsg.sh
@ -22,14 +22,17 @@
|
|||||||
# 3. This notice may not be removed or altered from any source
|
# 3. This notice may not be removed or altered from any source
|
||||||
# distribution.
|
# distribution.
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
SOURCE_DIR="src"
|
SOURCE_DIR="src"
|
||||||
OUTPUT_DIR="output"
|
OUTPUT_DIR="output"
|
||||||
|
JOBS=1
|
||||||
|
|
||||||
function print_usage() {
|
function print_usage() {
|
||||||
echo "$0 [-o <output dir>] [-s <source dir>]"
|
echo "$0 [-o <output dir>] [-s <source dir>] [-j <num>]"
|
||||||
}
|
}
|
||||||
|
|
||||||
while getopts "o:s:h" opt
|
while getopts "o:s:j:h" opt
|
||||||
do
|
do
|
||||||
case "$opt" in
|
case "$opt" in
|
||||||
o)
|
o)
|
||||||
@ -38,6 +41,15 @@ do
|
|||||||
s)
|
s)
|
||||||
SOURCE_DIR="${OPTARG}"
|
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)
|
h)
|
||||||
print_usage
|
print_usage
|
||||||
exit
|
exit
|
||||||
@ -49,6 +61,10 @@ do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Make these variables visible within parallel
|
||||||
|
export OUTPUT_DIR
|
||||||
|
export SOURCE_DIR
|
||||||
|
|
||||||
while IFS= read -r -d '' dir
|
while IFS= read -r -d '' dir
|
||||||
do
|
do
|
||||||
OUT_DIR="${OUTPUT_DIR}/${dir:${#SOURCE_DIR}}"
|
OUT_DIR="${OUTPUT_DIR}/${dir:${#SOURCE_DIR}}"
|
||||||
@ -58,14 +74,14 @@ do
|
|||||||
fi
|
fi
|
||||||
done < <(find "$SOURCE_DIR" -mindepth 1 -type d -print0)
|
done < <(find "$SOURCE_DIR" -mindepth 1 -type d -print0)
|
||||||
|
|
||||||
while IFS= read -r -d '' file
|
function process_file() {
|
||||||
do
|
file="$1"
|
||||||
if [[ $file = *.php ]]
|
if [[ $file = *.php ]]
|
||||||
then
|
then
|
||||||
DEST_FILE="${OUTPUT_DIR}/${file:${#SOURCE_DIR}:-4}"
|
DEST_FILE="${OUTPUT_DIR}/${file:${#SOURCE_DIR}:-4}"
|
||||||
if ! [ "$file" -nt "$DEST_FILE" ]
|
if ! [ "$file" -nt "$DEST_FILE" ]
|
||||||
then
|
then
|
||||||
continue
|
return
|
||||||
fi
|
fi
|
||||||
echo -n "Generating $DEST_FILE ... "
|
echo -n "Generating $DEST_FILE ... "
|
||||||
php "$file" > "$DEST_FILE"
|
php "$file" > "$DEST_FILE"
|
||||||
@ -74,10 +90,15 @@ do
|
|||||||
DEST_FILE="${OUTPUT_DIR}/${file:${#SOURCE_DIR}}"
|
DEST_FILE="${OUTPUT_DIR}/${file:${#SOURCE_DIR}}"
|
||||||
if ! [ "$file" -nt "$DEST_FILE" ]
|
if ! [ "$file" -nt "$DEST_FILE" ]
|
||||||
then
|
then
|
||||||
continue
|
return
|
||||||
fi
|
fi
|
||||||
echo -n "Copying target $DEST_FILE ... "
|
echo -n "Copying target $DEST_FILE ... "
|
||||||
cp "$file" "$DEST_FILE"
|
cp "$file" "$DEST_FILE"
|
||||||
echo "done"
|
echo "done"
|
||||||
fi
|
fi
|
||||||
done < <(find "$SOURCE_DIR" -type f -not -name '*.cfg.php' -print0)
|
}
|
||||||
|
# Make function usable to parallel
|
||||||
|
export -f process_file
|
||||||
|
|
||||||
|
find "$SOURCE_DIR" -type f -not -name '*.cfg.php' |
|
||||||
|
parallel -j"${JOBS}" process_file
|
||||||
|
Loading…
x
Reference in New Issue
Block a user