-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
Allow configuring the title of a sidebar link in sidebar.js
in plugin-docs
#4314
Comments
That's something we could add easily, will ask one of our MLH fellows to take a look at this. |
@vjpr we agree that you want to "override" the doc title set in frontmatter through the sidebar file? What's your usecase for defining a name in sidebars.js instead of using the doc sidebar_label frontmatter? Should it be named label? (because your snippet show "title") Label is already allowed by the other sidebar types like category and link so it could be more consistent. |
I want the page title to be sentence case. My file is ‘foo.md’ and I want
the page title to be ‘Foo’.
My ultimate use case is to have an “auto sidebar” that matches the file
system structure. Seems like this would be a pretty popular use case also.
At the moment I do this manually.
…On Mon 1. Mar 2021 at 18:58, Sébastien Lorber ***@***.***> wrote:
@vjpr <https://github.com/vjpr> we agree that you want to "override" the
doc title set in frontmatter through the sidebar file?
What's your usecase for defining a name in sidebars.js instead of using
the doc sidebar_label frontmatter?
Should it be named label? (because your snippet show "title")
Label is already allowed by the other sidebar types like category and link
so it could be more consistent.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4314 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACEWRLIUTFXG3CL2I7BHLDTBPIVFANCNFSM4YKO7P6A>
.
|
Label is good.
…On Mon 1. Mar 2021 at 19:08, Vaughan Rouesnel ***@***.***> wrote:
I want the page title to be sentence case. My file is ‘foo.md’ and I want
the page title to be ‘Foo’.
My ultimate use case is to have an “auto sidebar” that matches the file
system structure. Seems like this would be a pretty popular use case also.
At the moment I do this manually.
On Mon 1. Mar 2021 at 18:58, Sébastien Lorber ***@***.***>
wrote:
> @vjpr <https://github.com/vjpr> we agree that you want to "override" the
> doc title set in frontmatter through the sidebar file?
>
> What's your usecase for defining a name in sidebars.js instead of using
> the doc sidebar_label frontmatter?
>
> Should it be named label? (because your snippet show "title")
>
> Label is already allowed by the other sidebar types like category and
> link so it could be more consistent.
>
> —
> You are receiving this because you were mentioned.
>
>
> Reply to this email directly, view it on GitHub
> <#4314 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AACEWRLIUTFXG3CL2I7BHLDTBPIVFANCNFSM4YKO7P6A>
> .
>
|
Yes but why don't you set this sentence case syntax in the doc frontmatter exactly? https://v2.docusaurus.io/docs/next/api/plugins/@docusaurus/plugin-content-docs#markdown-frontmatter ---
id: foo
title: fOO
sidebar_label: FoO
---
My Document Markdown content Is there any case where you would want a sidebar label that can't be hardcoded in the frontmatter? and for what reason? |
It's just inconvenient to have to add a |
So, adding I don't understand why exactly this is less convenient. In all cases if you need a custom sidebar label the creator of the document would have to remember to add that custom label |
The label is not added manually...my sidebars.js codemodule.exports = function (docsDir, overrides = [], excludes = []) {
if (debug) console.log('----------')
docsDir = require('path').resolve(docsDir)
const filteredTree = dirTree(docsDir, {
extensions: /\.(md|mdx)$/,
exclude: [/node_modules/, ...excludes],
})
const sidebarTree = treeToDocuSidebarTreeShorthand(filteredTree)
// See: https://v2.docusaurus.io/docs/sidebar#creating-a-hierachy
function treeToDocuSidebarTreeShorthand(node) {
if (!node) return
// File (leaf)
if (node.type === 'file') {
const id = getDocumentIdFromPath(node, docsDir)
// TODO(vjpr): We skip ids starting with dots because Docusaurus doesn't support them right now.
if (id.startsWith('.')) return
return {
type: 'doc',
id,
}
}
// Directory
if (node.type === 'directory') {
const out = {
type: 'category',
label: changeCase.sentenceCase(node.name),
items: node.children
.map(child => treeToDocuSidebarTreeShorthand(child))
.filter(Boolean), // Filter trees with no markdown files.
}
if (out.items.length) return out
return
}
}
const sidebarTreeItems = sidebarTree?.items ?? []
// We use `.items` because the first dir is the docs dir which whose level we don't want to show.
const out = [...sidebarTreeItems, ...overrides]
if (debug) console.log(JSON.stringify(out, null, 2))
return out
} |
I see thanks Allowing to add frontmatter through the sidebars file is a more generic solution, maybe we should just focus on that to enable all use-cases? What if the frontmatter is defined in the doc and the sidebar, which one wins? Should we shallow-merge or fully replace one frontmatter by the other? |
I feel like explicit frontmatter should win.
…On Tue 2. Mar 2021 at 17:24, Sébastien Lorber ***@***.***> wrote:
I see thanks
Allowing to add frontmatter through the sidebars file is a more generic
solution, maybe we should just focus on that to enable all use-cases?
What if the frontmatter is defined in the doc and the sidebar, which one
wins? Should we shallow-merge or fully replace one frontmatter by the other?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4314 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACEWRJN3SLEOII6HZMRBGLTBUGM5ANCNFSM4YKO7P6A>
.
|
After thinking about this, I think we should just let the sidebar provides its own label That would be a bit weird to allow the sidebar config to override doc frontmatter, and there's already a workaround where you can assign a https://v2.docusaurus.io/docs/next/sidebar#passing-custom-props We can still add the ability to set the label through the sidebar, as a shortcut. |
hey @slorber, We were migrating our Docs from
Is there any way possible that we can change the title/sidebar_label of the files from But adding label to a
label only seem to work with |
@CovalentBond can you help me understand your usecase better? What does a source doc look like? (content + filename, ideally Git repo?) Why is it complicated to add frontmatter to the 200 docs and why it is better to do that on sidebars.js instead? Wouldn't this complicate the maintenance on the long term as authors won't understand how to set the doc title? What data do you want to provide with sidebars.js exactly? Only the doc sidebar label? Or also the doc title? Or even more frontmatter data? |
Hey, my usecase is similar to what's stated in #4425 . We have existing markdown files without frontmatter in it. Now to only add sidebar labels and title to each file, we might need to edit those existing files. Instead we are looking out for alternatives to just pass Now even if somehow we are able to pass the title from sidebar.js, we might have two headings in each file (one from existing doc and one from the Docusaurus page title). So to hide the Docusaurus title, we still might need to add And were looking if But I feel #4485 would definitely resonate with our use case to support docs without frontmatter in them |
Does this cover all your use cases? I don't feel sidebars.js is a good place to "override" the frontmatter (but it make sense to override the "sidebar_label" frontmatter), as it is possible to create docs that don't belong to any sidebar for which we still want somehow to provide the frontmatter from an "external" config. Maybe we should have a callback in the docs plugin allowing you to "modify/enhance/override" the doc frontmatter with your custom computed data? (ie you could provide/read your own config file or use data from a CMS or whatever) [
"@docusaurus/plugin-content-docs",
{
createFrontMatter: async ({ frontmatter, version, sourceFile, markdownString }) => ({
...frontmatter,
title: formatTitle(frontmatter.title),
myExtraFrontMatter: "hello"
})
}
]; Would you use this? @vjpr I think you could wire your title formatting logic here? Just wondering if you still need this once the 2 linked issues are both implemented? |
FYI the PR of @besemuna here #4500 Allows to declare the sidebar label of a doc through Does not allow (on purpose) to override the doc title frontmatter that will be used in page/document heading/title. So, not sure it will solve any of your pain points, but still think it's useful to add this. |
I thought it would be possible to do something like this:
{type: 'doc', id: 'foo', title: 'Foo'}
.However it doesn't work
Error: Unknown sidebar item keys: label.
.Say you want to automatically generate your sidebar from the file system structure inside
sidebar
.js`...this would be useful.The text was updated successfully, but these errors were encountered: