Replies: 2 comments 3 replies
-
There's virtually none, for your own use case. This is what |
Beta Was this translation helpful? Give feedback.
-
To be honest I have never been a fan of That's why I plan to improve the plugin API over time, starting with export default function friendsPlugin(context, options) {
return {
name: 'docusaurus-friends-plugin',
async contentLoaded({content, actions}) {
actions.addRoute({
path: '/friends',
component: '@site/src/components/Friends.js',
exact: true,
props: {
friends: ['Yangshun', 'Sebastien']
}
});
},
};
} It is also possible that we'll introduce another method such as Back to your case: import Data from '@site/.docusaurus/{{pluginName}}/default/data.json'; Yes that would work, you can also do this BTW: import Data from '@generated/{{pluginName}}/default/data.json'; But as @Josh-Cena said you are coupling to the json path. Note that doing this does not give you any advantage over just using So, that's fine to use |
Beta Was this translation helpful? Give feedback.
-
We are using an external CMS for some data. I was reading the docs to understand the functionality of createData in the async contentLoaded plugin API. I see that you can create a JSON file with that and it's stored in the .docusaurus folder for that plugin. I also saw alot of discussions about getting content from an external API and the different approaches suggested. The approach we took was to use the createData to create a JSON file from data we get from the CMS in loadContent() function. We then import that data in a React component, like below and then just use that data as we need to:
Is there anything wrong with this approach? I didn't see this in any code examples. Usually it seems like the JSON data is passed to some component as a prop when running addRoute in the API, but is there is anything wrong with just importing the JSON file in a component, when it's not used in a route? I haven't seen any issues doing it this way, and just wondering why this is not a recommended approach in many instances, because the ability to create JSON files on build is a very helpful feature.
Beta Was this translation helpful? Give feedback.
All reactions