Skip to content

Commit

Permalink
feat: post service
Browse files Browse the repository at this point in the history
  • Loading branch information
cptchloroplast committed Aug 20, 2024
1 parent 1ee0238 commit 6b3a114
Show file tree
Hide file tree
Showing 28 changed files with 669 additions and 47 deletions.
5 changes: 4 additions & 1 deletion drizzle.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { defineConfig } from "drizzle-kit"

export default defineConfig({
dialect: "sqlite",
schema: ["./src/schemas/strava/tables.ts"],
schema: [
"./src/schemas/strava/tables.ts",
"./src/schemas/tables.ts",
],
out: "./migrations"
})
16 changes: 16 additions & 0 deletions migrations/0001_add_posts_and_tags_tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
CREATE TABLE `posts` (
`content` text,
`description` text,
`published` text NOT NULL,
`slug` text PRIMARY KEY NOT NULL,
`title` text NOT NULL,
`type` text NOT NULL,
`updated` text
);
--> statement-breakpoint
CREATE TABLE `tags` (
`name` text NOT NULL,
`post_slug` text NOT NULL,
PRIMARY KEY(`name`, `post_slug`),
FOREIGN KEY (`post_slug`) REFERENCES `posts`(`slug`) ON UPDATE no action ON DELETE no action
);
273 changes: 273 additions & 0 deletions migrations/meta/0001_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
{
"version": "6",
"dialect": "sqlite",
"id": "33e6eabe-c792-4d57-bd4d-906a2df54df2",
"prevId": "d0532e55-b97a-4c4f-b350-50a3301e31bb",
"tables": {
"components": {
"name": "components",
"columns": {
"added": {
"name": "added",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"brand": {
"name": "brand",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"distance": {
"name": "distance",
"type": "real",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"gear_id": {
"name": "gear_id",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"string": {
"name": "string",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"removed": {
"name": "removed",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"type": {
"name": "type",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {
"gear_id_idx": {
"name": "gear_id_idx",
"columns": [
"gear_id"
],
"isUnique": false
}
},
"foreignKeys": {
"components_gear_id_gear_id_fk": {
"name": "components_gear_id_gear_id_fk",
"tableFrom": "components",
"tableTo": "gear",
"columnsFrom": [
"gear_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"gear": {
"name": "gear",
"columns": {
"brand_name": {
"name": "brand_name",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"frame_type": {
"name": "frame_type",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"model_name": {
"name": "model_name",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"slug": {
"name": "slug",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {
"slug_idx": {
"name": "slug_idx",
"columns": [
"slug"
],
"isUnique": false
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"posts": {
"name": "posts",
"columns": {
"content": {
"name": "content",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"published": {
"name": "published",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"slug": {
"name": "slug",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"title": {
"name": "title",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"type": {
"name": "type",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"updated": {
"name": "updated",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"tags": {
"name": "tags",
"columns": {
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"post_slug": {
"name": "post_slug",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"tags_post_slug_posts_slug_fk": {
"name": "tags_post_slug_posts_slug_fk",
"tableFrom": "tags",
"tableTo": "posts",
"columnsFrom": [
"post_slug"
],
"columnsTo": [
"slug"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {
"tags_name_post_slug_pk": {
"columns": [
"name",
"post_slug"
],
"name": "tags_name_post_slug_pk"
}
},
"uniqueConstraints": {}
}
},
"enums": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
},
"internal": {
"indexes": {}
}
}
7 changes: 7 additions & 0 deletions migrations/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
"when": 1722563388919,
"tag": "0000_add_gear_and_components_tables",
"breakpoints": true
},
{
"idx": 1,
"version": "6",
"when": 1723171014511,
"tag": "0001_add_posts_and_tags_tables",
"breakpoints": true
}
]
}
1 change: 1 addition & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"drizzle-orm": "^0.32.1",
"esbuild": "^0.23.0",
"googleapis": "^140.0.1",
"gray-matter": "^4.0.3",
"npm-run-all": "^4.1.5",
"rehype-external-links": "^3.0.0",
"remark-gfm": "^4.0.0",
Expand Down
12 changes: 12 additions & 0 deletions scripts/seed-bucket.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
GEAR=$CONFIG/gear/*
for gear in $GEAR
do
filename=`echo $gear | cut -c ${#GEAR}-`
npx wrangler r2 object put strava/gear/$filename --file $gear --local
done
POSTS=$LOCAL/src/content/posts/*
for post in $POSTS
do
filename=`echo $post | cut -c ${#POSTS}-`
npx wrangler r2 object put blog/posts/$filename --file $post --local
done
6 changes: 0 additions & 6 deletions scripts/seed-strava.sh

This file was deleted.

9 changes: 6 additions & 3 deletions src/components/Tags.astro
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
---
import type { Tag } from "@schemas"
import { Chip } from "@components/ui"
type Props = {
tags: Tag[]
tags: {
name: string
count: number
}[] | string[]
}
const { tags } = Astro.props
---

<ol>
{tags.map(tag => {
const { name, count } = tag
let count = typeof tag === "object" ? tag.count : undefined
let name = typeof tag === "object" ? tag.name : tag
return (
<li>
<Chip href={`/tags/${name}`} title={`Tags - ${name}`}>
Expand Down
18 changes: 9 additions & 9 deletions src/content/config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { defineCollection } from "astro:content"
import { PostSchema } from "@schemas"
const PostCollection = defineCollection({
type: "content",
schema: PostSchema,
})
export const collections = {
"posts": PostCollection,
}
// import { defineCollection } from "astro:content"
// import { PostSchema } from "@schemas"
// const PostCollection = defineCollection({
// type: "content",
// schema: PostSchema,
// })
// export const collections = {
// "posts": PostCollection,
// }
Loading

0 comments on commit 6b3a114

Please sign in to comment.