Compare commits

...

2 Commits

Author SHA1 Message Date
5f57ee1bcd test build 2025-06-01 12:09:01 +03:00
d7d238dfb0 test build.sh 2025-06-01 12:07:10 +03:00

108
build.sh
View File

@ -1,91 +1,47 @@
#!/bin/bash
echo "🚀 Starting build..."
set -e
echo "🧹 Cleaning build folders..."
rm -rf public static/css
SOURCE=${BASH_SOURCE[0]}
DIR_OF_THIS_SCRIPT="$( dirname "$SOURCE" )"
ABS_DIR_OF_SCRIPT="$( realpath "$DIR_OF_THIS_SCRIPT" )"
# Detect platform for Tailwind binary
ASSET="tailwindcss"
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
ASSET="$ASSET-linux"
elif [[ "$OSTYPE" == "darwin"* ]]; then
ASSET="$ASSET-macos"
echo "⬇️ Downloading TailwindCSS CLI..."
if [[ -f "tailwindcss.exe" ]]; then
rm tailwindcss.exe
fi
if [[ "$(uname -m)" == "x86_64"* ]]; then
ASSET="$ASSET-x64"
elif [[ "$(uname -m)" == "arm64"* ]]; then
ASSET="$ASSET-arm64"
fi
ASSET="tailwindcss-windows-x64.exe"
curl -sLO "https://github.com/tailwindlabs/tailwindcss/releases/download/v3.4.17/${ASSET}"
mv ${ASSET} tailwindcss.exe
chmod +x tailwindcss.exe
# Get latest Tailwind version from GitHub
LATEST_VERSION=$(curl -s https://api.github.com/repos/tailwindlabs/tailwindcss/releases/latest | grep '"tag_name":' | cut -d '"' -f 4)
# Check current version
CURRENT_VERSION=""
if [[ -f "./tailwindcss" ]]; then
CURRENT_VERSION=$(./tailwindcss -v | awk '{print $2}')
fi
echo "Current Tailwind version: $CURRENT_VERSION"
echo "Latest Tailwind version: $LATEST_VERSION"
# Download Tailwind binary if needed
if [[ "$CURRENT_VERSION" != "$LATEST_VERSION" ]]; then
echo "⬇️ Downloading latest Tailwind..."
rm -f tailwindcss
curl -sLO "https://github.com/tailwindlabs/tailwindcss/releases/download/${LATEST_VERSION}/${ASSET}"
chmod +x $ASSET
mv $ASSET tailwindcss
else
echo "✅ Tailwind is up to date."
fi
# Initialize Tailwind config if needed
# Ensure correct config
if [[ ! -f "tailwind.config.js" ]]; then
echo "🛠 Initializing Tailwind config..."
./tailwindcss init
sed -i.bak "s| content: \[\],| content: \['./templates/**/*.html'\],|g" tailwind.config.js
echo "⚙️ Creating tailwind.config.js"
echo "module.exports = {
content: ['./templates/**/*.html'],
theme: { extend: {} },
plugins: [],
}" > tailwind.config.js
fi
# Ensure static/css exists
mkdir -p static/css
# Build Tailwind CSS
echo "🎨 Building Tailwind CSS..."
./tailwindcss.exe -i css/index.css -o static/css/index.css --minify
# Clean previous build
rm -rf public
# Compile Tailwind
echo "🧵 Building Tailwind CSS..."
# Create a backup of the original CSS file
cp css/index.css css/index.css.bak
# Generate the CSS file with Tailwind
./tailwindcss -i css/index.css -o static/css/index.css --minify
# Check if the generated CSS file is empty or very small
if [ ! -s static/css/index.css ] || [ $(wc -c < static/css/index.css) -lt 1000 ]; then
echo "⚠️ Warning: Generated CSS file is empty or very small. Using backup CSS file."
# If Tailwind fails to generate a proper CSS file, use a pre-generated one
cp css/index.css.bak static/css/index.css
if [[ ! -f "static/css/index.css" ]]; then
echo "❌ Tailwind CSS not generated."
exit 1
fi
# Print the size of the generated CSS file
echo "📏 Generated CSS file size: $(du -h static/css/index.css | cut -f1)"
echo "✅ Tailwind CSS built at static/css/index.css"
# Build Zola site
echo "🏗 Running Zola..."
zola --root "$ABS_DIR_OF_SCRIPT" build
echo "🏗️ Building site with Zola..."
zola build
# Ensure CSS is in the public directory
echo "📋 Ensuring CSS is in public directory..."
mkdir -p public/css
cp static/css/index.css public/css/
# Also copy to the root of public for fallback
echo "📋 Also copying CSS to root of public for fallback..."
cp static/css/index.css public/index.css
echo "✅ Build complete. Check public/ folder."
# Final check
if [[ -f "public/css/index.css" ]]; then
echo "✅ CSS successfully copied to public/"
else
echo "❌ CSS NOT copied to public/. Check Zola static settings."
fi