Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: rewrite #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 40 additions & 34 deletions components/Pagination.vue
Original file line number Diff line number Diff line change
@@ -1,56 +1,62 @@
<template>
<div
class="pagination"
v-if="$pagination"
v-if="pagination"
>
<router-link
class="prev"
title="新的文章"
v-if="$pagination.hasPrev"
:to="$pagination.prevLink"
v-if="pagination.hasPrev"
:to="pagination.prevLink"
>
新的文章
</router-link>
<router-link
class="next"
title="旧的文章"
v-if="$pagination.hasNext"
:to="$pagination.nextLink"
v-if="pagination.hasNext"
:to="pagination.nextLink"
>
旧的文章
</router-link>
</div>
</template>

<script>
export default {
props: ['pagination']
}
</script>

<style lang="stylus">
.pagination
a
margin-right: 20px
color: #b58900
height: 38px
line-height: 38px
transition: all .3s ease
position: relative
overflow: hidden
display: inline-block
background: #eee8d5
padding: 0 15px
text-decoration: none
&:before
content: attr(title)
width: 100%
left: 0
transform: translateX(-100%)
text-align: center
top: 0
bottom: 0
background-color: #b58900
position: absolute
transition: transform .3s ease
z-index: 1
color: #eee8d5
&:hover
color: #eee8d5
.pagination
a
margin-right: 20px
color: #b58900
height: 38px
line-height: 38px
transition: all .3s ease
position: relative
overflow: hidden
display: inline-block
background: #eee8d5
padding: 0 15px
text-decoration: none
&:before
transform: translateX(0)
content: attr(title)
width: 100%
left: 0
transform: translateX(-100%)
text-align: center
top: 0
bottom: 0
background-color: #b58900
position: absolute
transition: transform .3s ease
z-index: 1
color: #eee8d5
&:hover
color: #eee8d5
&:before
transform: translateX(0)
</style>
1 change: 1 addition & 0 deletions example/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = {
{ text: 'donate', link: '/donate.html' },
{ text: 'tag', link: '/tag/' },
{ text: 'category', link: '/category/' },
{ text: 'archive', link: '/archive/' },
]
},
markdown: {
Expand Down
1 change: 1 addition & 0 deletions example/about.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
layout: Page
title: 关于这个可爱的男孩子
subtitle: 先定一个小目标,写出能用的代码就行了。
---
Expand Down
1 change: 1 addition & 0 deletions example/donate.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
layout: Page
title: 捐赠支持
---

Expand Down
3 changes: 2 additions & 1 deletion example/girls.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
layout: Page
title: 那些吸引我的女孩子们
subtitle: 来自 EGOIST 的告白
waifus:
Expand Down Expand Up @@ -163,4 +164,4 @@ export default {
}
}
}
</script>
</script>
6 changes: 5 additions & 1 deletion example/index.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
layout: Layout
---

<div class="egoist-name">
egoist
<span class="dot">.</span>
Expand Down Expand Up @@ -78,4 +82,4 @@ export default {
.egoist-name
font-size: 1.6rem;
margin: 5px 0 15px 0;
</style>
</style>
71 changes: 69 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,77 @@
const path = require('path')

const POST_PERMALINK = '/:year/:month/:day/:slug'

module.exports = {
name: 'vuepress-theme-egoist',
plugins: [
'@vuepress/blog',
'@vuepress/pagination',
['@vuepress/blog', {
// 基于目录的分类
// 声明哪些目录下的文档将会被认为是 post
// name 声明了类型
// dirname 声明了子目录的名字
// permalink 决定了该目录下所有 post 将会采用的 permalink pattern
directories: [
{
id: 'post',
dirname: '_posts',
// 列表页(只有一个)
path: '/post/',
layout: 'IndexPost',
// 详情页(N个)
itemLayout: 'Post',
itemPermalink: POST_PERMALINK,
// 通过 this.$pagination.$post 访问
pagination: {
perPagePosts: 10
}
},
{
id: 'archive',
dirname: '_archive',
// 列表页(只有一个)
path: '/archive/',
layout: 'Archive',
// 详情页(N个)
itemLayout: 'Post',
itemPermalink: `/archive/${POST_PERMALINK}`,
// 通过 this.$pagination.$archive 访问
pagination: {
perPagePosts: 10
}
}
],
// 基于 frontmatter 的分类
// 声明哪些目录下的文档将会被认为是额外添加的聚合页
// name 决定了 fronmatter 上分类的属性名
// path 决定了该聚合页的路径
frontmatters: [
{
id: "category",
keys: ['category', 'categories'],
path: '/category/',
layout: 'Categories',
frontmatter: { title: 'Categories' },
itemlayout: 'Category',
// 通过 this.$pagination.$category 访问
pagination: {
perPagePosts: 10
}
},
{
id: "tag",
keys: ['tag', 'tags'],
path: '/tag/',
layout: 'Tags',
frontmatter: { title: 'Tags' },
itemlayout: 'Tag',
// 通过 this.$pagination.$category 访问
pagination: {
perPagePosts: 10
}
}
]
}],
[
'@vuepress/search', {
searchMaxSuggestions: 10
Expand Down
44 changes: 44 additions & 0 deletions layouts/Archive.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<template>
<LayoutWrapper>
<div class="main">
<Content/>
<List :items="pages"/>
<Pagination :pagination="pagination"/>
</div>
</LayoutWrapper>
</template>

<script>
export default {
created() {
this.pagination.setIndexPage('/archive/')
},
computed: {
pagination () {
return this.$pagination('archive')
},
pages () {
return this.pagination.pages
}
}
}
</script>

<style lang="stylus">
.post-title
font-weight: 300
font-size: 2rem
margin: 0 0 15px 0
a
color: #b58900
text-decoration: none
&:hover
color: #ff69b4

@media screen and (max-width: 768px)
.post-title
font-size: 16px

.egoist-tags
margin-bottom 10px
</style>
2 changes: 1 addition & 1 deletion layouts/Categories.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<LayoutWrapper>
<div class="main">
<EgoistTags :tags="$categories.list"/>
<EgoistTags :tags="$category.list"/>
</div>
</LayoutWrapper>
</template>
Expand Down
1 change: 0 additions & 1 deletion layouts/Category.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
</div>
</LayoutWrapper>
</template>

38 changes: 38 additions & 0 deletions layouts/FrontmatterClassification.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<template>
<LayoutWrapper>
<div class="main">
<div class="page-header">
<h2 class="page-title">{{ paths.pid + ' = "' + paths.id + '"'}}</h2>
</div>
<List :items="pagination.pages"/>
<Pagination :pagination="pagination"/>
</div>
</LayoutWrapper>
</template>

<script>
export default {
created () {
},
computed: {
pagination () {
const { pid, id } = this.paths
return this.$pagination(pid, id)
},
paths () {
const path = this.$route.path
const [pid, id] = path.split('/').filter(v => v)
return {
pid,
id
}
}
}
}
</script>

<style>
.page-title {
text-transform: uppercase;
}
</style>
26 changes: 21 additions & 5 deletions layouts/Layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,29 @@
<LayoutWrapper>
<div class="main">
<Content/>
<EgoistTags :tags="$tags.list.slice(0, 10)"/>
<List :items="$pagination.posts"/>
<Pagination/>
<EgoistTags :tags="$tag.list.slice(0, 10)"/>
<List :items="pages"/>
<Pagination :pagination="pagination"/>
</div>
</LayoutWrapper>
</template>

<script>
export default {
created() {
this.pagination.setIndexPage('/')
},
computed: {
pagination () {
return this.$pagination('post')
},
pages () {
return this.pagination.pages
}
}
}
</script>

<style lang="stylus">
.post-title
font-weight: 300
Expand All @@ -19,11 +35,11 @@
text-decoration: none
&:hover
color: #ff69b4

@media screen and (max-width: 768px)
.post-title
font-size: 16px

.egoist-tags
margin-bottom 10px
</style>
2 changes: 1 addition & 1 deletion layouts/Tags.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<LayoutWrapper>
<div class="main">
<EgoistTags :tags="$tags.list"/>
<EgoistTags :tags="$tag.list"/>
</div>
</LayoutWrapper>
</template>
Expand Down
Loading