I am trying to implement a "Get random page" link in Docusaurus. For that I would like to get a list of all available pages/page ids+path from the docs/ directory.
Does Docusaurus have a way to do this programmatically?
I am trying to implement a "Get random page" link in Docusaurus. For that I would like to get a list of all available pages/page ids+path from the docs/ directory.
Does Docusaurus have a way to do this programmatically?
I did not find any native or plugin way to achieve this... Here is how I you do it:
PART 1
Once you built you docusaurus website, will be generated a sitemap.xml file.
This file is locate at the root directory of your site and contains all of the url of the doc pages.
Create a js function that read this file and parse it. Then get a random url open it.
TIP 1: https://www.w3schools.com/xml/xml_parser.asp
TIP 2: https://www.w3schools.com/jsref/met_win_open.asp
PART 2
Then, you can embed your JavaScript using the mdx function of docusaurus.
TIP: How can I add custom scripts in index.html's head part in Docusaurus V2?