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

Commit

Permalink
feat: paginationComponent option - ability to cutom pagination component
Browse files Browse the repository at this point in the history
  • Loading branch information
ulivz committed Jun 22, 2019
1 parent a6dab8b commit 5518887
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
3 changes: 2 additions & 1 deletion example/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module.exports = {
modifyBlogPluginOptions(blogPlugnOptions) {
const archiveDirectoryClassifierIndex = blogPlugnOptions.directories.findIndex(d => d.id === 'archive')
blogPlugnOptions.directories.splice(archiveDirectoryClassifierIndex, 1)
console.log(blogPlugnOptions)
return blogPlugnOptions
},
/**
Expand Down Expand Up @@ -51,5 +50,7 @@ module.exports = {
},
],
},

// paginationComponent: 'SimplePagination'
},
}
33 changes: 30 additions & 3 deletions global-components/BaseListLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,50 @@
</div>
</div>

<Pagination :pagination="pagination"/>
<component v-if="paginationComponent" :is="paginationComponent"></component>
</div>
</template>

<script>
/* global THEME_BLOG_PAGINATION_COMPONENT */
import Toc from '@theme/components/Toc.vue'
import Pagination from '@theme/components/Pagination.vue'
import { NavigationIcon, ClockIcon } from 'vue-feather-icons'
import { Pagination, SimplePagination } from '@vuepress/plugin-blog/lib/client/components'
console.log(SimplePagination)
export default {
components: { Toc, Pagination, NavigationIcon, ClockIcon },
props: ['pagination'],
data() {
return {
paginationComponent: null
}
},
created() {
this.paginationComponent = this.getPaginationComponent()
},
computed: {
pages() {
return this.pagination.pages
}
},
},
methods: {
getPaginationComponent() {
const n = THEME_BLOG_PAGINATION_COMPONENT
if (n === 'Pagination') {
return Pagination
}
if (n === 'SimplePagination') {
return SimplePagination
}
return Vue.component(n) || Pagination
}
}
}
</script>

Expand Down
13 changes: 9 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = (themeConfig, ctx) => {
itemLayout: 'Post',
itemPermalink: '/:year/:month/:day/:slug',
pagination: {
perPagePosts: 5,
lengthPerPage: 5,
},
},
{
Expand All @@ -32,7 +32,7 @@ module.exports = (themeConfig, ctx) => {
itemLayout: 'Post',
itemPermalink: '/archive/:year/:month/:day/:slug',
pagination: {
perPagePosts: 5,
lengthPerPage: 5,
},
},
],
Expand All @@ -41,8 +41,8 @@ module.exports = (themeConfig, ctx) => {
id: "tag",
keys: ['tag', 'tags'],
path: '/tag/',
layout: 'Tags',
frontmatter: { title: 'Tags' },
layout: 'Tag',
frontmatter: { title: 'Tag' },
itemlayout: 'Tag',
pagination: {
perPagePosts: 5
Expand Down Expand Up @@ -80,6 +80,11 @@ module.exports = (themeConfig, ctx) => {

const config = {
plugins,
define: {
THEME_BLOG_PAGINATION_COMPONENT: themeConfig.paginationComponent
? themeConfig.paginationComponent
: 'Pagination'
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"author": "ulivz<chl814@foxmail.com>",
"license": "MIT",
"dependencies": {
"@vuepress/plugin-blog": "1.0.0",
"@vuepress/plugin-blog": "1.1.0",
"@vuepress/plugin-medium-zoom": "1.0.0",
"@vuepress/plugin-nprogress": "1.0.0",
"@vuepress/plugin-pwa": "1.0.0",
Expand All @@ -36,7 +36,7 @@
},
"devDependencies": {
"eslint-config-sherry": "0.0.1",
"vuepress": "1.0.0-beta.1"
"vuepress": "^1.0.0"
},
"publishConfig": {
"registry": "https://registry.npmjs.org/"
Expand Down

0 comments on commit 5518887

Please sign in to comment.