vitepress icon indicating copy to clipboard operation
vitepress copied to clipboard

breadcrumb

Open pclokcer opened this issue 1 year ago • 7 comments

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

pclokcer avatar Feb 02 '24 08:02 pclokcer

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

brc-dd avatar Feb 02 '24 09:02 brc-dd

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

this is temporary solve. I dont want to custom component

pclokcer avatar Feb 02 '24 18:02 pclokcer

+1

ruslan-onishchenko avatar Feb 08 '24 19:02 ruslan-onishchenko

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

peterbe avatar May 23 '24 14:05 peterbe

@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.

brc-dd avatar May 23 '24 14:05 brc-dd

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 :)

peterbe avatar May 23 '24 16:05 peterbe

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 avatar May 23 '24 16:05 brc-dd