From d22b4ec65a67cb5f074493d33670ccf760d235ed Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 8 Dec 2025 13:45:08 +0000 Subject: [PATCH] Adds Neocities deployment script Introduces a build script to automate the deployment process to Neocities. This script: - Reads API key from a `.env` file. - Builds the Hugo site. - Uploads all files to Neocities, displaying a progress bar. - Implements error handling and color-coded output for better visibility. Also includes `.editorconfig` for consistent code formatting, updates `.gitignore` and removes the `PaperMod` submodule. --- .editorconfig | 10 ++++++ .gitignore | 4 ++- .gitmodules | 3 -- build.sh | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 101 insertions(+), 4 deletions(-) create mode 100644 .editorconfig delete mode 100644 .gitmodules create mode 100755 build.sh diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..c79ce2d --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ + +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true \ No newline at end of file diff --git a/.gitignore b/.gitignore index 19f2b50..5796af3 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,6 @@ hugo.exe hugo.linux -hugo.darwin \ No newline at end of file +hugo.darwin + +.env \ No newline at end of file diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 89af1b0..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "themes/PaperMod"] - path = themes/PaperMod - url = https://github.com/adityatelange/hugo-PaperMod.git diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..a2db556 --- /dev/null +++ b/build.sh @@ -0,0 +1,88 @@ +#!/bin/bash + +# Load environment variables from .env file +if [ -f .env ]; then + export $(cat .env | grep -v '^#' | xargs) +else + echo -e "${RED}Error: .env file not found!${NC}" + exit 1 +fi + +# Check if API key is set +if [ -z "$NEOCITIES_API_KEY" ]; then + echo -e "${RED}Error: NEOCITIES_API_KEY not set in .env file!${NC}" + exit 1 +fi + +# Colors +GREEN='\033[0;32m' +RED='\033[0;31m' +BLUE='\033[0;34m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color + +echo -e "${BLUE}Removing existing files...${NC}" +rm -rf public/ + +# Build the Hugo site +echo -e "${BLUE}Building Hugo site...${NC}" +hugo + +if [ $? -ne 0 ]; then + echo -e "${RED}Hugo build failed!${NC}" + exit 1 +fi + +echo -e "${GREEN}✓ Hugo build successful!${NC}" +echo "" + +# Count total files +cd public +total_files=$(find . -type f | wc -l) +current=0 + +echo -e "${BLUE}Uploading $total_files files to Neocities...${NC}" +echo "========================================" +echo "" + +# Upload files using the API +find . -type f | while read file; do + cleanfile="${file#./}" + ((current++)) + + # Calculate progress percentage + percentage=$((current * 100 / total_files)) + + # Create progress bar with simple characters + filled=$((percentage / 2)) + empty=$((50 - filled)) + bar=$(printf "%${filled}s" | tr ' ' '=') + space=$(printf "%${empty}s" | tr ' ' '-') + + # Upload and capture response + response=$(curl -s -H "Authorization: Bearer $NEOCITIES_API_KEY" \ + -F "$cleanfile=@$file" \ + "https://neocities.org/api/upload") + + # Parse result from JSON - check if response contains "success" + if echo "$response" | grep -q '"result"[[:space:]]*:[[:space:]]*"success"'; then + result="success" + else + result="error" + fi + + # Display progress with color + printf "[${YELLOW}%s${NC}%s] %3d%% (%d/%d) " "$bar" "$space" "$percentage" "$current" "$total_files" + + # Show file status + if [ "$result" = "success" ]; then + echo -e "${GREEN}✓${NC} $cleanfile" + else + echo -e "${RED}✗${NC} $cleanfile - ERROR" + echo " Response: $response" + fi +done + +echo "" +echo "========================================" +echo -e "${GREEN}✓ Deployment complete!${NC}" \ No newline at end of file