Search code examples
docusaurus

How can I find out the number of pages in my Docusarus site?


We have a rather big site. At least I think that it is big. We use documentation versioning for some parts of it.

How can I find out how many pages do I have in the current version, and how many do I have in versioned docs?


Solution

  • After some days, I thought about an idea: parse the sitemap.xml !


    Step-by-step

    1. Build your docusaurus website with:

    npm run build
    

    2. Inside the generated folder build will be the sitemap.xml. It will be something like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
        <url>
            <loc>https://your.website.com/docs/Intro</loc>
            <changefreq>weekly</changefreq>
            <priority>0.5</priority>
        </url>
    […]
    

    If you count how many <url> tags are inside the file, you will have the amount of pages.

    And, obviously, you can search for other keywords for your versioned docs.