-
❗️ ProblemWe want to conditionally exclude Markdown docs based on a custom enabled_languages frontmatter field, matching the current locale. For example: This works in en and sv, but should be excluded in for example fi, pt-BR, etc. 🧪 What We Tried (but failed due to build model constraints)
A few other likely similar approaches have been tried during our experiments... :-) 💡 What We Would likeA clean and official hook or mechanism to conditionally exclude docs based on frontmatter per locale, before content is loaded or compiled. Or any other way we can simply "exclude" content per locale, and make sure those specific files are not included as the language specific site is built. Has anyone attempted this and got it working? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
|
Having locale-only docs/pages is a feature I often get asked about, but by design, it breaks assumptions Docusaurus makes that all locales all have the exact same pages, as I explained here: #11001 If you break this assumption, you are not really localizing an existing site. Instead, you are creating distinct sites for each locale.
That's not totally true. You can access the current locale with Although the API is quite bad, it's evaluated once globally ( See also #4542 (comment) You can also use
You can pass
Not sure what you mean 😅 need to see the attempt.
Again, if you do this, you are not localizing your site. You are building distinct sites. If the localized sites are mostly the same, I'd recommend to not delete the pages, but replace the content with some thing like "this content doesn't exist in this language", or adding code to perform a redirect to some other page. This can eventually be automated using a remark plugin that replaces content with some placeholder/code based on the front matter.
We don't have an official way unfortunately. I'm open to making things easier, as long as we keep the assumption that we need for i18n SEO that the structure of the localized Docusaurus site. I created a dedicated issue/proposal: #11076 Can you please comment here and tell us what you think? Would the "redirect solution" I suggested work for your use case? Before implementing anything, I need to see if all users share the same need, which is still not 100% clear right now. |
Beta Was this translation helpful? Give feedback.
Glad it helps, thanks
I'll see if other users come with different needs in the related issue #11076