Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
atas committed Oct 13, 2023
1 parent 966b227 commit 038ee28
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 24 deletions.
69 changes: 45 additions & 24 deletions system/bin/generate_html.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@
echo "Creating symbolic link /workspace to $(pwd)"
ln -s "$(pwd)" /workspace

php-fpm -D
service nginx start

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

function curl_and_save() {
echo Hitting URL "$1"
Expand All @@ -34,33 +38,50 @@ function curl_and_save() {
fi
}

curl_and_save "https://$host/" "html/index.html"
curl_and_save "https://$hostname/" "html/index.html"

# generate html from all md files at pages directory
#region Building HTML files
rm -rf html
mkdir -p html

# pages/*.md HTML BUilding
for file in pages/*.md; do
filename=$(basename "$file" .md)
curl_and_save "https://$host/$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
curl_and_save "https://$hostname/$filename" "html/$filename.html"
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 "https://$hostname/p/$slug" "html/p/$slug.html"
done

# **/*.php Any php file HTML Building
find . -name "*.php" ! -path "./system/*" | while read -r file; do
if [[ "$file" == "index.php" || "$file" == "page.php" || "$file" != "post.php" ]]; then
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 "https://$hostname/$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/
1 change: 1 addition & 0 deletions system/workflow-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ RUN apt-get update && apt-get install -y \
node-less \
git \
jq \
procps \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install gd pdo_mysql

Expand Down

0 comments on commit 038ee28

Please sign in to comment.