Here are some of the extra things I had to make sure to do:
Sort the blog posts by something, I decided to use date
There's some duplicate code for things like headers that is just raw HTML. If I ever end up changing anything, I'll move those to a separate template at that time
I ended up breaking out all of the post logic that I wrote into it's own file (this is maybe against the spirit of a "minimum viable" blog since it's not really being served by two files)
server.ts
page, but not when I try to break it out to posts.ts
class
es instead of const
s for services 🤦ts-node
or tsc --watch
and ended up just going with ts-node
for ease of use. It's just a little slowNow I'm going to work on getting it deployed using DigitalOcean
Checking Vercel now, since lots of people are recommending this
Shout-out to Victor Cora Colombo for his blog post that details copying extra files when building typescript
package.json
scripts
that you can run to clean
and copy-files
Going to attempt to re-deploy now
vercel.json
config file as well/api
folder, and I needed my main typescript file to be index.ts
-- this way when it gets built/compiled into my /dist
folder, there is a valid index
for Vercel to pick up and serve. I had to also rename my index.html
template to home.html
vercel dev
and npm run dev
working locally, which is encouragingWoke up late but still went for a run today, made a bacon, spinach, and egg hash for breakfast, and then got back to work on this.
First step was creating a new directory for the Next.JS app and getting some of the files that I would need copied over
Then made sure to get my global style sheet configured correctly before I tackled any of the routing issues
Was able to pretty easily convert the code that I had before into React components -- which allowed me to re-use a lot of the things like the headers and template.html that I had before. I just had to convert it to React code.
Porting the service code for the posts was really easy, but I did stumble a bit once the markdown was being spit out -- I used a very easy .md -> .html converter but was missing a lot of global styling due to Tailwind's css reset. Updating globals.css easily fixed that
Ended up moving some files around a bit more based on how I like things laid out, I'm pretty content with how things are laid out now.
Time to run vercel
and see if I can just deploy this magically
Ran into a problem with the param of slug
being sent to the Post component for rendering. Simple to fix this by following the steps here: generateStaticParams.
Basically what is happening here is that Next.js can statically generate all of the routes for each of the posts that I have by defining this function
Pretty cool because then I assume that this all happens at compile time because everything is static, letting us serve the page faster
The code for this is really simple:
export async function generateStaticParams() {
const postsService = new PostsService();
const posts = await postsService.getAllPosts();
return posts
.filter(({ title }) => title.endsWith(".md"))
.map(({ title }) => ({
slug: title.replace(/\.md$/, ""),
}));
}
It just fetches all the posts and for each of them returns what the slug would be, which is effectively the url: /blog/making-of
in this case
Running vercel
again works, so going to repoint my domain to the new project I made and we should be good to go!
Thanks for following along! Check out the github repo and hit me up if you have any questions!