Skip to content

Commit d04a727

Browse files
committed
feat: add named chunk plugin
1 parent 8c95f96 commit d04a727

File tree

6 files changed

+77
-84
lines changed

6 files changed

+77
-84
lines changed

docs/.vuepress/config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ const path = require('path')
33
module.exports = {
44
title: 'vuepress-theme-mini',
55
description: 'A minimal blogging theme of VuePress.',
6+
shouldPrefetch: (name) => {
7+
return name.includes('vendors~') || name.includes('layout-')
8+
},
69
theme: path.join(__dirname, '..', '..'),
710
themeConfig: {
811
hostname: 'https://vuepress-theme-mini.wxsm.space',

index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ const reverse = require('lodash.reverse')
22
const sortBy = require('lodash.sortby')
33

44
module.exports = (options, ctx) => {
5-
const plugins = {}
5+
const plugins = {
6+
['named-chunks']: {
7+
pageChunkName: (page) => 'page' + page.key.slice(1),
8+
layoutChunkName: (layout) => 'layout-' + layout.componentName,
9+
},
10+
}
611

712
if (options.hostname) {
813
plugins.sitemap = {

layouts/Archive.vue

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,29 @@
11
<template>
2-
<div class="theme-container no-sidebar">
3-
<main class="page">
4-
<div class="theme-default-content content__default">
5-
<nav-bar />
6-
<ul class="article-list">
7-
<li v-for="post in posts" :key="post.key">
8-
<h3>
9-
<template v-if="post.frontmatter.date">
10-
{{ format(new Date(post.frontmatter.date), 'MMM dd, yyyy') }}
11-
</template>
12-
</h3>
13-
<div class="list-item">
14-
<router-link :to="post.path" class="title-link">{{
15-
post.title
16-
}}</router-link>
17-
</div>
18-
</li>
19-
</ul>
20-
<footer-bar />
21-
</div>
22-
</main>
23-
</div>
2+
<page>
3+
<ul class="article-list">
4+
<li v-for="post in posts" :key="post.key">
5+
<h3>
6+
<template v-if="post.frontmatter.date">
7+
{{ format(new Date(post.frontmatter.date), 'MMM dd, yyyy') }}
8+
</template>
9+
</h3>
10+
<div class="list-item">
11+
<router-link :to="post.path" class="title-link">{{
12+
post.title
13+
}}</router-link>
14+
</div>
15+
</li>
16+
</ul>
17+
</page>
2418
</template>
2519

2620
<script>
27-
import NavBar from '@theme/components/NavBar'
28-
import FooterBar from '@theme/components/FooterBar'
21+
import Page from '@theme/layouts/Page'
2922
import format from 'date-fns/format'
3023
import postsMixin from '../mixins/posts.mixin'
3124
3225
export default {
33-
components: { NavBar, FooterBar },
26+
components: { Page },
3427
mixins: [postsMixin],
3528
methods: {
3629
format,

layouts/Pager.vue

Lines changed: 40 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,57 @@
11
<template>
2-
<div class="theme-container no-sidebar">
3-
<main class="page">
4-
<div class="theme-default-content content__default">
5-
<nav-bar />
6-
<Content />
7-
<ul class="article-list article-list-with-excerpt">
8-
<li v-for="post in postChunks[page - 1]" :key="post.key">
9-
<h3>
10-
<template v-if="post.frontmatter.date">
11-
{{ format(new Date(post.frontmatter.date), 'MMM dd, yyyy') }}
12-
</template>
13-
</h3>
14-
<div class="list-item">
2+
<page>
3+
<ul class="article-list article-list-with-excerpt">
4+
<li v-for="post in postChunks[page - 1]" :key="post.key">
5+
<h3>
6+
<template v-if="post.frontmatter.date">
7+
{{ format(new Date(post.frontmatter.date), 'MMM dd, yyyy') }}
8+
</template>
9+
</h3>
10+
<div class="list-item">
11+
<router-link :to="post.path" class="title-link" v-text="post.title" />
12+
<template v-if="post.excerpt">
13+
<div class="excerpt" v-html="post.excerpt"></div>
14+
<div class="read-more">
1515
<router-link
1616
:to="post.path"
17-
class="title-link"
18-
v-text="post.title"
17+
class="read-more-link"
18+
v-text="'Read more...'"
1919
/>
20-
<template v-if="post.excerpt">
21-
<div class="excerpt" v-html="post.excerpt"></div>
22-
<div class="read-more">
23-
<router-link
24-
:to="post.path"
25-
class="read-more-link"
26-
v-text="'Read more...'"
27-
/>
28-
</div>
29-
</template>
3020
</div>
31-
</li>
32-
</ul>
33-
34-
<div class="article-page-nav">
35-
<p class="inner">
36-
<span v-if="page > 1" class="prev"
37-
>←&nbsp;
38-
<router-link
39-
class="prev"
40-
:to="`${$page.regularPath}?page=${page - 1}`"
41-
v-text="'Newer'"
42-
/>
43-
</span>
44-
<span v-if="page < postChunks.length" class="next">
45-
<router-link
46-
:to="`${$page.regularPath}?page=${page + 1}`"
47-
v-text="'Older'"
48-
/>
49-
&nbsp;
50-
</span>
51-
</p>
21+
</template>
5222
</div>
53-
54-
<footer-bar />
55-
</div>
56-
</main>
57-
</div>
23+
</li>
24+
</ul>
25+
<div class="article-page-nav">
26+
<p class="inner">
27+
<span v-if="page > 1" class="prev"
28+
>←&nbsp;
29+
<router-link
30+
class="prev"
31+
:to="`${$page.regularPath}?page=${page - 1}`"
32+
v-text="'Newer'"
33+
/>
34+
</span>
35+
<span v-if="page < postChunks.length" class="next">
36+
<router-link
37+
:to="`${$page.regularPath}?page=${page + 1}`"
38+
v-text="'Older'"
39+
/>
40+
&nbsp;
41+
</span>
42+
</p>
43+
</div>
44+
</page>
5845
</template>
5946

6047
<script>
61-
import NavBar from '@theme/components/NavBar'
62-
import FooterBar from '@theme/components/FooterBar'
48+
import Page from '@theme/layouts/Page'
6349
import format from 'date-fns/format'
6450
import chunk from 'lodash.chunk'
6551
import postsMixin from '../mixins/posts.mixin'
6652
6753
export default {
68-
components: { NavBar, FooterBar },
54+
components: { Page },
6955
mixins: [postsMixin],
7056
data() {
7157
return {

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,13 @@
3030
"lodash.sortby": "^4.7.0",
3131
"vuepress-plugin-feed": "^0.1.9",
3232
"vuepress-plugin-flowchart-js": "^2.0.2",
33-
"vuepress-plugin-sitemap": "^2.3.1"
33+
"vuepress-plugin-sitemap": "^2.3.1",
34+
"vuepress-plugin-named-chunks": "^1.1.4"
3435
},
3536
"peerDependencies": {
3637
"vuepress": "^1.7.1"
3738
},
3839
"devDependencies": {
39-
"markdown-it-include": "2.0.0",
40-
"vuepress": "1.8.2",
4140
"eslint": "7.32.0",
4241
"eslint-config-prettier": "8.3.0",
4342
"eslint-plugin-html": "6.2.0",
@@ -46,6 +45,8 @@
4645
"eslint-plugin-prettier": "4.0.0",
4746
"eslint-plugin-promise": "5.1.0",
4847
"eslint-plugin-vue": "7.19.1",
49-
"prettier": "2.4.1"
48+
"markdown-it-include": "2.0.0",
49+
"prettier": "2.4.1",
50+
"vuepress": "1.8.2"
5051
}
5152
}

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8690,6 +8690,11 @@ vuepress-plugin-flowchart-js@^2.0.2:
86908690
dependencies:
86918691
flowchart.js "1.15.0"
86928692

8693+
vuepress-plugin-named-chunks@^1.1.4:
8694+
version "1.1.4"
8695+
resolved "https://registry.yarnpkg.com/vuepress-plugin-named-chunks/-/vuepress-plugin-named-chunks-1.1.4.tgz#c65e121a8d0bbb4201766ec06816a2aa67dae3b7"
8696+
integrity sha512-zCRVmbf10VAf8NcrVLlm1b6eGU3vkc/iLVNvpIL3sBvtCCVaZheT2OlaV0CMPE6OjjTYbMrYXjugu4vcpiXrNQ==
8697+
86938698
vuepress-plugin-sitemap@^2.3.1:
86948699
version "2.3.1"
86958700
resolved "https://registry.yarnpkg.com/vuepress-plugin-sitemap/-/vuepress-plugin-sitemap-2.3.1.tgz#51298aca77a5de96396fdbd1103e1637dd61ae6a"

0 commit comments

Comments
 (0)