Back I rewrote my blog in Astro cover pic

I rewrote my blog in Astro

4 min read
# Astro

Hey there 👋! I’ve just migrated my blog from Next.js to Astro. In this post, I’ll dive into why I made the switch and highlight all the cool, out-of-the-box features Astro brings to the table! 😎

Why I Left Next.js😔

I was using Next.js 14 with Contentlayer, a solid setup for content-heavy sites.

Highlights

Cons

If your still planning stick with Next.js, I recommend content-collections. I found it throught this blog post very simple to integrate comes with MDX & Typescript support, and may be a good alternative to Contentlayer.

Getting to Know Astro🧐

In my case i know about astro earlier, it’s popular for content-driven sites. Started checking few open-source repos using Astro, clonned there blog website starter template. Started replicating my Next.js app on Astro

Features

Challenges

Migration process

npm create astro@latest
// astro.config.mjs file

// @ts-check
import { defineConfig } from "astro/config";

// Here are my plugins specified👇
import mdx from "@astrojs/mdx";
import react from "@astrojs/react";
import sitemap from "@astrojs/sitemap";
import tailwind from "@astrojs/tailwind";
import vercel from "@astrojs/vercel/serverless";

import { transformerNotationHighlight } from "@shikijs/transformers";

// https://astro.build/config
export default defineConfig({
  site: "https://blog.pavanbhaskar.com",

  // simply add those plugins here👇
  integrations: [mdx(), sitemap(), react(), tailwind()],

  // syntax highlighting comes by default no extra packages are required!
  markdown: {
    shikiConfig: {
      themes: {
        light: "dracula",
        dark: "everforest-light",
      },
      transformers: [transformerNotationHighlight()],
    },
  },

  vite: {
    optimizeDeps: {
      exclude: ["@resvg/resvg-js"],
    },
  },

  output: "hybrid",
  // vercel adpater is to handle dynamic API's or for Server side rendering
  adapter: vercel(),
});
// config.ts file

import { defineCollection, z } from "astro:content";

const blogConfig = defineCollection({
  type: "content",
  // Type-check frontmatter using a schema
  schema: z.object({
    title: z.string(),
    summary: z.string(),
    // Transform string to Date object
    date: z.coerce.date(),
    imageURL: z.string(),
    tags: z.array(z.string()),
  }),
});

// here i've exported blog with blogConfig
// Which means whatever content in src/content/blog folder will use blogConfig schema!
export const collections = { blog: blogConfig };

How it improved content creation process

Now, all that’s left is to keep creating content!

Bonus💫

I missed last week’s post because of the migration. Hope you enjoyed this one! ✌️