Skip to content

Commit bddd54c

Browse files
authored
Merge pull request #83 from janniks/add-block-overrides
Add block overrides
2 parents 7d9827e + 5ba407f commit bddd54c

33 files changed

+121
-30
lines changed

dev/serve.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ Vue.use(VueKatex);
88
Vue.config.productionTip = false;
99

1010
new Vue({
11-
render: (h) => h(Dev),
11+
render: h => h(Dev)
1212
}).$mount("#app");

docs/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
The `NotionRenderer` component offers a few properties
1515

1616
- [`blockMap`](#blockMap) – required
17+
- [`blockOverrides`](#blockOverrides) – default: `{}`
1718
- [`contentId`](#contentId) – default: `undefined`
1819
- [`embedAllow`](#embedAllow) – default: `"fullscreen"`
1920
- [`fullPage`](#fullPage) – default: `false`
@@ -32,6 +33,19 @@ The `NotionRenderer` component offers a few properties
3233
– the blocks part of a Notion API response.
3334
A list of blocks by their id that may contain contents and properties.
3435

36+
### `blockOverrides`: Object
37+
38+
– the Notion blocks that should be overriden by custom registered Vue components.
39+
A key-value pair Object of Notion block names to Vue component names.
40+
41+
e.g. to use a custom `code` component—after registering the `CustomCode` Vue component—add the following override, as seen in the `/example`
42+
43+
```js
44+
blockOverrides: {
45+
code: "CustomCode",
46+
}
47+
```
48+
3549
### `contentId`: String
3650

3751
– the id of the block that should be rendered.

example/nuxt.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@ export default {
2323
buildModules: ["vue-notion/nuxt"],
2424

2525
// Plugins (e.g. vue-katex for equations)
26-
plugins: ["~/plugins/vue-katex.js"],
26+
plugins: [
27+
"~/plugins/vue-katex.js",
28+
"~/plugins/vue-custom-notion-component.js",
29+
],
2730
};

example/pages/_slug.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<template>
22
<NotionRenderer
33
:blockMap="blockMap"
4+
:blockOverrides="blockOverrides"
45
:pageLinkOptions="pageLinkOptions"
56
fullPage
67
prism
@@ -15,6 +16,7 @@ import "prismjs/themes/prism.css";
1516
export default {
1617
data() {
1718
return {
19+
blockOverrides: { code: "CustomCode" },
1820
pageLinkOptions: { component: "NuxtLink", href: "to" },
1921
};
2022
},

example/plugins/custom-code.vue

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<template>
2+
<pre
3+
class="notion-code-wrapper"
4+
:style="{
5+
border: '3px solid tomato',
6+
}"
7+
>
8+
<NotionCode v-bind="pass"/>
9+
</pre>
10+
</template>
11+
12+
<script>
13+
import { NotionCode, Blockable, blockComputed, blockProps } from "vue-notion";
14+
15+
export default {
16+
extends: Blockable,
17+
name: "CustomCode",
18+
components: {
19+
NotionCode,
20+
},
21+
props: {
22+
...blockProps,
23+
//> your own additional props
24+
},
25+
computed: {
26+
...blockComputed,
27+
//> your own additional `computed` methods go here
28+
},
29+
};
30+
</script>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import Vue from "vue";
2+
import CustomCode from "./custom-code.vue";
3+
4+
Vue.component("CustomCode", CustomCode);

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
],
1616
"scripts": {
1717
"serve": "vue-cli-service serve dev/serve.js",
18-
"example": "nuxt example",
19-
"example:pack": "npm pack && cd example && npm install && npm install ../*.tgz && npm run build && npm run generate",
18+
"example": "npm run example:generate && cd example && npm start",
19+
"example:install": "npm pack && cd example && npm install && npm install ../*.tgz",
20+
"example:generate": "npm run example:install && cd example && npm run build && npm run generate",
2021
"build": "cross-env NODE_ENV=production rollup --config build/rollup.config.js",
2122
"build:ssr": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format cjs",
2223
"build:es": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format es",
2324
"build:unpkg": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format iife",
25+
"clean": "rm -rf node_modules dist example/node_modules example/dist example/.nuxt",
2426
"release:minor": "npm version minor -m 'Release %s' && npm publish",
2527
"release:patch": "npm version patch -m 'Release %s' && npm publish",
2628
"postpublish": "echo \"\\033[31m !!! Now, manually run: ./scripts/postpublish.sh !!! \\033[00m\"",

src/blocks/bookmark.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
</template>
3636

3737
<script>
38-
import Blockable from "@/lib/blockable";
38+
import { Blockable } from "@/lib/blockable";
3939
import NotionTextRenderer from "@/blocks/helpers/text-renderer";
4040
4141
export default {

src/blocks/callout.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</template>
1111

1212
<script>
13-
import Blockable from "@/lib/blockable";
13+
import { Blockable } from "@/lib/blockable";
1414
import NotionPageIcon from "@/blocks/helpers/page-icon";
1515
import NotionTextRenderer from "@/blocks/helpers/text-renderer";
1616

src/blocks/code.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<script>
1313
import Prism from "prismjs";
1414
import PrismComponent from "vue-prism-component";
15-
import Blockable, { blockComputed, blockProps } from "@/lib/blockable";
15+
import { Blockable, blockComputed, blockProps } from "@/lib/blockable";
1616
1717
export default {
1818
extends: Blockable,

0 commit comments

Comments
 (0)