diff --git a/.astro/types.d.ts b/.astro/types.d.ts index fea26b7..cd8b382 100644 --- a/.astro/types.d.ts +++ b/.astro/types.d.ts @@ -374,6 +374,13 @@ declare module 'astro:content' { collection: "blog"; data: InferEntrySchema<"blog"> } & { render(): Render[".md"] }; +"2024/doctor-type-love.md": { + id: "2024/doctor-type-love.md"; + slug: "2024/doctor-type-love"; + body: string; + collection: "blog"; + data: InferEntrySchema<"blog"> +} & { render(): Render[".md"] }; "2024/my-backup-solution.md": { id: "2024/my-backup-solution.md"; slug: "2024/my-backup-solution"; diff --git a/astro.config.mjs b/astro.config.mjs index c56b7b2..f2362ae 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -1,5 +1,5 @@ import { defineConfig } from 'astro/config'; -import netlify from '@astrojs/netlify/functions'; +import netlify from '@astrojs/netlify'; // https://astro.build/config import mdx from '@astrojs/mdx'; diff --git a/bun.lockb b/bun.lockb index 9d2cff9..399e324 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/newPost.ts b/newPost.ts new file mode 100644 index 0000000..ac80db7 --- /dev/null +++ b/newPost.ts @@ -0,0 +1,24 @@ +import { Tag } from 'src/types'; + +const renderFile = ( + title: string, + date: string, + tags: string[], + md: string +) => ` +--- +title: ${title} +pubDate: ${date} +tags: ['${tags.join("', '")}'] +--- + +${md} +`; + +const newPost = () => { + const tagArr = Object.values(Tag); + + console.log(tagArr); +}; + +newPost(); diff --git a/package.json b/package.json index 3a1ef00..ce86909 100644 --- a/package.json +++ b/package.json @@ -1,28 +1,30 @@ { - "name": "ghall.blog", - "type": "module", - "version": "0.1.0", - "private": true, - "scripts": { - "dev": "astro dev", - "start": "astro dev", - "build": "astro build", - "preview": "astro preview", - "astro": "astro" - }, - "dependencies": { - "@astrojs/mdx": "2.1.0", - "@astrojs/netlify": "5.0.0", - "@astrojs/rss": "4.0.4", - "astro": "4.2.6", - "date-fns": "^3.3.1", - "date-fns-tz": "^1.3.7", - "markdown-it": "^13.0.1", - "sanitize-html": "^2.9.0", - "sharp": "^0.33.2" - }, - "devDependencies": { - "prettier": "^2.8.1", - "prettier-plugin-astro": "^0.7.0" - } + "name": "ghall.blog", + "type": "module", + "version": "0.1.0", + "private": true, + "scripts": { + "dev": "astro dev", + "start": "astro dev", + "build": "astro build", + "preview": "astro preview", + "astro": "astro", + "new-post": "bun ./newPost.ts" + }, + "dependencies": { + "@astrojs/mdx": "2.1.0", + "@astrojs/netlify": "5.0.0", + "@astrojs/rss": "4.0.4", + "astro": "4.2.6", + "date-fns": "^3.3.1", + "date-fns-tz": "^1.3.7", + "markdown-it": "^13.0.1", + "sanitize-html": "^2.9.0", + "sharp": "^0.33.2" + }, + "devDependencies": { + "inquirer": "^9.2.15", + "prettier": "^2.8.1", + "prettier-plugin-astro": "^0.7.0" + } } diff --git a/src/components/Header.astro b/src/components/Header.astro index 7d7bc7d..4427392 100644 --- a/src/components/Header.astro +++ b/src/components/Header.astro @@ -1,10 +1,7 @@ --- -const { pathname } = Astro.url; +import type { NavLink } from 'src/types'; -type NavLink = { - label: string; - path: string; -}; +const { pathname } = Astro.url; const navLinks: NavLink[] = [ { label: '📝 Blog', path: '/' }, diff --git a/src/content/blog/2024/doctor-type-love.md b/src/content/blog/2024/doctor-type-love.md new file mode 100644 index 0000000..8e43c34 --- /dev/null +++ b/src/content/blog/2024/doctor-type-love.md @@ -0,0 +1,28 @@ +--- +title: 'How I Learned to Stop Worrying and Love TypeScript' +pubDate: '2/21/24' +tags: ['Learning', 'Programming'] +--- + +One of the first steps I took on my post-boot camp webdev journey was to learn TypeScript. It wasn't something that was covered–though I wish it had been, I'll get into why in a second–but it was something we were encouraged to study on our own. I immediately got frustrated, and determined that there was no point. Why would I need to go through the trouble of assigning types to my variables when it was all just getting compiled into vanilla JavaScript anyway? + +Two major things happened since then that changed my tune; I learned Swift, and I started using Bun for personal projects. + +First, I'll tackle Swift. + +Learning Swift was both pretty straightforward coming from JavaScript. The syntax, while pretty different, has some concepts that were familiar to me. By the same token though, Swift is a statically-typed[^1] language and I found that difficult to wrap my head around at first–I had, after all, given up on TypeScript in frustration. + +As I got more comfortable with Swift, I starte to miss the benefits of static typing when working in JavaScript. The ability to just tell my code "hey, this variable here is an integer" and have my code crash, or even just fail to even compile, with a super specific error when I inevitably do something stupid and try to treat that variable as a string is infinitely less frustrating than the alternative. + +Secondly, there's Bun. + +Bun is amazing, and I could write an entire post about how much I love working with bun. Heck, maybe I will, but that's something for another day... + +The main thing about Bun that's relevant to my TypeScript journey is the fact that it can natively interpret TypeScript without having to compile to JavaScript. That means that right out of the box, with no dependencies, Bun can just run your TypeScript code just as easily as it can run JavaScript.[^2] + +While any code getting shipped to the browser will still need to be compiled to vanilla JavaScript, you could, as I understand it, theoretically write your entire back-end in TypeScript and just skip the build step. 🤯 + +I started off being annoyed with using types in my code because, to be quite frank, they are annoying. They'll make your code throw errors whenever you try to multiply a string, or something silly like that. But that's part of the beauty I've come to appreciate. They're there to help you write better code, and to point you in the right direction when something inevitably goes wrong. + +[^1]: [Here](https://stackoverflow.com/questions/1517582/what-is-the-difference-between-statically-typed-and-dynamically-typed-languages) is a StackOverflow thread on the difference between dynamic and static typing put far better than I ever could explain it +[^2]: As an example, I rewrote [my CLI clone of Wordle](https://github.com/ghall89/wordle-cli) in TypeScript diff --git a/src/content/config.ts b/src/content/config.ts index 2fbf11c..aefa827 100644 --- a/src/content/config.ts +++ b/src/content/config.ts @@ -1,28 +1,10 @@ import { z, defineCollection } from 'astro:content'; - -export enum Tag { - 'Apps' = 'Apps', - 'Digital Life' = 'Digital Life', - 'Gaming' = 'Gaming', - 'Learning' = 'Learning', - 'Life' = 'Life', - 'MacOS' = 'MacOS', - 'Music' = 'Music', - 'Making Stuff' = 'Making Stuff', - 'Mental Health' = 'Mental Health', - 'Movies & TV' = 'Movies & TV', - 'Programming' = 'Programming', - 'Tech' = 'Tech', - 'Tutorial' = 'Tutorial', - 'Web Dev' = 'Web Dev', - // only for filtering - all = 'all', -} +import { Tag } from 'src/types'; const blogCollection = defineCollection({ schema: z.object({ title: z.string(), - pubDate: z.string().transform((str) => new Date(str)), + pubDate: z.string().transform((str: string) => new Date(str)), tags: z.array(z.nativeEnum(Tag)), }), }); diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 0000000..924bed4 --- /dev/null +++ b/src/types.ts @@ -0,0 +1,25 @@ +// navigation links +export type NavLink = { + label: string; + path: string; +}; + +// blog tags +export enum Tag { + 'Apps' = 'Apps', + 'Digital Life' = 'Digital Life', + 'Gaming' = 'Gaming', + 'Learning' = 'Learning', + 'Life' = 'Life', + 'MacOS' = 'MacOS', + 'Music' = 'Music', + 'Making Stuff' = 'Making Stuff', + 'Mental Health' = 'Mental Health', + 'Movies & TV' = 'Movies & TV', + 'Programming' = 'Programming', + 'Tech' = 'Tech', + 'Tutorial' = 'Tutorial', + 'Web Dev' = 'Web Dev', + // only for filtering + all = 'all', +}