Compare commits

..

2 Commits

7 changed files with 135 additions and 29 deletions

View File

@@ -1,38 +1,76 @@
# sv
# jnss-web
Everything you need to build a Svelte project, powered by [`sv`](https://github.com/sveltejs/cli).
Static website for jnss.me - built with SvelteKit and deployed via Caddy.
## Creating a project
## Project Structure
If you're seeing this, you've probably already done this step. Congrats!
This project uses a **two-branch deployment strategy**:
- **`main` branch**: Source code and development
- Contains all source files, configuration, and build tooling
- `build/` directory is gitignored
- **`deploy` branch**: Orphan branch with build outputs only
- Contains only the static build artifacts (index.html, _app/, etc.)
- No source code or build dependencies
- Used by Ansible/Caddy for serving the site
## Development
Install dependencies:
```sh
# create a new project in the current directory
npx sv create
# create a new project in my-app
npx sv create my-app
bun install
```
## Developing
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
Start development server:
```sh
npm run dev
bun run dev
# or start the server and open the app in a new browser tab
npm run dev -- --open
# or open in browser automatically
bun run dev -- --open
```
## Building
To create a production version of your app:
Build the static site:
```sh
npm run build
bun run build
```
You can preview the production build with `npm run preview`.
Preview the production build locally:
```sh
bun run preview
```
> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.
## Deployment
This project uses an automated deployment script that builds and pushes to the `deploy` branch:
```sh
# Deploy with auto-generated timestamp commit message
./deploy.sh
# Deploy with custom commit message
./deploy.sh "Add new feature X"
```
**What the script does:**
1. Builds the site on the `main` branch (`bun run build`)
2. Switches to the `deploy` branch
3. Clears old build files
4. Moves new build output to the root of `deploy` branch
5. Commits and pushes to `origin/deploy`
6. Switches back to `main` branch
**For rick-infra:**
The Ansible role clones the `deploy` branch to get production-ready static files:
```sh
git clone -b deploy git@jnss.me:joakim/jnss-web.git
```
## Tech Stack
- **Framework**: SvelteKit 2.x with static adapter
- **Build Tool**: Vite 7.x
- **Package Manager**: Bun
- **Deployment**: Two-branch strategy (main → source, deploy → build artifacts)
- **Hosting**: Caddy (configured via rick-infra)

View File

@@ -7,6 +7,7 @@
"devDependencies": {
"@poppanator/sveltekit-svg": "^6.0.1",
"@sveltejs/adapter-auto": "^7.0.0",
"@sveltejs/adapter-static": "^3.0.10",
"@sveltejs/kit": "^2.49.1",
"@sveltejs/vite-plugin-svelte": "^6.2.1",
"svelte": "^5.45.6",
@@ -135,6 +136,8 @@
"@sveltejs/adapter-auto": ["@sveltejs/adapter-auto@7.0.0", "", { "peerDependencies": { "@sveltejs/kit": "^2.0.0" } }, "sha512-ImDWaErTOCkRS4Gt+5gZuymKFBobnhChXUZ9lhUZLahUgvA4OOvRzi3sahzYgbxGj5nkA6OV0GAW378+dl/gyw=="],
"@sveltejs/adapter-static": ["@sveltejs/adapter-static@3.0.10", "", { "peerDependencies": { "@sveltejs/kit": "^2.0.0" } }, "sha512-7D9lYFWJmB7zxZyTE/qxjksvMqzMuYrrsyh1f4AlZqeZeACPRySjbC3aFiY55wb1tWUaKOQG9PVbm74JcN2Iew=="],
"@sveltejs/kit": ["@sveltejs/kit@2.49.2", "", { "dependencies": { "@standard-schema/spec": "^1.0.0", "@sveltejs/acorn-typescript": "^1.0.5", "@types/cookie": "^0.6.0", "acorn": "^8.14.1", "cookie": "^0.6.0", "devalue": "^5.3.2", "esm-env": "^1.2.2", "kleur": "^4.1.5", "magic-string": "^0.30.5", "mrmime": "^2.0.0", "sade": "^1.8.1", "set-cookie-parser": "^2.6.0", "sirv": "^3.0.0" }, "peerDependencies": { "@opentelemetry/api": "^1.0.0", "@sveltejs/vite-plugin-svelte": "^3.0.0 || ^4.0.0-next.1 || ^5.0.0 || ^6.0.0-next.0", "svelte": "^4.0.0 || ^5.0.0-next.0", "vite": "^5.0.3 || ^6.0.0 || ^7.0.0-beta.0" }, "optionalPeers": ["@opentelemetry/api"], "bin": { "svelte-kit": "svelte-kit.js" } }, "sha512-Vp3zX/qlwerQmHMP6x0Ry1oY7eKKRcOWGc2P59srOp4zcqyn+etJyQpELgOi4+ZSUgteX8Y387NuwruLgGXLUQ=="],
"@sveltejs/vite-plugin-svelte": ["@sveltejs/vite-plugin-svelte@6.2.1", "", { "dependencies": { "@sveltejs/vite-plugin-svelte-inspector": "^5.0.0", "debug": "^4.4.1", "deepmerge": "^4.3.1", "magic-string": "^0.30.17", "vitefu": "^1.1.1" }, "peerDependencies": { "svelte": "^5.0.0", "vite": "^6.3.0 || ^7.0.0" } }, "sha512-YZs/OSKOQAQCnJvM/P+F1URotNnYNeU3P2s4oIpzm1uFaqUEqRxUB0g5ejMjEb5Gjb9/PiBI5Ktrq4rUUF8UVQ=="],

59
deploy.sh Executable file
View File

@@ -0,0 +1,59 @@
#!/usr/bin/env bash
# deploy.sh - Build and deploy to orphan deploy branch
# Usage: ./deploy.sh [commit-message]
set -e
COMMIT_MSG="${1:-Deploy: $(date +'%Y-%m-%d %H:%M:%S')}"
echo "📦 Building site on main branch..."
bun run build
if [ ! -d "build" ]; then
echo "❌ Build failed - build directory not found"
exit 1
fi
echo "✅ Build successful"
echo ""
echo "🔄 Switching to deploy branch..."
git checkout deploy
echo "🧹 Cleaning deploy branch (keeping .git and .gitignore)..."
# Remove all tracked files except .gitignore
git ls-files | grep -v "^\.gitignore$" | xargs -r git rm -f
# Remove any untracked files/directories except build/, node_modules/, and .svelte-kit/
find . -mindepth 1 -maxdepth 1 ! -name 'build' ! -name 'node_modules' ! -name '.svelte-kit' ! -name '.git' ! -name '.gitignore' -exec rm -rf {} +
echo "📋 Copying build output to root..."
if [ -d "build" ]; then
mv build/* .
rm -rf build/
echo "✅ Build files copied to deploy branch root"
else
echo "⚠️ No build directory found (this is expected on deploy branch)"
fi
echo "📝 Staging changes..."
git add -A
# Check if there are any changes to commit
if git diff --staged --quiet; then
echo " No changes to deploy"
git checkout main
exit 0
fi
echo "💾 Committing build artifacts..."
git commit -m "$COMMIT_MSG"
echo "🚀 Pushing to origin/deploy..."
git push origin deploy
echo "✅ Switching back to main..."
git checkout main
echo ""
echo "✨ Deployment complete!"
echo " Deploy branch commit: $(git rev-parse --short deploy)"
echo " Main branch commit: $(git rev-parse --short main)"

View File

@@ -14,6 +14,7 @@
"devDependencies": {
"@poppanator/sveltekit-svg": "^6.0.1",
"@sveltejs/adapter-auto": "^7.0.0",
"@sveltejs/adapter-static": "^3.0.10",
"@sveltejs/kit": "^2.49.1",
"@sveltejs/vite-plugin-svelte": "^6.2.1",
"svelte": "^5.45.6",

1
src/routes/+layout.js Normal file
View File

@@ -0,0 +1 @@
export const prerender = true;

View File

@@ -1,12 +1,12 @@
<script>
import favicon from "$lib/assets/favicon.svg";
import css from "../app.css";
import faviconUrl from "$lib/assets/favicon.svg?url";
import "../app.css";
let { children } = $props();
</script>
<svelte:head>
<link rel="icon" href={favicon} />
<link rel="icon" href={faviconUrl} />
</svelte:head>
<div class="left"></div>

View File

@@ -1,12 +1,16 @@
import adapter from '@sveltejs/adapter-auto';
import adapter from '@sveltejs/adapter-static';
/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
// adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list.
// If your environment is not supported, or you settled on a specific environment, switch out the adapter.
// See https://svelte.dev/docs/kit/adapters for more information about adapters.
adapter: adapter()
adapter: adapter({
// Default options for static adapter
pages: 'build',
assets: 'build',
fallback: undefined,
precompress: false,
strict: true
})
}
};