Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.
This repository was archived by the owner on May 13, 2024. It is now read-only.

$pagination.pages contains extra page not in directory #32

Closed
@slanden

Description

@slanden
  • I confirm that this is an issue rather than a question.

Bug report

Steps to reproduce

  • I prepared a reproduction repo, here is the reproduction repo:

  • This issue doesn't need a reproduction repro, here is the steps to reproduce

  1. npm i -D vuepress @vuepress/plugin-blog
  2. add the following to package.json scripts: "dev": "vuepress dev src"
  3. add src/.vuepress/theme/layouts directory with Layout.vue file
  4. in Layout.vue add the following:
<template>
  <div v-if="$route.path === '/'">
    {{log({path: $route.path, equal: $route.path === '/'})}}
    <Content />
  </div>
  <div v-else>
    {{log($pagination.pages)}}
    <div v-for="page in $pagination.pages">{{page.title}}</div>
    <Pagination v-if="$pagination" />
  </div>
</template>

<script>
import { Pagination } from "@vuepress/plugin-blog/lib/client/components";
export default {
  components: { Pagination },
  methods: {
    log(x) {
      console.log(x);
    }
  }
};
</script>
  1. in the .vuepress folder, add config.js with the following:
module.exports = {
  plugins: [
    [
      '@vuepress/blog',
      {
        directories: [
          {
            // Unique ID of current classification
            id: 'post',
            // Target directory
            dirname: 'posts',
            // Path of the `entry page` (or `list page`)
            path: '/posts/',
            itemPermalink: '/:regular'
          },
        ],
        globalPagination: {
          lengthPerPage: 3
        }
      },
    ],
  ],
}
  1. add src/posts/ directory with at least four test MD files. Four, because I set the pagination length to 3. They can be empty.
  2. npm run dev
  3. open in a web browser and navigate to /posts
  4. navigate to the last pagination page using the Pagination component
  5. inspect the console for an object which will contain $pagination.pages
  6. notice that there will be an extra page logged with a path property like /posts/page/2/
  7. in config.js, in the directory classifier, remove the trailing slash from path: '/posts/' to path: '/posts'
  8. restart the server (Vuepress doesn't hot reload configs and MD files) and repeat steps 8-10
  9. notice that the logged $pagination.pages does not contain the extra page like before

What is expected?

$pagination.pages is expected to only contain the pages that exist in the /posts directory.

What is actually happening?

According to the docs, the trailing slash is correct. However, this seems to incorrectly add some sort of non-post page in the $pagination.pages array on the last pagination page.

This is a problem because a blog index component, such as the one in the official blog theme, builds the list of posts by looping with v-for="page in $pagination.pages".

In the official theme, it's not as noticeable but it creates an empty "post" at the end. For me, I'm listing the posts in a card style and on the last page, I have this weird empty/garbage card at the end.

Other relevant information

  • npx vuepress info:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions