diff --git a/.changeset/heavy-deers-jump.md b/.changeset/heavy-deers-jump.md new file mode 100644 index 0000000..adf0c6a --- /dev/null +++ b/.changeset/heavy-deers-jump.md @@ -0,0 +1,5 @@ +--- +"ottawa-boardgame-sell-bgg": minor +--- + +maint: read the games from a json file diff --git a/Taskfile.yaml b/Taskfile.yaml index bafdfb2..3ea7723 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -6,6 +6,13 @@ vars: GREETING: Hello, World! tasks: + export-db: + cmds: + - sqlite3 /home/bggsell/games.db '.mode json' '.once /home/bggsell/db/games.json' 'select * from game' + export-db:dev: + cmds: + - sqlite3 games.db '.mode json' '.once static/dev/games.json' 'select * from game' + deploy: deps: [build] cmds: diff --git a/contrib/nginx-bggsell.conf b/contrib/nginx-bggsell.conf index eabd1fe..fc7b2b1 100644 --- a/contrib/nginx-bggsell.conf +++ b/contrib/nginx-bggsell.conf @@ -17,4 +17,7 @@ server { location / { try_files $uri $uri/ $uri.html /index.html =404; } + location /db/ { + alias /home/bggsell/db/; + } } diff --git a/package.json b/package.json index 7077450..f9e063f 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "beercss": "^3.4.13", "better-sqlite3": "^9.3.0", "cheerio": "1.0.0-rc.12", - "node-fetch": "^3.3.2" + "node-fetch": "^3.3.2", + "vite-multiple-assets": "^1.2.10" } } diff --git a/src/routes/+page.js b/src/routes/+page.js new file mode 100644 index 0000000..03f551d --- /dev/null +++ b/src/routes/+page.js @@ -0,0 +1,9 @@ +import { dev } from '$app/environment'; + +export async function load({ fetch }) { + const url = dev ? '/dev/games.json' : '/games.json'; + + return { + games: fetch(url).then((doc) => doc.json()), + }; +} diff --git a/src/routes/+page.server.js b/src/routes/+page.server.js deleted file mode 100644 index 04e3583..0000000 --- a/src/routes/+page.server.js +++ /dev/null @@ -1,12 +0,0 @@ -import DB from 'better-sqlite3'; - -const db_file = process.env.DATABASE_URL.replace('sqlite3:',''); - -export async function load() { - const db = DB(db_file); - db.pragma('journal_mode = WAL'); - - return { - games: db.prepare( 'SELECT * from game').all() - }; -} diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 0a94655..59caf8f 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -28,7 +28,9 @@ >.
-