166 lines
4.0 KiB
Markdown
166 lines
4.0 KiB
Markdown
|
|
# Lean 101 Website
|
||
|
|
|
||
|
|
This repo runs as a server-rendered SvelteKit app with a custom Mongo-backed CMS at `/admin`.
|
||
|
|
|
||
|
|
## Stack
|
||
|
|
|
||
|
|
- `SvelteKit`
|
||
|
|
- `@sveltejs/adapter-node`
|
||
|
|
- `MongoDB` via the native `mongodb` driver
|
||
|
|
- `docker compose` for local and server runtime
|
||
|
|
|
||
|
|
## What changed
|
||
|
|
|
||
|
|
- The public site now reads page content from MongoDB when `MONGODB_URI` and `MONGODB_DB` are set.
|
||
|
|
- If MongoDB is not configured, the homepage falls back to the local seed file at `src/lib/content/homepage.json`.
|
||
|
|
- `/admin` is a custom password-protected editor for:
|
||
|
|
- pages
|
||
|
|
- movable page sections
|
||
|
|
- blog posts
|
||
|
|
- The homepage seed is automatically migrated into the `site_pages` collection the first time the app connects to MongoDB.
|
||
|
|
|
||
|
|
## Project layout
|
||
|
|
|
||
|
|
```text
|
||
|
|
.
|
||
|
|
├── Dockerfile
|
||
|
|
├── docker-compose.yml
|
||
|
|
├── package.json
|
||
|
|
├── scripts/
|
||
|
|
│ └── deploy-do.sh
|
||
|
|
├── src/
|
||
|
|
│ ├── app.css
|
||
|
|
│ ├── app.html
|
||
|
|
│ ├── lib/
|
||
|
|
│ │ ├── content/homepage.json
|
||
|
|
│ │ ├── components/SitePage.svelte
|
||
|
|
│ │ ├── server/auth.js
|
||
|
|
│ │ ├── server/content.js
|
||
|
|
│ │ └── site.js
|
||
|
|
│ └── routes/
|
||
|
|
│ ├── +layout.js
|
||
|
|
│ ├── +page.server.js
|
||
|
|
│ ├── +page.svelte
|
||
|
|
│ ├── [slug]/+page.server.js
|
||
|
|
│ ├── [slug]/+page.svelte
|
||
|
|
│ ├── admin/+page.server.js
|
||
|
|
│ ├── admin/+page.svelte
|
||
|
|
│ ├── blog/+page.server.js
|
||
|
|
│ ├── blog/+page.svelte
|
||
|
|
│ ├── blog/[slug]/+page.server.js
|
||
|
|
│ ├── blog/[slug]/+page.svelte
|
||
|
|
│ ├── robots.txt/+server.js
|
||
|
|
│ └── sitemap.xml/+server.js
|
||
|
|
└── static/assets/
|
||
|
|
├── lean101-isotipo.png
|
||
|
|
└── lean101-logotipo.png
|
||
|
|
```
|
||
|
|
|
||
|
|
## Environment variables
|
||
|
|
|
||
|
|
Required for the CMS:
|
||
|
|
|
||
|
|
- `MONGODB_URI`
|
||
|
|
- `MONGODB_DB`
|
||
|
|
- `ADMIN_PASSWORD`
|
||
|
|
- `ADMIN_SESSION_SECRET`
|
||
|
|
|
||
|
|
Required for correct canonical/meta URLs:
|
||
|
|
|
||
|
|
- `PUBLIC_SITE_URL`
|
||
|
|
|
||
|
|
Example `.env`:
|
||
|
|
|
||
|
|
```env
|
||
|
|
PUBLIC_SITE_URL=http://localhost:8080
|
||
|
|
MONGODB_URI=mongodb://localhost:27017
|
||
|
|
MONGODB_DB=lean101
|
||
|
|
ADMIN_PASSWORD=replace-this
|
||
|
|
ADMIN_SESSION_SECRET=replace-this-with-a-long-random-string
|
||
|
|
```
|
||
|
|
|
||
|
|
## Run locally with Docker
|
||
|
|
|
||
|
|
```bash
|
||
|
|
docker compose up --build
|
||
|
|
```
|
||
|
|
|
||
|
|
The site will be available at `http://localhost:8080`.
|
||
|
|
|
||
|
|
The app server listens on port `3000` inside the container and is mapped to `8080` on the host.
|
||
|
|
|
||
|
|
## Run locally without Docker
|
||
|
|
|
||
|
|
```bash
|
||
|
|
npm install
|
||
|
|
npm run dev
|
||
|
|
```
|
||
|
|
|
||
|
|
The Vite dev server will run on its normal local port, usually `http://localhost:5173`.
|
||
|
|
|
||
|
|
## Production build
|
||
|
|
|
||
|
|
```bash
|
||
|
|
npm run build
|
||
|
|
npm run preview
|
||
|
|
```
|
||
|
|
|
||
|
|
`npm run preview` now runs the built Node server with `node build`.
|
||
|
|
|
||
|
|
## Custom CMS
|
||
|
|
|
||
|
|
Visit `/admin`.
|
||
|
|
|
||
|
|
The CMS is intentionally simple, but it now supports structured content:
|
||
|
|
|
||
|
|
- one password
|
||
|
|
- multiple pages
|
||
|
|
- reorderable sections within each page
|
||
|
|
- blog drafts and published posts
|
||
|
|
|
||
|
|
Current collections:
|
||
|
|
|
||
|
|
- `site_pages`
|
||
|
|
- `blog_posts`
|
||
|
|
|
||
|
|
Current section types:
|
||
|
|
|
||
|
|
- `hero`
|
||
|
|
- `services`
|
||
|
|
- `process`
|
||
|
|
- `outcomes`
|
||
|
|
- `why`
|
||
|
|
- `richText`
|
||
|
|
- `cta`
|
||
|
|
|
||
|
|
Published blog posts are available under `/blog`, and individual pages are available at `/<slug>`.
|
||
|
|
|
||
|
|
## DigitalOcean deployment script
|
||
|
|
|
||
|
|
After copying this project folder onto a droplet, you can run:
|
||
|
|
|
||
|
|
```bash
|
||
|
|
sudo ./scripts/deploy-do.sh --domain yourdomain.com --email you@example.com --with-www
|
||
|
|
```
|
||
|
|
|
||
|
|
The script:
|
||
|
|
|
||
|
|
- installs Docker, the compose plugin, nginx, and certbot
|
||
|
|
- writes `.env` with `PUBLIC_SITE_URL=https://yourdomain.com`
|
||
|
|
- starts the compose stack
|
||
|
|
- configures system nginx to reverse proxy to the Docker app on `127.0.0.1:8080`
|
||
|
|
- requests and installs a Let's Encrypt certificate if `--email` is provided
|
||
|
|
|
||
|
|
If you use the CMS in production, make sure the `.env` file on the server also includes:
|
||
|
|
|
||
|
|
- `MONGODB_URI`
|
||
|
|
- `MONGODB_DB`
|
||
|
|
- `ADMIN_PASSWORD`
|
||
|
|
- `ADMIN_SESSION_SECRET`
|
||
|
|
|
||
|
|
## Notes
|
||
|
|
|
||
|
|
- The current contact CTA still uses `mailto:hello@lean-101.com`
|
||
|
|
- The seed homepage remains in `src/lib/content/homepage.json`
|
||
|
|
- Live page and blog content is stored in MongoDB once the database env vars are configured
|