markhorn-dev / astro-nano

Astro Nano is a static, minimalist, lightweight, lightning fast portfolio and blog.
https://astro-nano-demo.vercel.app
251 stars 90 forks source link

Feature Request: View count for the posts #4

Open GeraltO18 opened 3 months ago

GeraltO18 commented 3 months ago

Hi @mark-horn,

I went through the space nano blog and it has the view count for each blog. It's interesting to see those stats, would it be possible to do the same here in the nano? If yes, I would be happy to take it up and would like to have your insights on developing it.

Thanks.

markhorn-dev commented 3 months ago

I probably won't do it with Nano, because one of my goals for the project was to keep it fully static / minimal.

I can point you in the right direction though.

Previously I used React and Supabase to accomplish a page counter.

You'll need to make a fetch request to your database and increment your count / fetch your count per each slug in your blog.

Keep in mind if you do this in Astro in SSG mode (nano is built SSG) it will only fetch at build time and won't update until your next build. You'll likely want to change to SSR (server rendered). Then on the server you can make your crud operations and update the page before it's served to the client.