storyblok / storyblok

Info about Storyblok
https://storyblok.atlassian.net/servicedesk
318 stars 32 forks source link

Add breadcrumb property to story object #447

Open samuells opened 4 years ago

samuells commented 4 years ago

The feature would affect: (check one with "x")

Is your feature request related to a problem? Please describe. Creation of breadcrumbs with storyblok stories.

Describe the solution you'd like Would be nice to have a property with objects/parents that should be in breadcrumb according to folder structure in storyblok.

Especially if there is one story defined as root of the folder that it should be deliver in this array as parent.

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

DominikAngerer commented 4 years ago

Alternative for now as no alternativ was suggested: For this you can use the parent_id and the Links API. This allows you to directly resolve the parent_id & therefore the upper parents: https://www.storyblok.com/docs/api/content-delivery#core-resources/links/retrieve-multiple-links

dohomi commented 3 years ago

@DominikAngerer is there an example how that would look like? I don't see how that would look like with multiple links, you suggest to fetch all links and then how does the grandparents resolve?

deodat commented 2 years ago

Any news on this? I'm having so much troubles to get my breadcrumbs working. For the time being, it would be so great if we could have some example on how to get around with this.

simonmumenthaler commented 2 years ago

@dohomi @deodat I'm fetching all the links from https://api.storyblok.com/v1/cdn/links then searching all the parents in it. sth like:

/**
 * returns the parents of given `current` link
 * @param links the result from the `https://api.storyblok.com/v1/cdn/links`
 * @param current the current link you want to build the breadcrumbs for.
 */
function getParentLinks(links: Record<string, StoryBlokLink>, current: StoryBlokLink): StoryBlokLink[] {
  const items: StoryBlokLink[] = Object.values(links)

  const parents: StoryBlokLink[] = []

  let parentId: number | undefined = current.parent_id
  while (parentId) {
    const parent = items.find((item) => item.id === parentId)
    if (parent) {
      parents.push(parent)
    }
    parentId = parent?.parent_id
  }
  return parents
}
studentofcoding commented 1 year ago

Hey @simonmumenthaler, could you share how to get this running on Nuxt3 on storyblok? thanks