Skip to content

Commit f2a9aab

Browse files
authored
Merge pull request #12 from Geminii/nuxt-build-modules
Nuxt build modules
2 parents 91a527c + 839ecd5 commit f2a9aab

File tree

11 files changed

+16741
-35
lines changed

11 files changed

+16741
-35
lines changed

README.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,21 @@ This package doesn't handle the communication with the API. Check out [notion-ap
5757
npm install vue-notion
5858
```
5959

60+
### NuxtJS Module
61+
```js
62+
// nuxt.config.js
63+
64+
export default {
65+
// ...
66+
buildModules: [
67+
'vue-notion/nuxt'
68+
]
69+
notion: {
70+
// additionals configuration
71+
}
72+
}
73+
```
74+
6075
## How To
6176

6277
### Docs
@@ -65,7 +80,7 @@ npm install vue-notion
6580
6681
More information on the `NotionRenderer` specification, syntax-highlighting, the Notion API, and integration with Nuxt can be found at [`docs/`](https://github.com/janniks/vue-notion/tree/main/docs).
6782

68-
### Basic Example
83+
### Basic Example for Vue
6984

7085
This example is hosted at [vue-notion.now.sh/welcome](https://vue-notion.now.sh/welcome).
7186

@@ -95,6 +110,33 @@ export default {
95110
The example above uses a simple wrapper around the [notion-api-worker](https://github.com/splitbee/notion-api-worker).
96111
It is also possible to store and use plain `.json` objects received from the Notion API.
97112

113+
### Basic Example for Nuxt
114+
115+
This example is hosted at [vue-notion.now.sh/welcome](https://vue-notion.now.sh/welcome).
116+
117+
```vue
118+
<template>
119+
<NotionRenderer :blockMap="blockMap" fullPage />
120+
</template>
121+
122+
<script>
123+
export default {
124+
data: () => ({ blockMap: null }),
125+
async asyncData({ $notion }) {
126+
// use notion module to get Notion blocks from the API via a Notion pageId
127+
const blockMap = await $notion.getPageBlocks("8c1ab01960b049f6a282dda64a94afc7");
128+
129+
return { blockMap }
130+
},
131+
};
132+
133+
<style>
134+
@import "vue-notion/src/styles.css"; /* optional Notion-like styles */
135+
</style>
136+
```
137+
</script>
138+
139+
98140
> ⚠️ Use with caution.
99141
> The `getPageBlocks` and `getPageTable` are based on the private Notion API.
100142
> We can not gurantee it will stay stable.

example/nuxt.config.js

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export default {
2+
// Telemetry (https://github.com/nuxt/telemetry)
23
telemetry: false,
34

45
// Target (https://go.nuxtjs.dev/config-target)
@@ -15,23 +16,11 @@ export default {
1516
link: [{ rel: "icon", type: "image/x-icon", href: "/favicon.ico" }],
1617
},
1718

18-
// Global CSS (https://go.nuxtjs.dev/config-css)
19-
css: [],
20-
21-
// Plugins to run before rendering page (https://go.nuxtjs.dev/config-plugins)
22-
plugins: [],
23-
2419
// Auto import components (https://go.nuxtjs.dev/config-components)
2520
components: true,
2621

2722
// Modules for dev and build (recommended) (https://go.nuxtjs.dev/config-modules)
28-
buildModules: [],
29-
30-
// Modules (https://go.nuxtjs.dev/config-modules)
31-
modules: [],
32-
33-
// Build Configuration (https://go.nuxtjs.dev/config-build)
34-
build: {
35-
transpile: ["vue-notion"],
36-
},
23+
buildModules: [
24+
'vue-notion/nuxt'
25+
]
3726
};

example/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
"dependencies": {
1212
"core-js": "^3.6.5",
1313
"nuxt": "^2.14.12",
14-
"prismjs": "^1.22.0",
15-
"vue-notion": "^0.2.15"
14+
"prismjs": "^1.22.0"
1615
},
17-
"devDependencies": {}
16+
"devDependencies": {
17+
"vue-notion": "^0.2.15"
18+
}
1819
}

example/pages/_slug.vue

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,21 @@
88
</template>
99

1010
<script>
11-
import { NotionRenderer, getPageBlocks, getPageTable } from "vue-notion";
12-
1311
import "prismjs";
1412
import "prismjs/themes/prism.css";
1513
1614
export default {
17-
components: { NotionRenderer },
1815
data() {
1916
return {
2017
pageLinkOptions: { component: "NuxtLink", href: "to" },
2118
};
2219
},
23-
async asyncData({ params, error }) {
24-
const pageTable = await getPageTable("10327f9074b7433aad577ccd0020e971");
20+
async asyncData({ $notion, params, error }) {
21+
const pageTable = await $notion.getPageTable("10327f9074b7433aad577ccd0020e971");
2522
const page = pageTable.find(
2623
(item) => item.published && item.slug === params.slug
2724
);
28-
const blockMap = await getPageBlocks(page ? page.id : params.slug);
25+
const blockMap = await $notion.getPageBlocks(page ? page.id : params.slug);
2926
if (!blockMap || blockMap.error) {
3027
return error({ statusCode: 404, message: "Post not found" });
3128
}

example/pages/basic-example.vue

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
</template>
44

55
<script>
6-
import { NotionRenderer, getPageBlocks } from "vue-notion";
7-
86
export default {
9-
components: { NotionRenderer },
107
data: () => ({ blockMap: null }),
11-
async created() {
8+
async asyncData({ $notion }) {
129
// get Notion blocks from the API via a Notion pageId
13-
this.blockMap = await getPageBlocks("8c1ab01960b049f6a282dda64a94afc7");
10+
const blockMap = await $notion.getPageBlocks("8c1ab01960b049f6a282dda64a94afc7");
11+
12+
return { blockMap }
1413
},
1514
};
1615
</script>

example/pages/posts.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,9 @@
3535
</template>
3636

3737
<script>
38-
import { getPageTable } from "vue-notion";
39-
4038
export default {
41-
async asyncData({ params, error }) {
42-
const pageTable = await getPageTable("10327f9074b7433aad577ccd0020e971");
39+
async asyncData({ $notion, params, error }) {
40+
const pageTable = await $notion.getPageTable("10327f9074b7433aad577ccd0020e971");
4341
4442
// sort published pages
4543
const posts = pageTable

0 commit comments

Comments
 (0)