vitepress icon indicating copy to clipboard operation
vitepress copied to clipboard

Prev/Next link text in sidebar config

Open davidjr82 opened this issue 2 years ago • 4 comments

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

When the next/prev link text is generated, it takes the text from the frontmatter of the current page you are seeing. If empty, the text will be inferred from the sidebar config.

When inferred from sidebar, sometimes is weird. For example, in the vitepress api docs the "Next" text is "Introduction", and for me it should be "Themes - Introduction" (what if I have 3 sections with the introduction title?).

When using frontmatter, I can change the text in the guide/api page, but this means that if I add new documentation after the api page, the next text in the api page will be wrong.

Problem: In my opinion, the Next/Prev link should be defined in the same page (in this example, in the themes/introduction page), or in the same line as a new option in config.js for the themes/introduction page.

Describe the solution you'd like

Add nextPrevText property in sidebar items in config.js file, as follows:

        sidebar: [
            {
                text: 'Theme',
                items: [
                    { text: 'Introduction', link: '/theme/', nextPrevText: 'Theme - Introduction' },
                ]
            },

and change the priority of rendering the NextPrev text to the following:

  1. frontmatter of current page
  2. sidebar nextPrevText config of the next/prev page
  3. inferred from sidebar config

Describe alternatives you've considered

Add nextPrevText in the frontmatter of the page I am going to go.

Additional context

https://vitepress.vuejs.org/guide/api

imagen

Validations

davidjr82 avatar Sep 20 '22 07:09 davidjr82

@brc-dd This is exactly the problem I was describing. Here you can customize the text in the page you are coming from, not in the page you are going to. The reasons why I think that is not good were in my first post.

davidjr82 avatar Sep 20 '22 09:09 davidjr82

Yeah sorry about that. I hadn't read it properly. But currently we don't have any mechanism to access page data (including frontmatter) of a different (previous/next) page. Stuff might get complex while adding this functionality. Also, I don't think there will be a huge number of such pages where you'll need to customize that. I understand that it won't be best DX to keep track of these things, but IG current solution is usable.

brc-dd avatar Sep 20 '22 09:09 brc-dd

Yes, I thought the same about adding frontmatter to the destination page.

But what about adding to config.js sidebar object? I don't know how it works, but if right now it is using the config.js to guess the sidebar, it should not be that difficult to add the text in the destination, since right now the building process is reading the title text of the destination to do it.

It should be as simple as get other property (nextPrevText in my example) if present instead of the title property, isn't it?

davidjr82 avatar Sep 20 '22 09:09 davidjr82

Yeah using sidebar config it can be done IG. This most likely will be used only when context (sidebar group) is changed. So we can probably introduce some property there and modify our composable.

brc-dd avatar Sep 20 '22 09:09 brc-dd