Skip to content

Commit

Permalink
feat: trying web-vitals
Browse files Browse the repository at this point in the history
  • Loading branch information
Princesseuh committed May 22, 2024
1 parent e78d1a2 commit 1ef895d
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 39 deletions.
4 changes: 3 additions & 1 deletion astro.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import db from "@astrojs/db";
import markdoc from "@astrojs/markdoc";
import tailwind from "@astrojs/tailwind";
import expressiveCode from "astro-expressive-code";
import { defineConfig } from "astro/config";
import { rename } from "fs/promises";

import db from "@astrojs/db";
import webVitals from "@astrojs/web-vitals";

// https://astro.build/config
export default defineConfig({
Expand Down Expand Up @@ -43,5 +44,6 @@ export default defineConfig({
},
},
db(),
webVitals(),
],
});
46 changes: 23 additions & 23 deletions db/config.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import { column, defineDb, defineTable } from 'astro:db';
import { column, defineDb, defineTable } from "astro:db";

const Cover = defineTable({
columns: {
id: column.number({ primaryKey: true }),
src: column.text(),
width: column.number(),
height: column.number(),
placeholder: column.text()
}
columns: {
id: column.number({ primaryKey: true }),
src: column.text(),
width: column.number(),
height: column.number(),
placeholder: column.text(),
},
});

const Catalogue = defineTable({
columns: {
id: column.number({ primaryKey: true }),
type: column.text(),
title: column.text(),
author: column.text(),
cover: column.number({ references: () => Cover.columns.id }),
rating: column.text(),
finishedDate: column.number({ optional: true }),
platform: column.text({ optional: true }),
metadata: column.text()
}
columns: {
id: column.number({ primaryKey: true }),
type: column.text(),
title: column.text(),
author: column.text(),
cover: column.number({ references: () => Cover.columns.id }),
rating: column.text(),
finishedDate: column.number({ optional: true }),
platform: column.text({ optional: true }),
metadata: column.text(),
},
});

// https://astro.build/db/config
export default defineDb({
tables: {
Cover,
Catalogue
}
tables: {
Cover,
Catalogue,
},
});
25 changes: 14 additions & 11 deletions db/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import type { LocalImageServiceWithPlaceholder } from "src/imageService";

// https://astro.build/db/seed
export default async function seed() {
await prepareDB();
await prepareDB();
}

export async function prepareDB() {
const games = await getCollection("games");
const games = await getCollection("games");
const movies = await getCollection("movies");
const shows = await getCollection("shows");
const books = await getCollection("books");

const catalogueContent = [...games, ...movies, ...shows, ...books];
const catalogueContent = [...games, ...movies, ...shows, ...books];
for (const entry of catalogueContent) {
await addCatalogueEntry(entry);
}
Expand All @@ -26,16 +26,19 @@ export async function addCatalogueEntry(entry: allCatalogueTypes) {
const [processedCover, placeholderURL] = await getCoverAndPlaceholder(cover);
const metadata = await getCatalogueData(entry);

const author = getAuthorFromEntryMetadata(type, metadata);
const author = getAuthorFromEntryMetadata(type, metadata);

const coverId = await db.insert(Cover).values({
src: processedCover.src,
width: processedCover.attributes.width,
height: processedCover.attributes.height,
placeholder: placeholderURL,
}).returning({ id: Cover.id });
const coverId = await db
.insert(Cover)
.values({
src: processedCover.src,
width: processedCover.attributes.width,
height: processedCover.attributes.height,
placeholder: placeholderURL,
})
.returning({ id: Cover.id });

const firstCoverId = coverId[0]?.id ?? -1;
const firstCoverId = coverId[0]?.id ?? -1;

const insertData = {
type: type,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@astrojs/check": "^0.7.0",
"@astrojs/db": "~0.10.0",
"@astrojs/markdoc": "^0.11.0",
"@astrojs/web-vitals": "^0.2.0",
"@types/igdb-api-node": "^5.0.3",
"astro-capo": "^0.0.1",
"astro-expressive-code": "^0.35.3",
Expand Down
33 changes: 29 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1ef895d

Please sign in to comment.