-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: structured data faqs - not fully working; basis for discussion #8954
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure to understand everything yet but that looks a bit complicated and opinionated API to me.
Is this need so common to justify the creation of a core remark plugin, enabled by default?
Couldn't this benefit other MDX-based sites as well (like Next.js/Astro?). I feel it does not really belong in Docusaurus core.
Couldn't we use a theme-common helper component for those that want to create a FAQ? Your solution here looks much simpler: https://johnnyreilly.com/docusaurus-structured-data-faqs-mdx#the-faqstructureddata-mdx-component
// faqs questions are headings | ||
|
||
const value = toString(child); | ||
if (child.depth === 2 && value === 'FAQs') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks quite opinionated to use hardcoded values like this and probably does not support i18n where headings will be translated
console.log(x, 'faqsNodes', vfile.path, faqsNodes, faqs, root); | ||
console.log('faqsNodes', vfile.path, faqs); | ||
} | ||
children[targetIndex]!.value = `export const ${name} = ${stringifyObject( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does not look like MDX v2, we merged the PR so the TOC code you got inspired from is probably very different now 🤪
There more I think about it, the less I'm convinced this is a great idea / implementation. I think I'm going to close this as a consequence. |
I think this is a good idea @slorber. I'd be happy to contribute the FAQs component to Docusaurus as a shared component if that would be helpful? |
Yes why not Was wondering if it wouldn't be simpler to add the structured data directly to the html elements instead of adding extra scripts? Like we do for blog posts: export default function BlogPostItemContainer({
children,
className,
}: Props): JSX.Element {
const {frontMatter, assets} = useBlogPost();
const {withBaseUrl} = useBaseUrlUtils();
const image = assets.image ?? frontMatter.image;
return (
<article
className={className}
itemProp="blogPost"
itemScope
itemType="http://schema.org/BlogPosting">
{image && (
<meta itemProp="image" content={withBaseUrl(image, {absolute: true})} />
)}
{children}
</article>
);
} On the usage API side, how would we use the FAQ components? With Docusauurs v3 / MDX 2 there's a new CommonMark mode (#3018) and it would be nice if this feature can be used by both I think we have 2 choices then:
:::faq[My FAQ Title]
My FAQ Content
::: |
Pre-flight checklist
Motivation
I previously built a Structured Data FAQs plugin: https://johnnyreilly.com/docusaurus-structured-data-faqs-mdx
After I did that I discovered discussion of it as a feature here: https://docusaurus.io/feature-requests/p/creation-of-structured-faq
@Josh-Cena had suggested it would be good to have this built in. I started hacking together something to do that. This approach parses MD(X) files looking for
## FAQs
and uses child headings and their answers to construct structured data FAQs as well.This PR is that. There's a number of issues:
This PR is a (not quite) POC - and before I advance it further, I wanted to see if people saw value in it. Maybe not. If they do, I'd appreciate some pointers on solving the problems.
Also happy for this to be closed - maybe this isn't a good direction.
Test Plan
Test links
Deploy preview: https://deploy-preview-_____--docusaurus-2.netlify.app/
Related issues/PRs