Skip to content

FrontMatter.top has no effect on sorting items within sidebar #554

@cxw620

Description

@cxw620

Clear and concise description of the problem

Custom sequence of items within a category is necessary when editing a docs site, Could we add a mechanism sorting it?

Suggested solution

None.

My temporal solution:

export function usePageList() {
  const routerStore = useRouterStore()
  const router = routerStore.router

  return computed<Post[]>(() => {
    const excludePages = ['/:..all', '/:all(.*)*', '/', '/:path(.*)']
    const routes = router.getRoutes()
      .filter(i => i.name)
      .filter(i => i.meta)
      .filter(i => i.meta!.frontmatter)
      .filter(i => i.path && !excludePages.includes(i.path))
      .map((i) => {
        return Object.assign({ path: i.path, excerpt: i.meta!.excerpt }, i.meta!.frontmatter || {}) as Post
      })
      

+    // For pages, also sort it.
+    routes.sort((a, b) => {
+      // console.log(a.top, b.top, 'sort post list')
+      return (b.top || 0) - (a.top || 0)
+    })
+
    return routes
  })
}

Alternative

No response

Additional context

No response

Validations

  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions