Custom plugin - how to handle page-specific meta-data? #7253
Replies: 1 comment 1 reply
-
|
Okay, after a bit of investigation, it appears that both docs and blog support only .md and .mdx files which supports front matters. Whereas only page plugin supports all four .md, .mdx, .jsx and .tsx. Since the page plugin does not support custom front matters, it suggests to me I should restrict my users' options to .md and .mdx in line with the docs and blog plugins to benefit from custom meta-data on each page. In this case, does my index.js (contentLoaded function) loop in the products folder, read each file, call font-matter in https://www.npmjs.com/package/front-matter to read out the .md or .mdx file, use |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I am designing a custom e-commerce plugin.
The plugin works as follows:
The user of my plugin will create a folder
productsin the root directory along sidedocsandblog. Then, my plugin will ensure that each page in this folder will render a product page, and will further glue those pages together nicely with taxonomies and other features, etc. For it to be ergonomic, I want the user to be able to define custom data for each page, and have the rendering use that data to render the page. For instance, I would like the user to be able to set the price, a description, and series of options, a taxonomy, etc directly into the product page.Should all this product description go into the front-matter of each page? If so, how do I make this custom front-matter available to the components I am rendering as part of my plugin? Are there any helper functions exposed by Docusaurus, or do I have to handle it from scratch in index.js? As I create the addRoute, do I read each file for its front matter, then I use createObject over this front-matter so that the rendering component can use it as props or module?
What if the user creates a .jsx or .tsx file? If my user prefers to use this file format, how will they define the custom information without a front matter? Is there a convention here in Docusaurus?
Beta Was this translation helpful? Give feedback.
All reactions