-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* . * works * use tagged image
- Loading branch information
Showing
6 changed files
with
88 additions
and
40 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,97 @@ | ||
#!/bin/bash | ||
|
||
echo "Creating symbolic link /workspace to $(pwd)" | ||
ln -s "$(pwd)" /workspace | ||
|
||
php-fpm -D | ||
service nginx start | ||
# Create a symbolic link to the current directory | ||
# if it doesn't exist | ||
if [[ ! -L "/workspace" ]]; then | ||
echo "Creating symbolic link /workspace to $(pwd)" | ||
ln -s "$(pwd)" /workspace | ||
fi | ||
|
||
host=$(jq -r '.hostname' config.json) | ||
# Check if php-fpm is running | ||
if ! pgrep "php-fpm" > /dev/null; then | ||
php-fpm -D | ||
fi | ||
|
||
if ! grep -qF "$host" "/etc/hosts"; then | ||
echo "$host" >> "/etc/hosts" | ||
# Check if nginx is running | ||
if ! pgrep "nginx" > /dev/null; then | ||
service nginx start | ||
fi | ||
|
||
echo 127.0.0.1 "$host" >> /etc/hosts | ||
hostname=$(jq -r '.hostname' config.json) | ||
|
||
rm -rf html | ||
mkdir -p html | ||
if ! grep -qF "$hostname" "/etc/hosts"; then | ||
echo "$hostname" >> "/etc/hosts" | ||
fi | ||
|
||
echo 127.0.0.1 "$hostname" >> /etc/hosts | ||
|
||
# Curl the URL $1 and save it to $2 | ||
function curl_and_save() { | ||
echo Hitting URL "$1" | ||
curl -k "$1" > "$2" | ||
echo "curl_and_save https://$hostname$1 > $2" | ||
curl -ks --fail "https://$hostname$1" > "$2" | ||
|
||
# Check if the file exists and is not zero bytes | ||
if [[ ! -s $2 ]]; then | ||
echo "Error: The file does not exist or is zero bytes." | ||
exit 1 | ||
fi | ||
|
||
# Check if the file is missing the specific text string | ||
if ! grep -q "<!-- Built with Ata's SSG https://www.github.com/atas/ssg -->" "$2"; then | ||
echo "Error: The file does not contain the attribution HTML comment OR something else is wrong in the output. As the MIT license requirement, please do not remove it to help other fellow developers discover this neat tool." | ||
# Check if file exists | ||
if [[ ! -e "$2" ]]; then | ||
echo "Error: File $2 does not exist." | ||
exit 1 | ||
fi | ||
|
||
# Check if file size is zero | ||
if [[ ! -s "$2" ]]; then | ||
echo "Error: File $2 is empty." | ||
exit 1 | ||
fi | ||
} | ||
|
||
curl_and_save "https://$host/" "html/index.html" | ||
#region Building HTML files | ||
rm -rf html | ||
mkdir -p html | ||
|
||
# generate html from all md files at pages directory | ||
# pages/*.md HTML BUilding | ||
for file in pages/*.md; do | ||
filename=$(basename "$file" .md) | ||
curl_and_save "https://$host/$filename" "html/$filename.html" | ||
curl_and_save "/$filename" "html/$filename.html" | ||
done | ||
|
||
# generate html from all php files at home directory except index.php, page.php and post.php | ||
for file in *.php; do | ||
if [[ "$file" != "index.php" && "$file" != "page.php" && "$file" != "post.php" ]]; then | ||
filename=$(basename "$file" .php) | ||
curl_and_save "https://$host/$filename" "html/$filename.html" | ||
fi | ||
done | ||
|
||
# generate html from all md files at posts directory | ||
# posts/*.md HTML Building | ||
mkdir -p html/p | ||
for file in posts/*.md; do | ||
filename=$(basename "$file" .md) | ||
slug=$(awk -F': ' '/^slug:|^[ \t]*"slug":/ {gsub(/["\r]/, "", $2); print $2}' $file) | ||
curl_and_save "https://$host/p/$slug" "html/p/$slug.html" | ||
curl_and_save "/p/$slug" "html/p/$slug.html" | ||
done | ||
|
||
# **/*.php Any php file HTML Building | ||
find . -name "*.php" ! -path "./system/*" ! -path "./vendor/*" ! -path "./layout/*" | while read -r file; do | ||
file="${file#./}" #Remove the leading ./ | ||
if [[ "$file" == "page.php" || "$file" == "post.php" ]]; then #pages and posts are handled above separately | ||
continue; | ||
fi | ||
|
||
without_extension="${file%.*}" | ||
# Replace the .php extension with .txt | ||
html_file="html/${file%.php}.html" | ||
|
||
# Create the directory structure if it doesn't exist | ||
mkdir -p "$(dirname "$html_file")" | ||
|
||
filename=$(basename "$file" .php) | ||
curl_and_save "/$without_extension" "$html_file" | ||
done | ||
|
||
#endregion | ||
|
||
# ./assets/* copying to ./html | ||
cp -R assets html/assets | ||
# Build CSS | ||
lessc html/assets/styles/style.less html/assets/styles/style.css | ||
|
||
# Remove .less as .css file is built | ||
rm -f html/assets/styles/*.less | ||
|
||
# Robots.txt is good to have | ||
cp robots.txt html/ |
This file contains 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
This file contains 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