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

Commit 3825854

Browse files
committed
feat: create out-of-box component <newsletter>
1 parent c1fafd7 commit 3825854

File tree

8 files changed

+81
-6
lines changed

8 files changed

+81
-6
lines changed

.eslintrc.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ module.exports = {
99
},
1010

1111
globals: {
12-
COMMENT_SERVICE: true
12+
COMMENT_SERVICE: true,
13+
IS_NEWSLETTER_ENABLED: true
1314
},
1415

1516
extends: [

docs/.vuepress/public/Newsletter.png

42.4 KB
Loading

docs/components/README.md

+28
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,32 @@ export default {
9696

9797
<img src="/Vssue.png" />
9898

99+
## `<Newsletter>`
99100

101+
- Source Code: [Comment.vue](https://github.com/ulivz/vuepress-plugin-blog/blob/master/src/client/components/Newsletter.vue)
102+
103+
- Usage:
104+
105+
```vue
106+
<template>
107+
<Newsletter />
108+
</template>
109+
110+
<script>
111+
import { Newsletter } from '@vuepress/plugin-blog/lib/client/components'
112+
export default {
113+
components: {
114+
Newsletter
115+
}
116+
}
117+
</script>
118+
```
119+
- Output:
120+
121+
<img src="/Newsletter.png" width="500"/>
122+
123+
::: tip
124+
For `<Comment>` and `<Newsletter>`:
125+
126+
When you're writing your own theme, you may offer user options whether to enable or not. In this scenario, you can still simply put those components in your layout component because it has handled this condition. It'll render nothing without error if the feature is disabled.
127+
:::

docs/guide/getting-started.md

+24
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,30 @@ module.exports = {
435435
],
436436
}
437437
```
438+
439+
Again, a out-of-box component `<Newsletter>`. you can import it from `'@vuepress/plugin-blog/lib/client/components'`.
440+
441+
```vue
442+
// layouts/Post.vue
443+
<template>
444+
<div>
445+
<Content />
446+
<Newsletter />
447+
<Comment />
448+
</div>
449+
</template>
450+
451+
<script>
452+
import { Comment, Newsletter } from '@vuepress/plugin-blog/lib/client/components'
453+
454+
export default {
455+
components: {
456+
Comment,
457+
Newsletter
458+
},
459+
}
460+
</script>
461+
```
438462
## Writing a blog theme
439463

440464
If everything is ok, you can start to write a blog theme. Actually, there are only 2 necessary layout components to
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<template>
22
<div>
33
<Content />
4-
<SimpleNewsletter />
4+
<Newsletter />
55
</div>
66

77
</template>
88

99
<script>
10-
import SimpleNewsletter from "vuepress-plugin-mailchimp/src/components/SimpleNewsletter";
10+
import { Newsletter } from "../../../../../lib/client/components.js";
1111
export default {
1212
components: {
13-
SimpleNewsletter
13+
Newsletter
1414
}
1515
};
1616
</script>

src/client/components.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ import Pagination from './components/Pagination.vue';
44
import SimplePagination from './components/SimplePagination.vue';
55
// @ts-ignore
66
import Comment from './components/Comment.vue';
7+
// @ts-ignore
8+
import Newsletter from './components/Newsletter.vue';
79

8-
export { Pagination, SimplePagination, Comment };
10+
export { Pagination, SimplePagination, Comment, Newsletter };

src/client/components/Newsletter.vue

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<template>
2+
<SimpleNewsletter v-if="isNewsletterEnabled" />
3+
</template>
4+
<script>
5+
export default {
6+
data() {
7+
return {
8+
isNewsletterEnabled: IS_NEWSLETTER_ENABLED,
9+
};
10+
},
11+
mounted() {
12+
if (!this.isNewsletterEnabled) console.warn('Newsletter is disabled!');
13+
},
14+
};
15+
</script>

src/node/index.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ module.exports = (options: BlogPluginOptions, ctx: VuePressContext) => {
7070
}
7171
}
7272

73-
if (options.newsletter && options.newsletter.endpoint) {
73+
const isNewsletterEnabled = !!(
74+
options.newsletter && options.newsletter.endpoint
75+
);
76+
77+
if (isNewsletterEnabled) {
7478
plugins.push(['vuepress-plugin-mailchimp', options.newsletter]);
7579
}
7680

@@ -248,6 +252,7 @@ export default ${serializePaginations(ctx.serializedPaginations, [
248252

249253
define: {
250254
COMMENT_SERVICE: options.comment && options.comment.service,
255+
IS_NEWSLETTER_ENABLED: isNewsletterEnabled,
251256
},
252257
};
253258
};

0 commit comments

Comments
 (0)