How to Display Blog and Documentation Counts in Docusaurus
· 6 min read
Adding a metric counter that displays the total number of blog articles and documentation pages is a great way to make a Docusaurus site feel active.
However, since Docusaurus compiles your pages statically, you cannot call internal hooks like useBlogPosts() inside static landing pages (such as src/pages/index.js). Doing so causes server-side rendering (SSR) failures during build execution on platforms like Vercel.
This guide provides a robust, build-time solution that counts flat files, subdirectories, and nested folders, saving the results to a static JSON file that can be safely imported anywhere in your project.
