From 25d9e559ec21a7c540ba57f68566d3f9f665bf3f Mon Sep 17 00:00:00 2001 From: TJ Raklovits <91501317+Monster0506@users.noreply.github.com> Date: Tue, 9 Dec 2025 14:37:23 -0500 Subject: [PATCH] Update docs (#13) * Clean up build warnings * Clean up display of icons * Update documents --- .env.example | 1 - .gitignore | 4 +- README.md | 70 +++++++++++--- scripts/README.md | 29 ++++++ src/lib/Navbar.svelte | 13 +-- .../components/lessons/CategoryCard.svelte | 94 +++++++++---------- src/lib/components/lessons/LessonCard.svelte | 4 +- src/lib/components/lessons/SearchBar.svelte | 8 +- src/lib/lessons/utils.ts | 2 +- src/lib/server/auth.ts | 7 -- src/routes/admin/lesson-icons/+page.svelte | 12 ++- src/routes/lessons/+page.svelte | 42 ++++++--- src/routes/lessons/[...path]/+page.svelte | 38 ++++---- src/routes/resources/hotcard/+page.svelte | 2 +- svelte.config.js | 5 + 15 files changed, 213 insertions(+), 118 deletions(-) create mode 100644 scripts/README.md diff --git a/.env.example b/.env.example index 707d5b8..1dc5adc 100644 --- a/.env.example +++ b/.env.example @@ -13,4 +13,3 @@ BODY_SIZE_LIMIT=20M # for those hi res pictures GITHUB_TOKEN=github_pat_X_X PUBLIC_APP_URL=http://localhost:3000 -BODY_SIZE_LIMIT=20M diff --git a/.gitignore b/.gitignore index 1f5c67b..5e1322e 100644 --- a/.gitignore +++ b/.gitignore @@ -25,7 +25,7 @@ vite.config.js.timestamp-* vite.config.ts.timestamp-* -compose.override.yml +compose.override.yaml # Uploads static/uploads/ @@ -33,4 +33,4 @@ static/uploads/ scripts/assets/ scripts/dump.json -scripts/restore.log \ No newline at end of file +scripts/restore.log diff --git a/README.md b/README.md index aace9b0..7457672 100644 --- a/README.md +++ b/README.md @@ -2,32 +2,76 @@ Programmers. + +This is the current main website for HacKSU. It exists at hacksu.com + + +## Quickstart + To run this site locally, you will want Docker. You can run it without production configuration locally, but it is generally not recommended, as the deployed build environment is Docker. - You will need a `.env` file. This file should contain all of the variables in the `.env.example` file at the root of the project correctly filled out. -## Environment Variables +The below might not be maintained, use the `.env.example` for correct information +```env +DATABASE_URL=postgresql://hacksu:hacksu@db:5432/hacksu -Required environment variables: -- `GITHUB_TOKEN` - GitHub personal access token for accessing the GitHub API -- `DATABASE_URL` - PostgreSQL connection string (automatically set in Docker Compose) -- `REDIS_URL` - Redis connection string (defaults to `redis://localhost:6379`, automatically set in Docker Compose) -- `GITHUB_ORG` - GitHub organization name (defaults to `hacksu`, optional) +SESSION_SECRET=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +SENDGRID_TOKEN=SG.X.X -The `REDIS_URL` is automatically configured in Docker Compose to connect to the Redis service. For local development outside Docker, you may need to set it manually. +DISCORD_ROLES=X Y Z +DISCORD_CLIENT_ID=XXXXX +DISCORD_GUILD_ID=XXXXX +DISCORD_CLIENT_SECRET=XXXXX +BODY_SIZE_LIMIT=20M -To make changes on the admin side, go to the `/admin` route, and login with discord. If you have acceptable roles, this will authenticate you. +GITHUB_TOKEN=github_pat_X_X +PUBLIC_APP_URL=http://localhost:3000 +``` -Run the containers with `docker compose up -d --build` -This should setup persistent postgres and redis volumes and expose `localhost:3002` with the site. +The `REDIS_URL` is automatically configured in Docker Compose to connect to the Redis service. For local development outside Docker, you may need to set it manually. + +I am configuring a couple of the variables in the compose file because they are unimportant and don't require security: `REDIS_URL`, `GITHUB_ORG` which is modifiable, but defaults to `hacksu`, `DATABASE_URL` but I also configured that on the server in case we ever need to expose it, and `NODE_ENV`, which we are not really using. + +To make changes on the admin side, go to the `/admin` route, and login with Discord. If you have acceptable roles, (organizer, core, leader) this will authenticate you. + +This should setup persistent postgres and redis volumes and expose `localhost:3000` with the site. The setup includes: -- **PostgreSQL** - Main database (port 5434) +- **PostgreSQL** - Main database (port 5432) - **Redis** - Cache for lesson repositories (port 6379) - **Lessons Service** - Python service that fetches and caches GitHub lesson repos -- **SvelteKit App** - Main web application (port 3002) +- **SvelteKit App** - Main web application (port 3000) + +For local testing you will also want a `compose.override.yaml` + +```yaml +services: + app: + ports: + - 3000:3000 +``` + +The ports are important. This will allow you to access the port internal to the container externally. Take care not to push this file to a deployment, as it will conflict and tie up an actual port from the HacKSU server.(It is in the `.gitignore`, so it would take some effort) + + +## Running: + +Run the containers with `docker compose up -d --build` + + + +## Development + +If you make changes to the schema, be sure to run `bun db:generate` to generate migrations in the drizzle folder, that will be automatically performed on start. + + +The schema for our database lies within `./src/lib/server/db/schema.ts`. This is a pretty neat way to define a schema with SQL-like TS. + +If you add to the schema, if necessary, update the dump and restore routes, following the established pattern so we can restore in the event of a volume failure. + +I have written some helper scripts for running these dump and restore commands fully, and getting consistent output. See the `scripts` folder README for more information on that. diff --git a/scripts/README.md b/scripts/README.md new file mode 100644 index 0000000..bbdf725 --- /dev/null +++ b/scripts/README.md @@ -0,0 +1,29 @@ +# Helper Scripts + + +## Dump and Restore + +These guys are here to create a json dump of our existing database before performing major structural changes (like switching out databases or volumes) + +I really really really recommend running these with `uv` as it makes life so much easier. + +### `dump.py` +`uv run scripts/dump.py [ACTIVE_ADMIN_SESSION_COOKIE] [LOCATION_OF_ENDPOINT_BASE_URL|https://localhost:3000]` + +This will: +- Call /admin/api/dump/json and save the result as dump.json +- Call /admin/api/dump/assets and download all listed files + into an ./assets directory, mirroring their /uploads paths. + + +### `restore.py` +`uv run scripts/restore.py [ACTIVE_ADMIN_SESSION_COOKIE] [LOCATION_OF_ENDPOINT_BASE_URL|https://localhost:3000]` + +This expects that you have previously run `dump.py` so that: +- `scripts/dump.json` exists (full JSON dump) +- `scripts/assets/` exists with files mirroring `/uploads/**` paths + +It will: +- POST dump.json to /admin/api/dump/json to restore DB contents +- Walk `assets/` and POST each file to /admin/api/dump/assets + diff --git a/src/lib/Navbar.svelte b/src/lib/Navbar.svelte index d64de3d..0c37ecc 100644 --- a/src/lib/Navbar.svelte +++ b/src/lib/Navbar.svelte @@ -25,12 +25,13 @@ } const routes: Route[] = [ - {href:'/', img:hacksuLogo, alt:"Hacksu", pos:"center"}, - {href:'/',text:"Home",pos:"left"}, - {href:'/leadership',text:"Leadership",pos:"left"}, - {href:'/meetings',text:"Meetings",pos:"left"}, - {href:'/info',text:"Resources",pos:"right"}, - {href:'/contact',text:"Contact",pos:"right"}, + {href:'/', img:hacksuLogo, alt:"Hacksu", pos:"center"}, + {href:'/', text:"Home", pos:"left"}, + {href:'/leadership', text:"Leadership", pos:"left"}, + {href:'/lessons', text:"Lessons", pos:"right"}, + {href:'/meetings', text:"Meetings", pos:"left"}, + {href:'/info', text:"Resources", pos:"right"}, + {href:'/contact', text:"Contact", pos:"right"}, ] // Get all non-center routes for mobile menu diff --git a/src/lib/components/lessons/CategoryCard.svelte b/src/lib/components/lessons/CategoryCard.svelte index 11507a0..866c67b 100644 --- a/src/lib/components/lessons/CategoryCard.svelte +++ b/src/lib/components/lessons/CategoryCard.svelte @@ -1,47 +1,47 @@ - - -
-
-
- {#if iconUrl} - {category} - {:else if initials} - {initials} - {:else} - 📁 - {/if} -
- -

- {displayCategory} -

- -
- {lessonCount} lesson{lessonCount !== 1 ? 's' : ''} -
-
-
+ + +
+
+
+ {#if iconUrl} + {category} + {:else if initials} + {initials} + {:else} + 📁 + {/if} +
+ +

+ {displayCategory} +

+ +
+ {lessonCount} lesson{lessonCount !== 1 ? 's' : ''} +
+
+
diff --git a/src/lib/components/lessons/LessonCard.svelte b/src/lib/components/lessons/LessonCard.svelte index 25dd1d5..bf6f4e5 100644 --- a/src/lib/components/lessons/LessonCard.svelte +++ b/src/lib/components/lessons/LessonCard.svelte @@ -1,6 +1,6 @@