Skip to content

Commit

Permalink
feat: add top frontmatter
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorlxy committed Mar 23, 2019
1 parent 48ae7e3 commit b982324
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 20 deletions.
13 changes: 1 addition & 12 deletions lib/components/IconInfo.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<script>
import Icon from './Icon.vue'
const typeIconMap = {
'category': 'folder-open',
'date': 'calendar',
'email': 'mail',
'location': 'location',
'organization': 'team',
'tag': 'tag',
'tags': 'tags',
}
export default {
name: 'IconInfo',
Expand Down Expand Up @@ -41,21 +32,19 @@ export default {
type: {
type: String,
required: true,
validator: val => Object.keys(typeIconMap).includes(val),
},
},
render (h, { props: { href, size, title, type }, children }) {
const Component = href ? 'a' : 'span'
const icon = typeIconMap[type]
return (
<Component
href={href}
title={title}
>
<Icon
class="info-icon"
name={icon}
name={type}
size={size}
title={title}
/>
Expand Down
15 changes: 11 additions & 4 deletions lib/components/Iconfont.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</symbol>

<symbol
id="icon-team"
id="icon-organization"
viewBox="0 0 1024 1024"
>
<path d="M824.2 699.9c-25.4-25.4-54.7-45.7-86.4-60.4C783.1 602.8 812 546.8 812 484c0-110.8-92.4-201.7-203.2-200-109.1 1.7-197 90.6-197 200 0 62.8 29 118.8 74.2 155.5-31.7 14.7-60.9 34.9-86.4 60.4C345 754.6 314 826.8 312 903.8c-0.1 4.5 3.5 8.2 8 8.2h56c4.3 0 7.9-3.4 8-7.7 1.9-58 25.4-112.3 66.7-153.5C493.8 707.7 551.1 684 612 684c60.9 0 118.2 23.7 161.3 66.8C814.5 792 838 846.3 840 904.3c0.1 4.3 3.7 7.7 8 7.7h56c4.5 0 8.1-3.7 8-8.2-2-77-33-149.2-87.8-203.9zM612 612c-34.2 0-66.4-13.3-90.5-37.5-24.5-24.5-37.9-57.1-37.5-91.8 0.3-32.8 13.4-64.5 36.3-88 24-24.6 56.1-38.3 90.4-38.7 33.9-0.3 66.8 12.9 91 36.6 24.8 24.3 38.4 56.8 38.4 91.4 0 34.2-13.3 66.3-37.5 90.5-24.2 24.2-56.4 37.5-90.6 37.5z" />
Expand All @@ -59,21 +59,21 @@
</symbol>

<symbol
id="icon-folder-open"
id="icon-category"
viewBox="0 0 1024 1024"
>
<path d="M928 444H820V330.4c0-17.7-14.3-32-32-32H473L355.7 186.2c-1.5-1.4-3.5-2.2-5.5-2.2H96c-17.7 0-32 14.3-32 32v592c0 17.7 14.3 32 32 32h698c13 0 24.8-7.9 29.7-20l134-332c1.5-3.8 2.3-7.9 2.3-12 0-17.7-14.3-32-32-32zM136 256h188.5l119.6 114.4H748V444H238c-13 0-24.8 7.9-29.7 20L136 643.2V256z m635.3 512H159l103.3-256h612.4L771.3 768z" />
</symbol>

<symbol
id="icon-calendar"
id="icon-date"
viewBox="0 0 1024 1024"
>
<path d="M880 184H712v-64c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v64H384v-64c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v64H144c-17.7 0-32 14.3-32 32v664c0 17.7 14.3 32 32 32h736c17.7 0 32-14.3 32-32V216c0-17.7-14.3-32-32-32z m-40 656H184V460h656v380zM184 392V256h128v48c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-48h256v48c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-48h128v136H184z" />
</symbol>

<symbol
id="icon-mail"
id="icon-email"
viewBox="0 0 1024 1024"
>
<path d="M928 160H96c-17.7 0-32 14.3-32 32v640c0 17.7 14.3 32 32 32h832c17.7 0 32-14.3 32-32V192c0-17.7-14.3-32-32-32z m-40 110.8V792H136V270.8l-27.6-21.5 39.3-50.5 42.8 33.3h643.1l42.8-33.3 39.3 50.5-27.7 21.5z" />
Expand Down Expand Up @@ -185,6 +185,13 @@
<path d="M440 852H208V148h560v344c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8V108c0-17.7-14.3-32-32-32H168c-17.7 0-32 14.3-32 32v784c0 17.7 14.3 32 32 32h272c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8z" />
<path d="M885.7 903.5l-93.3-93.3C814.7 780.7 828 743.9 828 704c0-97.2-78.8-176-176-176s-176 78.8-176 176 78.8 176 176 176c35.8 0 69-10.7 96.8-29l94.7 94.7c1.6 1.6 3.6 2.3 5.6 2.3s4.1-0.8 5.6-2.3l31-31c3.1-3.1 3.1-8.1 0-11.2zM652 816c-61.9 0-112-50.1-112-112s50.1-112 112-112 112 50.1 112 112-50.1 112-112 112z" />
</symbol>

<symbol
id="icon-top"
viewBox="0 0 1024 1024"
>
<path d="M859.9 168H164.1c-4.5 0-8.1 3.6-8.1 8v60c0 4.4 3.6 8 8.1 8h695.8c4.5 0 8.1-3.6 8.1-8v-60c0-4.4-3.6-8-8.1-8zM518.3 355c-3.2-4.1-9.4-4.1-12.6 0l-112 141.7c-4.1 5.2-0.4 12.9 6.3 12.9h73.9V848c0 4.4 3.6 8 8 8h60c4.4 0 8-3.6 8-8V509.7H624c6.7 0 10.4-7.7 6.3-12.9L518.3 355z" />
</symbol>
</svg>
</template>

Expand Down
4 changes: 2 additions & 2 deletions lib/components/PostsFilterCategories.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
>

<IconTag
icon="folder-open"
icon="category"
:name="$themeConfig.lang.allCategories"
/>
</label>
Expand All @@ -27,7 +27,7 @@
>

<IconTag
icon="folder-open"
icon="category"
:name="category"
/>
</label>
Expand Down
12 changes: 12 additions & 0 deletions lib/components/PostsListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@
</RouterLink>

<p class="post-info-list">
<span
v-if="post.top"
class="post-info-item"
>
<IconInfo
type="top"
:title="$themeConfig.lang.top"
>
{{ $themeConfig.lang.top }}
</IconInfo>
</span>

<span
v-if="post.createdAt"
class="post-info-item"
Expand Down
1 change: 1 addition & 0 deletions lib/langs/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
noRelatedPosts: 'No related posts',

// post meta
top: 'Top',
createdAt: 'Created',
updatedAt: 'Updated',
prevPost: 'Previous Post',
Expand Down
1 change: 1 addition & 0 deletions lib/langs/pt-BR.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
noRelatedPosts: 'Nenhum artigo encontrado',

// post meta
top: 'Top',
createdAt: 'Criado',
updatedAt: 'Atualizado',
prevPost: 'Anterior',
Expand Down
1 change: 1 addition & 0 deletions lib/langs/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
noRelatedPosts: '没有相关文章',

// post meta
top: '置顶',
createdAt: '发布时间',
updatedAt: '最后修改',
prevPost: '上一篇',
Expand Down
2 changes: 1 addition & 1 deletion lib/layouts/Categories.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
:to="cate.path"
>
<IconTag
icon="folder-open"
icon="category"
:name="cate.name"
/>
</RouterLink>
Expand Down
10 changes: 9 additions & 1 deletion lib/plugins/blog/enhanceApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ export default ({ Vue }) => {
$posts () {
const pages = this.$site.pages
const pageFilter = p => p.type === 'post'
const pageSort = (p1, p2) => compareDesc(p1.frontmatter.date, p2.frontmatter.date)
const pageSort = (p1, p2) => {
if (p1.top === p2.top) {
return compareDesc(p1.createdAt, p2.createdAt)
}
if (p1.top && p2.top) {
return p1.top - p2.top
}
return p2.top ? 1 : -1
}
const posts = pages.filter(pageFilter).sort(pageSort)
return posts
},
Expand Down
1 change: 1 addition & 0 deletions lib/plugins/blog/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports = ({
$page.frontmatter.layout = $page.frontmatter.layout || postsLayout
$page.frontmatter.permalink = $page.frontmatter.permalink || permalink
$page.type = 'post'
$page.top = $page.frontmatter.top || false
$page.tags = $page.frontmatter.tags || []
$page.category = $page.frontmatter.category
$page.createdAt = $page.frontmatter.date ? format($page.frontmatter.date, 'YYYY-MM-DD') : null
Expand Down

0 comments on commit b982324

Please sign in to comment.