Skip to content

Commit

Permalink
✨ Servers are for loosers
Browse files Browse the repository at this point in the history
  • Loading branch information
nwrenger committed Mar 23, 2024
1 parent 760456b commit 894807e
Show file tree
Hide file tree
Showing 17 changed files with 167 additions and 110 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Deploy to GitHub Pages

on:
push:
branches: ['main']

jobs:
build_site:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: 'latest'

- name: Install dependencies
run: bun install

- name: build
env:
BASE_PATH: '/'
run: |
bun run build
touch build/.nojekyll
- name: Upload Artifacts
uses: actions/upload-pages-artifact@v1
with:
# this should match the `pages` option in your adapter-static options
path: 'build/'

deploy:
needs: build_site
runs-on: ubuntu-latest

permissions:
pages: write
id-token: write

environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

steps:
- name: Deploy
id: deployment
uses: actions/deploy-pages@v1
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ node_modules
!.env.example
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
bun.lockb
bun.lockb
/src/lib/data.json
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "vite dev",
"build": "vite build",
"dev": "bun run gen && vite dev",
"build": "bun run gen && vite build",
"gen": "bun src/lib/init.ts",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
Expand Down Expand Up @@ -36,6 +37,6 @@
"dependencies": {
"@floating-ui/dom": "1.5.3",
"@fortawesome/fontawesome-free": "^6.5.1",
"@sveltejs/adapter-node": "^3.0.0"
"@sveltejs/adapter-static": "^3.0.1"
}
}
46 changes: 46 additions & 0 deletions src/lib/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import fs from 'fs';
import path from 'path';

export interface Resource {
title: string;
summary: string;
comment: string;
subject: string;
grade: string;
school: string;
file_name: string;
year: string;
}

export interface Database {
subjects: string[];
resources: Resource[];
}

const db: Database = { subjects: [], resources: [] };

function importFiles(directoryPath: string) {
const items = fs.readdirSync(directoryPath, { withFileTypes: true });

items.forEach((item) => {
const fullPath = path.join(directoryPath, item.name);
if (item.isDirectory()) {
importFiles(fullPath);
} else if (path.extname(item.name) === '.json') {
const fileData = fs.readFileSync(fullPath, 'utf8');
const resource: Resource = JSON.parse(fileData);

if (!db.subjects.includes(resource.subject)) {
db.subjects.push(resource.subject);
}

db.resources.push(resource);
}
});
}

importFiles('static/files');

fs.writeFile('src/lib/data.json', JSON.stringify(db), (err) => {
if (err) throw err;
});
3 changes: 0 additions & 3 deletions src/lib/links.ts

This file was deleted.

76 changes: 0 additions & 76 deletions src/lib/server/mem.ts

This file was deleted.

42 changes: 42 additions & 0 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import type { Database, Resource } from './init';

// links
export const DiscordURL = 'https://discord.com/invite/nWd8yZ4HWY';
export const InstagramURL = 'https://www.instagram.com/schulenimchaos/';
export const GithubURL = 'https://github.com/schulen-im-chaos';

// helper sorting function
export function resourcesBySubjectAndGradeMap(
db: Database,
subjectName: string,
query: string
): { [key: string]: Resource[] } {
const filteredResources: { [key: string]: Resource[] } = {};
query = query.toLowerCase();

for (const resource of db.resources) {
if (resource.subject === subjectName) {
if (!query) {
filteredResources[resource.grade] = [
...(filteredResources[resource.grade] || []),
resource
];
} else {
if (
resource.grade.toLowerCase().includes(query) ||
resource.title.toLowerCase().includes(query) ||
resource.school.toLowerCase().includes(query) ||
resource.year.toLowerCase().includes(query) ||
resource.summary.toLowerCase().includes(query)
) {
filteredResources[resource.grade] = [
...(filteredResources[resource.grade] || []),
resource
];
}
}
}
}

return filteredResources;
}
3 changes: 1 addition & 2 deletions src/routes/+layout.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export const prerender = false;
export const ssr = false;
export const prerender = true;
2 changes: 1 addition & 1 deletion src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { DiscordURL } from '$lib/links';
import { DiscordURL } from '$lib/utils';
</script>

<svelte:head>
Expand Down
2 changes: 1 addition & 1 deletion src/routes/Footer.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { DiscordURL, GithubURL, InstagramURL } from '$lib/links';
import { DiscordURL, GithubURL, InstagramURL } from '$lib/utils';
// eslint-disable-next-line no-undef
// Base Classes
Expand Down
2 changes: 1 addition & 1 deletion src/routes/Header.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { DiscordURL } from '$lib/links';
import { DiscordURL } from '$lib/utils';
import { AppBar, popup } from '@skeletonlabs/skeleton';
</script>

Expand Down
2 changes: 1 addition & 1 deletion src/routes/contact/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { DiscordURL } from '$lib/links';
import { DiscordURL } from '$lib/utils';
</script>

<svelte:head>
Expand Down
7 changes: 0 additions & 7 deletions src/routes/materials/+page.server.ts

This file was deleted.

6 changes: 2 additions & 4 deletions src/routes/materials/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<script lang="ts">
import type { PageData } from './$types';
export let data: PageData;
import db from '$lib/data.json';
</script>

<svelte:head>
Expand All @@ -23,7 +21,7 @@
>!
</p>
<div class="grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 2xl:grid-cols-6 gap-6">
{#each data.subjects as subject}
{#each db.subjects as subject}
<a class="btn variant-filled" href="/materials/kind/{subject}">{subject}</a>
{:else}
<aside class="alert variant-filled-warning !m-0">
Expand Down
8 changes: 0 additions & 8 deletions src/routes/materials/kind/[subject]/+page.server.ts

This file was deleted.

15 changes: 15 additions & 0 deletions src/routes/materials/kind/[subject]/+page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { resourcesBySubjectAndGradeMap } from '$lib/utils';
import db from '$lib/data.json';

export const prerender = false;

export async function load({ params, url }) {
return {
resources: resourcesBySubjectAndGradeMap(
db,
params.subject,
url.searchParams.get('query') || ''
),
subject: params.subject
};
}
3 changes: 1 addition & 2 deletions svelte.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//import adapter from '@sveltejs/adapter-static';
import adapter from '@sveltejs/adapter-node';
import adapter from '@sveltejs/adapter-static';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';

/** @type {import('@sveltejs/kit').Config} */
Expand Down

0 comments on commit 894807e

Please sign in to comment.