Skip to content
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

breadcrumb #3534

Open
4 tasks done
pclokcer opened this issue Feb 2, 2024 · 7 comments
Open
4 tasks done

breadcrumb #3534

pclokcer opened this issue Feb 2, 2024 · 7 comments
Labels
enhancement New feature or request has-workaround Has workaround, low priority stale theme Related to the theme

Comments

@pclokcer
Copy link

pclokcer commented Feb 2, 2024

Is your feature request related to a problem? Please describe.

nope

Describe the solution you'd like

Screenshot_2

I want to breadcrumb like this.

Describe alternatives you've considered

No response

Additional context

No response

Validations

@brc-dd
Copy link
Member

brc-dd commented Feb 2, 2024

You can use one of our layouts slots to add a breadcrumbs component there.

@brc-dd brc-dd added the has-workaround Has workaround, low priority label Feb 2, 2024
@pclokcer
Copy link
Author

pclokcer commented Feb 2, 2024

You can use one of our layouts slots to add a breadcrumbs component there.

this is temporary solve. I dont want to custom component

@ruslan-onishchenko

This comment was marked as spam.

@github-actions github-actions bot added the stale label Apr 12, 2024
@peterbe
Copy link

peterbe commented May 23, 2024

You can use one of our layouts slots to add a breadcrumbs component there.

That would be cool! Do we have any examples of that?
In my case, I don't really have control over the .md files that I put into the source directory.
My site uses:

cp -r ../some-other-repo/docs .
npm run build:docs

@brc-dd
Copy link
Member

brc-dd commented May 23, 2024

@peterbe Do your markdown files have some data in frontmatter that can tell their breadcrumb path? Asking because the final part of breadcrumb can be inferred from title, but not the other parts. Otherwise you'll need to maintain a list of data yourself 👀

Regarding layout slots, they are added via theme - https://vitepress.dev/guide/extending-default-theme#layout-slots - you can use doc-top/doc-before probably.

@peterbe
Copy link

peterbe commented May 23, 2024

Do your markdown files have some data in frontmatter that can tell their breadcrumb path? Asking because the final part of breadcrumb can be inferred from title, but not the other parts. Otherwise you'll need to maintain a list of data yourself 👀

It does not know about where it lives. All an individual file knows is that it's parent directory is called my-cool-directory but it doesn't know that the title for that directory should be My Coolio Dir (for example).

I'm trying to learn about https://vitepress.dev/guide/data-loading#createcontentloader and how it could make it possible to retroactive attach these. Still new to this :)

@brc-dd
Copy link
Member

brc-dd commented May 23, 2024

If you can maintain an object like this:

const names = {
  'my-cool-directory': 'My Cool Dir',
  ...
}

You can use https://vitepress.dev/reference/site-config#transformpagedata to do something like this:

// .vitepress/config.ts

export default defineConfig({
  transformPageData(pageData) {
    pageData.frontmatter.breadcrumbs = [...pageData.relativePath.split('/').slice(0, -1).map(x => names[x]), pageData.title]
  }
})

And then use this data in your vue component:

https://stackblitz.com/edit/vite-rqxgjj

@brc-dd brc-dd added enhancement New feature or request theme Related to the theme and removed stale labels May 23, 2024
@github-actions github-actions bot added the stale label Jun 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request has-workaround Has workaround, low priority stale theme Related to the theme
Projects
None yet
Development

No branches or pull requests

4 participants