Skip to content

Commit 5a366e6

Browse files
authored
Merge pull request #74 from eliasparis/custom-image-options
feat: opens the door for custom image attrs or component through props
2 parents be5c788 + 9438f7f commit 5a366e6

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

docs/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@ pageLinkOptions: {
8989

9090
– the [target attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-target) of links referencing other pages (skipped for pages with `pageLinkeOptions`)
9191

92+
### `imageOptions`: Object
93+
94+
– this Object can be use to specify a custom Vue component you want to use to render pictures. Any other key in this object will spread as element attributes
95+
96+
```js
97+
imageOptions: {
98+
component: "LazyLoadImage",
99+
attribute: "vue-notion-attr"
100+
}
101+
```
102+
92103
### `prism`: Boolean
93104

94105
– whether or not syntax-highlighting using Prims.js should be activated.

src/blocks/helpers/image.vue

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
11
<template>
22
<div v-if="f.block_aspect_ratio" :style="style">
3-
<img class="notion-image-inset" :alt="alt || 'Notion image'" :src="src" />
3+
<component v-if="hasImageComponent" :is="imageOptions.component" class="notion-image-inset" :alt="alt || 'Notion image'" :src="src" v-bind="attrs"/>
4+
<img v-else class="notion-image-inset" :alt="alt || 'Notion image'" :src="src" v-bind="attrs" />
45
</div>
5-
<img v-else :alt="caption" :src="src" />
6+
<component v-else-if="hasImageComponent" :is="imageOptions.component" :alt="alt || 'Notion image'" :src="src" v-bind="attrs" />
7+
<img v-else :alt="caption" :src="src" v-bind="attrs" />
68
</template>
79

810
<script>
9-
import Blockable, { blockComputed } from "@/lib/blockable";
11+
import Blockable from "@/lib/blockable";
1012
1113
export default {
1214
extends: Blockable,
1315
name: "NotionImage",
1416
computed: {
15-
...blockComputed,
1617
alt() {
1718
return this.caption?.[0][0];
1819
},
1920
src() {
2021
return this.mapImageUrl(this.properties?.source[0][0], this.block);
2122
},
23+
attrs() {
24+
const {component, ...attrs} = this.imageOptions || {}
25+
return attrs;
26+
},
27+
hasImageComponent() {
28+
return !!this.imageOptions?.component;
29+
},
2230
style() {
2331
const aspectRatio =
2432
this.f.block_aspect_ratio || this.f.block_height / this.f.block_width;

src/components/notion-renderer.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export default {
3333
mapImageUrl: { type: Function, default: defaultMapImageUrl },
3434
mapPageUrl: { type: Function, default: defaultMapPageUrl },
3535
pageLinkOptions: Object,
36+
imageOptions: Object,
3637
prism: { type: Boolean, default: false },
3738
todo: { type: Boolean, default: false },
3839
},

src/lib/blockable.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const blockProps = {
1111
mapImageUrl: Function,
1212
mapPageUrl: Function,
1313
pageLinkOptions: Object,
14+
imageOptions: Object,
1415
pageLinkTarget: { type: String, default: "_self" },
1516
prism: { type: Boolean, default: false },
1617
katex: { type: Boolean, default: false },
@@ -32,6 +33,7 @@ export const blockComputed = {
3233
mapImageUrl: this.mapImageUrl,
3334
mapPageUrl: this.mapPageUrl,
3435
pageLinkOptions: this.pageLinkOptions,
36+
imageOptions: this.imageOptions,
3537
prism: this.prism,
3638
katex: this.katex,
3739
todo: this.todo,

0 commit comments

Comments
 (0)