Skip to content

Commit 749d0e9

Browse files
authored
feat: add alias, add indent (#143)
* fix: fix indent and page alias * build: fix build * chore: build * chore: build --------- Co-authored-by: janniks <[email protected]>
1 parent 3e829ad commit 749d0e9

File tree

9 files changed

+63
-14
lines changed

9 files changed

+63
-14
lines changed

dev/serve.vue

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export default {
2525
// sync tester: c10e1556bec44f23a20f71497b3d98c4
2626
// table tester: bd1de400a8b349dc824f4f00e61d0797
2727
// todo tester: 235057194b954a60ace89c052a65d102
28+
// indent tester: 5b494cf668b04197882fe1b66c6ee2a8
2829
this.blockMap = await getPageBlocks("2e22de6b770e4166be301490f6ffd420");
2930
},
3031
};

example/pages/posts.vue

+5-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
<script>
3838
export default {
3939
async asyncData({ $notion, params, error }) {
40-
const pageTable = await $notion.getPageTable("10327f9074b7433aad577ccd0020e971");
40+
const pageTable = await $notion.getPageTable(
41+
"10327f9074b7433aad577ccd0020e971"
42+
);
4143
4244
// sort published pages
4345
const posts = pageTable
@@ -48,6 +50,8 @@ export default {
4850
const postsByTag = pageTable
4951
.filter((page) => page.published)
5052
.reduce((map, currentPage) => {
53+
if (!currentPage.tags) return map;
54+
5155
currentPage.tags.forEach((tag) =>
5256
map.has(tag)
5357
? map.set(tag, [...map.get(tag), currentPage])

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"clean": "rm -rf node_modules dist example/node_modules example/dist example/.nuxt",
2222
"example": "npm run example:generate && cd example && npm start",
2323
"example:generate": "npm run example:install && cd example && npm run build && npm run generate",
24-
"example:install": "npm pack && cd example && npm install && npm install ../*.tgz",
24+
"example:install": "npm pack && cd example && npm ci && npm install ../*.tgz",
2525
"prepare": "rm -rf dist *.tgz && npm run build",
2626
"postpublish": "echo \"\\033[31m !!! Now, manually run: ./scripts/postpublish.sh !!! \\033[00m\"",
2727
"release:minor": "npm version minor -m 'Release %s' && npm publish",

src/blocks/page-alias.vue

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<template>
2+
<NotionRenderer v-bind="pass" :contentId="aliasPointerId" />
3+
</template>
4+
5+
<script>
6+
import { Blockable, blockComputed } from "@/lib/blockable";
7+
8+
export default {
9+
extends: Blockable,
10+
name: "NotionPageAlias",
11+
computed: {
12+
...blockComputed,
13+
aliasPointerId() {
14+
return this.format?.alias_pointer?.id;
15+
},
16+
},
17+
};
18+
</script>

src/blocks/sync-pointer.vue

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
<template>
2-
<NotionRenderer
3-
v-bind="pass"
4-
:blockMap="blockMap"
5-
:contentId="referencePointerId"
6-
/>
2+
<NotionRenderer v-bind="pass" :contentId="referencePointerId" />
73
</template>
84

95
<script>

src/blocks/text.vue

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
<template>
2-
<p v-if="properties" :class="['notion-text', blockColorClass()]">
3-
<NotionTextRenderer :text="title" v-bind="pass" />
4-
</p>
5-
<div v-else class="notion-blank">&nbsp;</div>
2+
<div>
3+
<p v-if="properties" :class="['notion-text', blockColorClass()]">
4+
<NotionTextRenderer :text="title" v-bind="pass" />
5+
</p>
6+
<div v-else class="notion-blank">&nbsp;</div>
7+
<div v-if="hasContent" class="notion-indent">
8+
<slot />
9+
</div>
10+
</div>
611
</template>
712

813
<script>
9-
import { Blockable } from "@/lib/blockable";
14+
import { Blockable, blockComputed } from "@/lib/blockable";
1015
import NotionTextRenderer from "@/blocks/helpers/text-renderer";
1116
1217
export default {
1318
extends: Blockable,
1419
name: "NotionText",
1520
components: { NotionTextRenderer },
21+
computed: {
22+
...blockComputed,
23+
hasContent() {
24+
return this.value?.content?.length > 0;
25+
},
26+
},
1627
};
1728
</script>

src/components/block.vue

+12-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@
33
v-if="blockOverrides.hasOwnProperty(type)"
44
:is="blockOverrides[type]"
55
v-bind="pass"
6-
/>
6+
>
7+
<slot />
8+
</component>
79
<div v-else-if="isType('page')">
810
<NotionPage v-bind="pass">
911
<slot />
1012
</NotionPage>
1113
</div>
14+
<NotionPageAlias
15+
v-else-if="isRendererRegistered && isType('alias')"
16+
v-bind="pass"
17+
/>
1218
<NotionHeader
1319
v-else-if="isType(['header', 'sub_header', 'sub_sub_header'])"
1420
v-bind="pass"
@@ -17,7 +23,9 @@
1723
<NotionCallout v-else-if="isType('callout')" v-bind="pass" />
1824
<NotionCode v-else-if="isType('code')" v-bind="pass" />
1925
<NotionEquation v-else-if="isType('equation')" v-bind="pass" />
20-
<NotionText v-else-if="isType('text')" v-bind="pass" />
26+
<NotionText v-else-if="isType('text')" v-bind="pass">
27+
<slot />
28+
</NotionText>
2129
<NotionQuote v-else-if="isType('quote')" v-bind="pass" />
2230
<NotionTodo v-else-if="isType('to_do')" v-bind="pass" />
2331
<NotionToggle v-else-if="isType('toggle')" v-bind="pass">
@@ -74,6 +82,7 @@ import NotionFigure from "@/blocks/helpers/figure";
7482
import NotionHeader from "@/blocks/header";
7583
import NotionList from "@/blocks/list";
7684
import NotionPage from "@/blocks/page";
85+
import NotionPageAlias from "@/blocks/page-alias";
7786
import NotionQuote from "@/blocks/quote";
7887
import NotionSyncPointer from "@/blocks/sync-pointer";
7988
import NotionTable from "@/blocks/table";
@@ -96,6 +105,7 @@ export default {
96105
NotionHeader,
97106
NotionList,
98107
NotionPage,
108+
NotionPageAlias,
99109
NotionQuote,
100110
NotionSyncPointer,
101111
NotionTable,

src/lib/utils.js

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export const getListNumber = (blockId, blockMap) => {
4040
};
4141

4242
export const defaultMapImageUrl = (image = "", block) => {
43+
if (image.startsWith("data:")) return image;
44+
4345
const url = new URL(
4446
`https://www.notion.so${
4547
image.startsWith("/image") ? image : `/image/${encodeURIComponent(image)}`

src/styles.css

+7
Original file line numberDiff line numberDiff line change
@@ -719,3 +719,10 @@ img.notion-nav-icon {
719719
background: rgb(247, 246, 243);
720720
font-weight: 500;
721721
}
722+
723+
/* more experimental additional rules */
724+
.notion-indent {
725+
display: flex;
726+
flex-direction: column;
727+
padding-left: 1.5em;
728+
}

0 commit comments

Comments
 (0)