notion-utility-personal 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/.tsbuildinfo +1 -0
- package/build/estimate-page-read-time.d.ts +35 -0
- package/build/estimate-page-read-time.d.ts.map +1 -0
- package/build/estimate-page-read-time.js +183 -0
- package/build/estimate-page-read-time.js.map +1 -0
- package/build/format-date.d.ts +4 -0
- package/build/format-date.d.ts.map +1 -0
- package/build/format-date.js +6 -0
- package/build/format-date.js.map +1 -0
- package/build/format-notion-date-time.d.ts +8 -0
- package/build/format-notion-date-time.d.ts.map +1 -0
- package/build/format-notion-date-time.js +7 -0
- package/build/format-notion-date-time.js.map +1 -0
- package/build/get-all-pages-in-space.d.ts +22 -0
- package/build/get-all-pages-in-space.d.ts.map +1 -0
- package/build/get-all-pages-in-space.js +110 -0
- package/build/get-all-pages-in-space.js.map +1 -0
- package/build/get-block-collection-id.d.ts +3 -0
- package/build/get-block-collection-id.d.ts.map +1 -0
- package/build/get-block-collection-id.js +18 -0
- package/build/get-block-collection-id.js.map +1 -0
- package/build/get-block-icon.d.ts +3 -0
- package/build/get-block-icon.d.ts.map +1 -0
- package/build/get-block-icon.js +19 -0
- package/build/get-block-icon.js.map +1 -0
- package/build/get-block-parent-page.d.ts +11 -0
- package/build/get-block-parent-page.d.ts.map +1 -0
- package/build/get-block-parent-page.js +31 -0
- package/build/get-block-parent-page.js.map +1 -0
- package/build/get-block-title.d.ts +3 -0
- package/build/get-block-title.d.ts.map +1 -0
- package/build/get-block-title.js +20 -0
- package/build/get-block-title.js.map +1 -0
- package/build/get-canonical-page-id.d.ts +8 -0
- package/build/get-canonical-page-id.d.ts.map +1 -0
- package/build/get-canonical-page-id.js +29 -0
- package/build/get-canonical-page-id.js.map +1 -0
- package/build/get-date-value.d.ts +6 -0
- package/build/get-date-value.d.ts.map +1 -0
- package/build/get-date-value.js +20 -0
- package/build/get-date-value.js.map +1 -0
- package/build/get-page-breadcrumbs.d.ts +3 -0
- package/build/get-page-breadcrumbs.d.ts.map +1 -0
- package/build/get-page-breadcrumbs.js +37 -0
- package/build/get-page-breadcrumbs.js.map +1 -0
- package/build/get-page-content-block-ids.d.ts +6 -0
- package/build/get-page-content-block-ids.d.ts.map +1 -0
- package/build/get-page-content-block-ids.js +58 -0
- package/build/get-page-content-block-ids.js.map +1 -0
- package/build/get-page-image-urls.d.ts +8 -0
- package/build/get-page-image-urls.d.ts.map +1 -0
- package/build/get-page-image-urls.js +63 -0
- package/build/get-page-image-urls.js.map +1 -0
- package/build/get-page-property.d.ts +16 -0
- package/build/get-page-property.d.ts.map +1 -0
- package/build/get-page-property.js +61 -0
- package/build/get-page-property.js.map +1 -0
- package/build/get-page-table-of-contents.d.ts +13 -0
- package/build/get-page-table-of-contents.d.ts.map +1 -0
- package/build/get-page-table-of-contents.js +67 -0
- package/build/get-page-table-of-contents.js.map +1 -0
- package/build/get-page-title.d.ts +3 -0
- package/build/get-page-title.d.ts.map +1 -0
- package/build/get-page-title.js +10 -0
- package/build/get-page-title.js.map +1 -0
- package/build/get-text-content.d.ts +9 -0
- package/build/get-text-content.d.ts.map +1 -0
- package/build/get-text-content.js +19 -0
- package/build/get-text-content.js.map +1 -0
- package/build/id-to-uuid.d.ts +2 -0
- package/build/id-to-uuid.d.ts.map +1 -0
- package/build/id-to-uuid.js +2 -0
- package/build/id-to-uuid.js.map +1 -0
- package/build/index.d.ts +25 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +25 -0
- package/build/index.js.map +1 -0
- package/build/is-url.d.ts +3 -0
- package/build/is-url.d.ts.map +1 -0
- package/build/is-url.js +3 -0
- package/build/is-url.js.map +1 -0
- package/build/merge-record-maps.d.ts +3 -0
- package/build/merge-record-maps.d.ts.map +1 -0
- package/build/merge-record-maps.js +13 -0
- package/build/merge-record-maps.js.map +1 -0
- package/build/normalize-title.d.ts +2 -0
- package/build/normalize-title.d.ts.map +1 -0
- package/build/normalize-title.js +11 -0
- package/build/normalize-title.js.map +1 -0
- package/build/normalize-url.d.ts +2 -0
- package/build/normalize-url.d.ts.map +1 -0
- package/build/normalize-url.js +27 -0
- package/build/normalize-url.js.map +1 -0
- package/build/normalize-url.test.d.ts +2 -0
- package/build/normalize-url.test.d.ts.map +1 -0
- package/build/normalize-url.test.js +30 -0
- package/build/normalize-url.test.js.map +1 -0
- package/build/parse-page-id.d.ts +9 -0
- package/build/parse-page-id.d.ts.map +1 -0
- package/build/parse-page-id.js +24 -0
- package/build/parse-page-id.js.map +1 -0
- package/build/parse-page-id.test.d.ts +2 -0
- package/build/parse-page-id.test.d.ts.map +1 -0
- package/build/parse-page-id.test.js +54 -0
- package/build/parse-page-id.test.js.map +1 -0
- package/build/uuid-to-id.d.ts +2 -0
- package/build/uuid-to-id.d.ts.map +1 -0
- package/build/uuid-to-id.js +2 -0
- package/build/uuid-to-id.js.map +1 -0
- package/package.json +51 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-block-title.js","sourceRoot":"","sources":["../src/get-block-title.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,MAAM,UAAU,aAAa,CAAC,KAAY,EAAE,SAA4B;;IACtE,IAAI,MAAA,KAAK,CAAC,UAAU,0CAAE,KAAK,EAAE;QAC3B,OAAO,cAAc,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;KAC/C;IAED,IACE,KAAK,CAAC,IAAI,KAAK,sBAAsB;QACrC,KAAK,CAAC,IAAI,KAAK,iBAAiB,EAChC;QACA,MAAM,YAAY,GAAG,oBAAoB,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;QAE5D,IAAI,YAAY,EAAE;YAChB,MAAM,UAAU,GAAG,MAAA,SAAS,CAAC,UAAU,CAAC,YAAY,CAAC,0CAAE,KAAK,CAAC;YAE7D,IAAI,UAAU,EAAE;gBACd,OAAO,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;aACxC;SACF;KACF;IAED,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ExtendedRecordMap } from "notion-types-personal";
|
|
2
|
+
/**
|
|
3
|
+
* Gets the canonical, display-friendly version of a page's ID for use in URLs.
|
|
4
|
+
*/
|
|
5
|
+
export declare const getCanonicalPageId: (pageId: string, recordMap: ExtendedRecordMap, { uuid }?: {
|
|
6
|
+
uuid?: boolean;
|
|
7
|
+
}) => string | null;
|
|
8
|
+
//# sourceMappingURL=get-canonical-page-id.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-canonical-page-id.d.ts","sourceRoot":"","sources":["../src/get-canonical-page-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAO1D;;GAEG;AACH,eAAO,MAAM,kBAAkB,WACrB,MAAM,aACH,iBAAiB;WACF,OAAO;MAChC,MAAM,GAAG,IAsBX,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { getBlockTitle } from "./get-block-title";
|
|
2
|
+
import { getPageProperty } from "./get-page-property";
|
|
3
|
+
import { normalizeTitle } from "./normalize-title";
|
|
4
|
+
import { uuidToId } from "./uuid-to-id";
|
|
5
|
+
/**
|
|
6
|
+
* Gets the canonical, display-friendly version of a page's ID for use in URLs.
|
|
7
|
+
*/
|
|
8
|
+
export const getCanonicalPageId = (pageId, recordMap, { uuid = true } = {}) => {
|
|
9
|
+
var _a;
|
|
10
|
+
if (!pageId || !recordMap)
|
|
11
|
+
return null;
|
|
12
|
+
const id = uuidToId(pageId);
|
|
13
|
+
const block = (_a = recordMap.block[pageId]) === null || _a === void 0 ? void 0 : _a.value;
|
|
14
|
+
if (block) {
|
|
15
|
+
const slug = getPageProperty("slug", block, recordMap) ||
|
|
16
|
+
getPageProperty("Slug", block, recordMap) ||
|
|
17
|
+
normalizeTitle(getBlockTitle(block, recordMap));
|
|
18
|
+
if (slug) {
|
|
19
|
+
if (uuid) {
|
|
20
|
+
return `${slug}-${id}`;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
return slug;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return id;
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=get-canonical-page-id.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-canonical-page-id.js","sourceRoot":"","sources":["../src/get-canonical-page-id.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,MAAc,EACd,SAA4B,EAC5B,EAAE,IAAI,GAAG,IAAI,KAAyB,EAAE,EACzB,EAAE;;IACjB,IAAI,CAAC,MAAM,IAAI,CAAC,SAAS;QAAE,OAAO,IAAI,CAAC;IAEvC,MAAM,EAAE,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC5B,MAAM,KAAK,GAAG,MAAA,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,0CAAE,KAAK,CAAC;IAE7C,IAAI,KAAK,EAAE;QACT,MAAM,IAAI,GACP,eAAe,CAAC,MAAM,EAAE,KAAK,EAAE,SAAS,CAAmB;YAC3D,eAAe,CAAC,MAAM,EAAE,KAAK,EAAE,SAAS,CAAmB;YAC5D,cAAc,CAAC,aAAa,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC;QAElD,IAAI,IAAI,EAAE;YACR,IAAI,IAAI,EAAE;gBACR,OAAO,GAAG,IAAI,IAAI,EAAE,EAAE,CAAC;aACxB;iBAAM;gBACL,OAAO,IAAI,CAAC;aACb;SACF;KACF;IAED,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-date-value.d.ts","sourceRoot":"","sources":["../src/get-date-value.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,uBAAuB,CAAC;AAE/C;;GAEG;AACH,eAAO,MAAM,YAAY,SAAU,GAAG,EAAE,KAAG,MAAM,aAAa,GAAG,IAehE,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attempts to find a valid date from a given property.
|
|
3
|
+
*/
|
|
4
|
+
export const getDateValue = (prop) => {
|
|
5
|
+
if (prop && Array.isArray(prop)) {
|
|
6
|
+
if (prop[0] === "d") {
|
|
7
|
+
return prop[1];
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
for (const v of prop) {
|
|
11
|
+
const value = getDateValue(v);
|
|
12
|
+
if (value) {
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=get-date-value.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-date-value.js","sourceRoot":"","sources":["../src/get-date-value.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAW,EAA8B,EAAE;IACtE,IAAI,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QAC/B,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;YACnB,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC;SAChB;aAAM;YACL,KAAK,MAAM,CAAC,IAAI,IAAI,EAAE;gBACpB,MAAM,KAAK,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;gBAC9B,IAAI,KAAK,EAAE;oBACT,OAAO,KAAK,CAAC;iBACd;aACF;SACF;KACF;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-page-breadcrumbs.d.ts","sourceRoot":"","sources":["../src/get-page-breadcrumbs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,uBAAuB,CAAC;AAM/C,eAAO,MAAM,kBAAkB,cAClB,MAAM,iBAAiB,gBACpB,MAAM,KACnB,MAAM,GAAG,CAAC,GAAG,IA0Cf,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { getBlockIcon } from "./get-block-icon";
|
|
2
|
+
import { getBlockParentPage } from "./get-block-parent-page";
|
|
3
|
+
import { getBlockTitle } from "./get-block-title";
|
|
4
|
+
export const getPageBreadcrumbs = (recordMap, activePageId) => {
|
|
5
|
+
var _a;
|
|
6
|
+
const blockMap = recordMap.block;
|
|
7
|
+
const breadcrumbs = [];
|
|
8
|
+
let currentPageId = activePageId;
|
|
9
|
+
do {
|
|
10
|
+
const block = (_a = blockMap[currentPageId]) === null || _a === void 0 ? void 0 : _a.value;
|
|
11
|
+
if (!block) {
|
|
12
|
+
break;
|
|
13
|
+
}
|
|
14
|
+
const title = getBlockTitle(block, recordMap);
|
|
15
|
+
const icon = getBlockIcon(block, recordMap);
|
|
16
|
+
if (!(title || icon)) {
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
breadcrumbs.push({
|
|
20
|
+
block,
|
|
21
|
+
active: currentPageId === activePageId,
|
|
22
|
+
pageId: currentPageId,
|
|
23
|
+
title,
|
|
24
|
+
icon,
|
|
25
|
+
});
|
|
26
|
+
const parentBlock = getBlockParentPage(block, recordMap);
|
|
27
|
+
const parentId = parentBlock === null || parentBlock === void 0 ? void 0 : parentBlock.id;
|
|
28
|
+
if (!parentId) {
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
currentPageId = parentId;
|
|
32
|
+
// eslint-disable-next-line no-constant-condition
|
|
33
|
+
} while (true);
|
|
34
|
+
breadcrumbs.reverse();
|
|
35
|
+
return breadcrumbs;
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=get-page-breadcrumbs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-page-breadcrumbs.js","sourceRoot":"","sources":["../src/get-page-breadcrumbs.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,SAAkC,EAClC,YAAoB,EACD,EAAE;;IACrB,MAAM,QAAQ,GAAG,SAAS,CAAC,KAAK,CAAC;IACjC,MAAM,WAAW,GAAG,EAAE,CAAC;IAEvB,IAAI,aAAa,GAAG,YAAY,CAAC;IAEjC,GAAG;QACD,MAAM,KAAK,GAAG,MAAA,QAAQ,CAAC,aAAa,CAAC,0CAAE,KAAK,CAAC;QAC7C,IAAI,CAAC,KAAK,EAAE;YACV,MAAM;SACP;QAED,MAAM,KAAK,GAAG,aAAa,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;QAC9C,MAAM,IAAI,GAAG,YAAY,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;QAE5C,IAAI,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,EAAE;YACpB,MAAM;SACP;QAED,WAAW,CAAC,IAAI,CAAC;YACf,KAAK;YACL,MAAM,EAAE,aAAa,KAAK,YAAY;YACtC,MAAM,EAAE,aAAa;YACrB,KAAK;YACL,IAAI;SACL,CAAC,CAAC;QAEH,MAAM,WAAW,GAAG,kBAAkB,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;QACzD,MAAM,QAAQ,GAAG,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,EAAE,CAAC;QAEjC,IAAI,CAAC,QAAQ,EAAE;YACb,MAAM;SACP;QAED,aAAa,GAAG,QAAQ,CAAC;QAEzB,iDAAiD;KAClD,QAAQ,IAAI,EAAE;IAEf,WAAW,CAAC,OAAO,EAAE,CAAC;IAEtB,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as types from "notion-types-personal";
|
|
2
|
+
/**
|
|
3
|
+
* Gets the IDs of all blocks contained on a page starting from a root block ID.
|
|
4
|
+
*/
|
|
5
|
+
export declare const getPageContentBlockIds: (recordMap: types.ExtendedRecordMap, blockId?: string) => string[];
|
|
6
|
+
//# sourceMappingURL=get-page-content-block-ids.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-page-content-block-ids.d.ts","sourceRoot":"","sources":["../src/get-page-content-block-ids.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,uBAAuB,CAAC;AAE/C;;GAEG;AACH,eAAO,MAAM,sBAAsB,cACtB,MAAM,iBAAiB,YACxB,MAAM,KACf,MAAM,EA2DR,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gets the IDs of all blocks contained on a page starting from a root block ID.
|
|
3
|
+
*/
|
|
4
|
+
export const getPageContentBlockIds = (recordMap, blockId) => {
|
|
5
|
+
const rootBlockId = blockId || Object.keys(recordMap.block)[0];
|
|
6
|
+
const contentBlockIds = new Set();
|
|
7
|
+
function addContentBlocks(blockId) {
|
|
8
|
+
var _a, _b, _c, _d;
|
|
9
|
+
if (contentBlockIds.has(blockId))
|
|
10
|
+
return;
|
|
11
|
+
contentBlockIds.add(blockId);
|
|
12
|
+
const block = (_a = recordMap.block[blockId]) === null || _a === void 0 ? void 0 : _a.value;
|
|
13
|
+
if (!block)
|
|
14
|
+
return;
|
|
15
|
+
const { content, type, properties, format } = block;
|
|
16
|
+
if (properties) {
|
|
17
|
+
// TODO: this needs some love, especially for resolving relation properties
|
|
18
|
+
// see this collection_view_page for an example: 8a586d253f984b85b48254da84465d23
|
|
19
|
+
for (const key of Object.keys(properties)) {
|
|
20
|
+
const p = properties[key];
|
|
21
|
+
p.map((d) => {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
const value = (_b = (_a = d === null || d === void 0 ? void 0 : d[0]) === null || _a === void 0 ? void 0 : _a[1]) === null || _b === void 0 ? void 0 : _b[0];
|
|
24
|
+
if ((value === null || value === void 0 ? void 0 : value[0]) === "p" && value[1]) {
|
|
25
|
+
addContentBlocks(value[1]);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
// [["‣", [["p", "841918aa-f2a3-4d4c-b5ad-64b0f57c47b8"]]]]
|
|
29
|
+
const value = (_c = (_b = p === null || p === void 0 ? void 0 : p[0]) === null || _b === void 0 ? void 0 : _b[1]) === null || _c === void 0 ? void 0 : _c[0];
|
|
30
|
+
if ((value === null || value === void 0 ? void 0 : value[0]) === "p" && value[1]) {
|
|
31
|
+
addContentBlocks(value[1]);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (format) {
|
|
36
|
+
const referenceId = (_d = format.transclusion_reference_pointer) === null || _d === void 0 ? void 0 : _d.id;
|
|
37
|
+
if (referenceId) {
|
|
38
|
+
addContentBlocks(referenceId);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (!content || !Array.isArray(content)) {
|
|
42
|
+
// no child content blocks to recurse on
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (blockId !== rootBlockId) {
|
|
46
|
+
if (type === "page" || type === "collection_view_page") {
|
|
47
|
+
// ignore the content of other pages and collections
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
for (const blockId of content) {
|
|
52
|
+
addContentBlocks(blockId);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
addContentBlocks(rootBlockId);
|
|
56
|
+
return Array.from(contentBlockIds);
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=get-page-content-block-ids.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-page-content-block-ids.js","sourceRoot":"","sources":["../src/get-page-content-block-ids.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,SAAkC,EAClC,OAAgB,EACN,EAAE;IACZ,MAAM,WAAW,GAAG,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/D,MAAM,eAAe,GAAG,IAAI,GAAG,EAAU,CAAC;IAE1C,SAAS,gBAAgB,CAAC,OAAe;;QACvC,IAAI,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC;YAAE,OAAO;QACzC,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAE7B,MAAM,KAAK,GAAG,MAAA,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,0CAAE,KAAK,CAAC;QAC9C,IAAI,CAAC,KAAK;YAAE,OAAO;QAEnB,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;QACpD,IAAI,UAAU,EAAE;YACd,2EAA2E;YAC3E,iFAAiF;YACjF,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;gBACzC,MAAM,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;gBAC1B,CAAC,CAAC,GAAG,CAAC,CAAC,CAAM,EAAE,EAAE;;oBACf,MAAM,KAAK,GAAG,MAAA,MAAA,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAG,CAAC,CAAC,0CAAG,CAAC,CAAC,0CAAG,CAAC,CAAC,CAAC;oBAC/B,IA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/**
|
|
3
|
+
* Gets URLs of all images contained on the given page.
|
|
4
|
+
*/
|
|
5
|
+
export declare const getPageImageUrls: (recordMap: types.ExtendedRecordMap, { mapImageUrl, }: {
|
|
6
|
+
mapImageUrl: (url: string, block: types.Block) => string | null;
|
|
7
|
+
}) => string[];
|
|
8
|
+
//# sourceMappingURL=get-page-image-urls.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-page-image-urls.d.ts","sourceRoot":"","sources":["../src/get-page-image-urls.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,uBAAuB,CAAC;AAK/C;;GAEG;AACH,eAAO,MAAM,gBAAgB,cAChB,MAAM,iBAAiB;uBAIb,MAAM,SAAS,MAAM,KAAK,KAAK,MAAM,GAAG,IAAI;MAEhE,MAAM,EAkER,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { getBlockIcon } from "./get-block-icon";
|
|
2
|
+
import { isUrl } from "./is-url";
|
|
3
|
+
/**
|
|
4
|
+
* Gets URLs of all images contained on the given page.
|
|
5
|
+
*/
|
|
6
|
+
export const getPageImageUrls = (recordMap, { mapImageUrl, }) => {
|
|
7
|
+
const blockIds = Object.keys(recordMap.block);
|
|
8
|
+
const imageUrls = blockIds
|
|
9
|
+
.flatMap((blockId) => {
|
|
10
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
11
|
+
const block = (_a = recordMap.block[blockId]) === null || _a === void 0 ? void 0 : _a.value;
|
|
12
|
+
const images = [];
|
|
13
|
+
if (block) {
|
|
14
|
+
if (block.type === "image") {
|
|
15
|
+
const signedUrl = (_b = recordMap.signed_urls) === null || _b === void 0 ? void 0 : _b[block.id];
|
|
16
|
+
let source = signedUrl || ((_e = (_d = (_c = block.properties) === null || _c === void 0 ? void 0 : _c.source) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e[0]);
|
|
17
|
+
if (source.includes("file.notion.so")) {
|
|
18
|
+
source = (_h = (_g = (_f = block.properties) === null || _f === void 0 ? void 0 : _f.source) === null || _g === void 0 ? void 0 : _g[0]) === null || _h === void 0 ? void 0 : _h[0];
|
|
19
|
+
}
|
|
20
|
+
if (source) {
|
|
21
|
+
images.push({
|
|
22
|
+
block,
|
|
23
|
+
url: source,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if ((_j = block.format) === null || _j === void 0 ? void 0 : _j.page_cover) {
|
|
28
|
+
const source = block.format.page_cover;
|
|
29
|
+
images.push({
|
|
30
|
+
block,
|
|
31
|
+
url: source,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
if ((_k = block.format) === null || _k === void 0 ? void 0 : _k.bookmark_cover) {
|
|
35
|
+
const source = block.format.bookmark_cover;
|
|
36
|
+
images.push({
|
|
37
|
+
block,
|
|
38
|
+
url: source,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
if ((_l = block.format) === null || _l === void 0 ? void 0 : _l.bookmark_icon) {
|
|
42
|
+
const source = block.format.bookmark_icon;
|
|
43
|
+
images.push({
|
|
44
|
+
block,
|
|
45
|
+
url: source,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
const pageIcon = getBlockIcon(block, recordMap);
|
|
49
|
+
if (pageIcon && isUrl(pageIcon)) {
|
|
50
|
+
images.push({
|
|
51
|
+
block,
|
|
52
|
+
url: pageIcon,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return images;
|
|
57
|
+
})
|
|
58
|
+
.filter(Boolean)
|
|
59
|
+
.map(({ block, url }) => mapImageUrl(url, block))
|
|
60
|
+
.filter(Boolean);
|
|
61
|
+
return Array.from(new Set(imageUrls));
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=get-page-image-urls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-page-image-urls.js","sourceRoot":"","sources":["../src/get-page-image-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AAC,IAAI,CAAC;oBACV,KAAK;oBACL,GAAG,EAAE,MAAM;iBACZ,CAAC,CAAC;aACJ;YAED,IAAI,MAAC,KAAK,CAAC,MAAc,0CAAE,cAAc,EAAE;gBACzC,MAAM,MAAM,GAAI,KAAK,CAAC,MAAc,CAAC,cAAc,CAAC;gBAEpD,MAAM,CAAC,IAAI,CAAC;oBACV,KAAK;oBACL,GAAG,EAAE,MAAM;iBACZ,CAAC,CAAC;aACJ;YAED,IAAI,MAAC,KAAK,CAAC,MAAc,0CAAE,aAAa,EAAE;gBACxC,MAAM,MAAM,GAAI,KAAK,CAAC,MAAc,CAAC,aAAa,CAAC;gBAEnD,MAAM,CAAC,IAAI,CAAC;oBACV,KAAK;oBACL,GAAG,EAAE,MAAM;iBACZ,CAAC,CAAC;aACJ;YAED,MAAM,QAAQ,GAAG,YAAY,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;YAChD,IAAI,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,EAAE;gBAC/B,MAAM,CAAC,IAAI,CAAC;oBACV,KAAK;oBACL,GAAG,EAAE,QAAQ;iBACd,CAAC,CAAC;aACJ;SACF;QAED,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;SACD,MAAM,CAAC,OAAO,CAAC;SACf,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;SAChD,MAAM,CAAC,OAAO,CAAC,CAAC;IAEnB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;AACxC,CAAC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Block, ExtendedRecordMap } from "notion-types-personal";
|
|
2
|
+
/**
|
|
3
|
+
* Gets the value of a collection property for a given page (collection item).
|
|
4
|
+
*
|
|
5
|
+
* @param propertyName property name
|
|
6
|
+
* @param block Page block, often be first block in blockMap
|
|
7
|
+
* @param recordMap
|
|
8
|
+
* @returns - The return value types will follow the following principles:
|
|
9
|
+
* 1. if property is date type, it will return `number` or `number[]`(depends on `End Date` switch)
|
|
10
|
+
* 2. property is text-like will return `string`
|
|
11
|
+
* 3. multi select property will return `string[]`
|
|
12
|
+
* 4. checkbox property return `boolean`
|
|
13
|
+
* @todo complete all no-text property type
|
|
14
|
+
*/
|
|
15
|
+
export declare function getPageProperty<T = string | number | boolean | string[] | number[]>(propertyName: string, block: Block, recordMap: ExtendedRecordMap): T;
|
|
16
|
+
//# sourceMappingURL=get-page-property.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-page-property.d.ts","sourceRoot":"","sources":["../src/get-page-property.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAc,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAI7E;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAC7B,CAAC,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,EACnD,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,iBAAiB,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { getTextContent } from "./get-text-content";
|
|
2
|
+
export function getPageProperty(propertyName, block, recordMap) {
|
|
3
|
+
var _a;
|
|
4
|
+
try {
|
|
5
|
+
if (!block.properties || !Object.keys(recordMap.collection)) {
|
|
6
|
+
// console.warn(
|
|
7
|
+
// `block ${block.id} has no properties or this recordMap has no collection record`
|
|
8
|
+
// )
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
const collection = (_a = recordMap.collection[block.parent_id]) === null || _a === void 0 ? void 0 : _a.value;
|
|
12
|
+
if (collection) {
|
|
13
|
+
const propertyNameL = propertyName.toLowerCase();
|
|
14
|
+
const propertyId = Object.keys(collection.schema).find((key) => { var _a, _b; return ((_b = (_a = collection.schema[key]) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === propertyNameL; });
|
|
15
|
+
if (!propertyId) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const { type } = collection.schema[propertyId];
|
|
19
|
+
const content = getTextContent(block.properties[propertyId]);
|
|
20
|
+
switch (type) {
|
|
21
|
+
case "created_time":
|
|
22
|
+
return block.created_time;
|
|
23
|
+
case "multi_select":
|
|
24
|
+
return content.split(",");
|
|
25
|
+
case "date": {
|
|
26
|
+
const property = block.properties[propertyId];
|
|
27
|
+
const formatDate = property[0][1][0][1];
|
|
28
|
+
if (formatDate.type == "datetime") {
|
|
29
|
+
return new Date(`${formatDate.start_date} ${formatDate.start_time}`).getTime();
|
|
30
|
+
}
|
|
31
|
+
else if (formatDate.type == "date") {
|
|
32
|
+
return new Date(formatDate.start_date).getTime();
|
|
33
|
+
}
|
|
34
|
+
else if (formatDate.type == "datetimerange") {
|
|
35
|
+
const { start_date, start_time, end_date, end_time } = formatDate;
|
|
36
|
+
const startTime = new Date(`${start_date} ${start_time}`).getTime();
|
|
37
|
+
const endTime = new Date(`${end_date} ${end_time}`).getTime();
|
|
38
|
+
return [startTime, endTime];
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
const startTime = new Date(formatDate.start_date).getTime();
|
|
42
|
+
const endTime = new Date(formatDate.end_date).getTime();
|
|
43
|
+
return [startTime, endTime];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
case "checkbox":
|
|
47
|
+
return content == "Yes";
|
|
48
|
+
case "last_edited_time":
|
|
49
|
+
return block.last_edited_time;
|
|
50
|
+
default:
|
|
51
|
+
return content;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (_b) {
|
|
56
|
+
// ensure that no matter what, we don't throw errors because of an unexpected
|
|
57
|
+
// collection data format
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=get-page-property.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-page-property.js","sourceRoot":"","sources":["../src/get-page-property.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAkBpD,MAAM,UAAU,eAAe,CAC7B,YAAoB,EACpB,KAAY,EACZ,SAA4B;;IAE5B,IAAI;QACF,IAAI,CAAC,KAAK,CAAC,UAAU,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE;YAC3D,gBAAgB;YAChB,qFAAqF;YACrF,IAAI;YACJ,OAAO,IAAI,CAAC;SACb;QAED,MAAM,UAAU,GAAG,MAAA,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,0CAAE,KAAK,CAAC;QAEhE,IAAI,UAAU,EAAE;YACd,MAAM,aAAa,GAAG,YAAY,CAAC,WAAW,EAAE,CAAC;YACjD,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,CACpD,CAAC,GAAG,EAAE,EAAE,eAAC,OAAA,CAAA,MAAA,MAAA,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,0CAAE,IAAI,0CAAE,WAAW,EAAE,MAAK,aAAa,CAAA,EAAA,CACvE,CAAC;YAEF,IAAI,CAAC,UAAU,EAAE;gBACf,OAAO,IAAI,CAAC;aACb;YAED,MAAM,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;YAC/C,MAAM,OAAO,GAAG,cAAc,CAAC,KAAK,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC;YAE7D,QAAQ,IAAI,EAAE;gBACZ,KAAK,cAAc;oBACjB,OAAO,KAAK,CAAC,YAAY,CAAC;gBAE5B,KAAK,cAAc;oBACjB,OAAO,OAAO,CAAC,KAAK,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OAAO,IAAI,KAAK,CAAC;gBAE1B,KAAK,kBAAkB;oBACrB,OAAO,KAAK,CAAC,gBAAgB,CAAC;gBAEhC;oBACE,OAAO,OAAO,CAAC;aAClB;SACF;KACF;IAAC,WAAM;QACN,6EAA6E;QAC7E,yBAAyB;KAC1B;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as types from "notion-types-personal";
|
|
2
|
+
export interface TableOfContentsEntry {
|
|
3
|
+
id: types.ID;
|
|
4
|
+
type: types.BlockType;
|
|
5
|
+
text: string;
|
|
6
|
+
indentLevel: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Gets the metadata for a table of contents block by parsing the page's
|
|
10
|
+
* H1, H2, and H3 elements.
|
|
11
|
+
*/
|
|
12
|
+
export declare const getPageTableOfContents: (page: types.PageBlock, recordMap: types.ExtendedRecordMap) => Array<TableOfContentsEntry>;
|
|
13
|
+
//# sourceMappingURL=get-page-table-of-contents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-page-table-of-contents.d.ts","sourceRoot":"","sources":["../src/get-page-table-of-contents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,uBAAuB,CAAC;AAI/C,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,KAAK,CAAC,EAAE,CAAC;IACb,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB;AAQD;;;GAGG;AACH,eAAO,MAAM,sBAAsB,SAC3B,MAAM,SAAS,aACV,MAAM,iBAAiB,KACjC,MAAM,oBAAoB,CA8D5B,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { getTextContent } from "./get-text-content";
|
|
2
|
+
const indentLevels = {
|
|
3
|
+
header: 0,
|
|
4
|
+
sub_header: 1,
|
|
5
|
+
sub_sub_header: 2,
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Gets the metadata for a table of contents block by parsing the page's
|
|
9
|
+
* H1, H2, and H3 elements.
|
|
10
|
+
*/
|
|
11
|
+
export const getPageTableOfContents = (page, recordMap) => {
|
|
12
|
+
var _a;
|
|
13
|
+
const toc = ((_a = page.content) !== null && _a !== void 0 ? _a : [])
|
|
14
|
+
.map((blockId) => {
|
|
15
|
+
var _a, _b;
|
|
16
|
+
const block = (_a = recordMap.block[blockId]) === null || _a === void 0 ? void 0 : _a.value;
|
|
17
|
+
if (block) {
|
|
18
|
+
const { type } = block;
|
|
19
|
+
if (type === "header" ||
|
|
20
|
+
type === "sub_header" ||
|
|
21
|
+
type === "sub_sub_header") {
|
|
22
|
+
return {
|
|
23
|
+
id: blockId,
|
|
24
|
+
type,
|
|
25
|
+
text: getTextContent((_b = block.properties) === null || _b === void 0 ? void 0 : _b.title),
|
|
26
|
+
indentLevel: indentLevels[type],
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
})
|
|
32
|
+
.filter(Boolean);
|
|
33
|
+
const indentLevelStack = [
|
|
34
|
+
{
|
|
35
|
+
actual: -1,
|
|
36
|
+
effective: -1,
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
// Adjust indent levels to always change smoothly.
|
|
40
|
+
// This is a little tricky, but the key is that when increasing indent levels,
|
|
41
|
+
// they should never jump more than one at a time.
|
|
42
|
+
for (const tocItem of toc) {
|
|
43
|
+
const { indentLevel } = tocItem;
|
|
44
|
+
const actual = indentLevel;
|
|
45
|
+
do {
|
|
46
|
+
const prevIndent = indentLevelStack[indentLevelStack.length - 1];
|
|
47
|
+
const { actual: prevActual, effective: prevEffective } = prevIndent;
|
|
48
|
+
if (actual > prevActual) {
|
|
49
|
+
tocItem.indentLevel = prevEffective + 1;
|
|
50
|
+
indentLevelStack.push({
|
|
51
|
+
actual,
|
|
52
|
+
effective: tocItem.indentLevel,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
else if (actual === prevActual) {
|
|
56
|
+
tocItem.indentLevel = prevEffective;
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
indentLevelStack.pop();
|
|
61
|
+
}
|
|
62
|
+
// eslint-disable-next-line no-constant-condition
|
|
63
|
+
} while (true);
|
|
64
|
+
}
|
|
65
|
+
return toc;
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=get-page-table-of-contents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-page-table-of-contents.js","sourceRoot":"","sources":["../src/get-page-table-of-contents.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AASpD,MAAM,YAAY,GAAG;IACnB,MAAM,EAAE,CAAC;IACT,UAAU,EAAE,CAAC;IACb,cAAc,EAAE,CAAC;CAClB,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,IAAqB,EACrB,SAAkC,EACL,EAAE;;IAC/B,MAAM,GAAG,GAAG,CAAC,MAAA,IAAI,CAAC,OAAO,mCAAI,EAAE,CAAC;SAC7B,GAAG,CAAC,CAAC,OAAe,EAAE,EAAE;;QACvB,MAAM,KAAK,GAAG,MAAA,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,0CAAE,KAAK,CAAC;QAE9C,IAAI,KAAK,EAAE;YACT,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;YAEvB,IACE,IAAI,KAAK,QAAQ;gBACjB,IAAI,KAAK,YAAY;gBACrB,IAAI,KAAK,gBAAgB,EACzB;gBACA,OAAO;oBACL,EAAE,EAAE,OAAO;oBACX,IAAI;oBACJ,IAAI,EAAE,cAAc,CAAC,MAAA,KAAK,CAAC,UAAU,0CAAE,KAAK,CAAC;oBAC7C,WAAW,EAAE,YAAY,CAAC,IAAI,CAAC;iBAChC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
|
1
|
+
import { getBlockTitle } from "./get-block-title";
|
|
2
|
+
export function getPageTitle(recordMap) {
|
|
3
|
+
var _a;
|
|
4
|
+
const pageBlock = (_a = recordMap.block[Object.keys(recordMap.block)[0]]) === null || _a === void 0 ? void 0 : _a.value;
|
|
5
|
+
if (pageBlock) {
|
|
6
|
+
return getBlockTitle(pageBlock, recordMap);
|
|
7
|
+
}
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=get-page-title.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-page-title.js","sourceRoot":"","sources":["../src/get-page-title.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,MAAM,UAAU,YAAY,CAAC,SAA4B;;IACvD,MAAM,SAAS,GAAG,MAAA,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,0CAAE,KAAK,CAAC;IAE1E,IAAI,SAAS,EAAE;QACb,OAAO,aAAa,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;KAC5C;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as types from "notion-types-personal";
|
|
2
|
+
/**
|
|
3
|
+
* Gets the raw, unformatted text content of a block's content value.
|
|
4
|
+
*
|
|
5
|
+
* This is useful, for instance, for extracting a block's `title` without any
|
|
6
|
+
* rich text formatting.
|
|
7
|
+
*/
|
|
8
|
+
export declare const getTextContent: (text?: types.Decoration[]) => string;
|
|
9
|
+
//# sourceMappingURL=get-text-content.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-text-content.d.ts","sourceRoot":"","sources":["../src/get-text-content.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,uBAAuB,CAAC;AAE/C;;;;;GAKG;AACH,eAAO,MAAM,cAAc,UAAW,MAAM,UAAU,EAAE,KAAG,MAc1D,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gets the raw, unformatted text content of a block's content value.
|
|
3
|
+
*
|
|
4
|
+
* This is useful, for instance, for extracting a block's `title` without any
|
|
5
|
+
* rich text formatting.
|
|
6
|
+
*/
|
|
7
|
+
export const getTextContent = (text) => {
|
|
8
|
+
var _a;
|
|
9
|
+
if (!text) {
|
|
10
|
+
return "";
|
|
11
|
+
}
|
|
12
|
+
else if (Array.isArray(text)) {
|
|
13
|
+
return ((_a = text === null || text === void 0 ? void 0 : text.reduce((prev, current) => prev + (current[0] !== "⁍" && current[0] !== "‣" ? current[0] : ""), "")) !== null && _a !== void 0 ? _a : "");
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
return text;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=get-text-content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-text-content.js","sourceRoot":"","sources":["../src/get-text-content.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,IAAyB,EAAU,EAAE;;IAClE,IAAI,CAAC,IAAI,EAAE;QACT,OAAO,EAAE,CAAC;KACX;SAAM,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QAC9B,OAAO,CACL,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,CACV,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,CAChB,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EACrE,EAAE,CACH,mCAAI,EAAE,CACR,CAAC;KACH;SAAM;QACL,OAAO,IAAI,CAAC;KACb;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id-to-uuid.d.ts","sourceRoot":"","sources":["../src/id-to-uuid.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,yBAIC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id-to-uuid.js","sourceRoot":"","sources":["../src/id-to-uuid.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAClC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,CACpE,EAAE,EACF,CAAC,CACF,IAAI,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAA"}
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export * from './get-text-content';
|
|
2
|
+
export * from './get-block-title';
|
|
3
|
+
export * from './get-block-icon';
|
|
4
|
+
export * from './get-block-collection-id';
|
|
5
|
+
export * from './get-page-title';
|
|
6
|
+
export * from './get-page-property';
|
|
7
|
+
export * from './get-date-value';
|
|
8
|
+
export * from './get-block-parent-page';
|
|
9
|
+
export * from './get-page-table-of-contents';
|
|
10
|
+
export * from './get-page-content-block-ids';
|
|
11
|
+
export * from './parse-page-id';
|
|
12
|
+
export * from './id-to-uuid';
|
|
13
|
+
export * from './uuid-to-id';
|
|
14
|
+
export * from './get-all-pages-in-space';
|
|
15
|
+
export * from './get-canonical-page-id';
|
|
16
|
+
export * from './get-page-breadcrumbs';
|
|
17
|
+
export * from './get-page-image-urls';
|
|
18
|
+
export * from './is-url';
|
|
19
|
+
export * from './normalize-url';
|
|
20
|
+
export * from './normalize-title';
|
|
21
|
+
export * from './merge-record-maps';
|
|
22
|
+
export * from './format-date';
|
|
23
|
+
export * from './format-notion-date-time';
|
|
24
|
+
export * from './estimate-page-read-time';
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,kBAAkB,CAAA;AAChC,cAAc,2BAA2B,CAAA;AACzC,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AACnC,cAAc,kBAAkB,CAAA;AAChC,cAAc,yBAAyB,CAAA;AACvC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,0BAA0B,CAAA;AACxC,cAAc,yBAAyB,CAAA;AACvC,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AACrC,cAAc,UAAU,CAAA;AACxB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,eAAe,CAAA;AAC7B,cAAc,2BAA2B,CAAA;AACzC,cAAc,2BAA2B,CAAA"}
|
package/build/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export * from './get-text-content';
|
|
2
|
+
export * from './get-block-title';
|
|
3
|
+
export * from './get-block-icon';
|
|
4
|
+
export * from './get-block-collection-id';
|
|
5
|
+
export * from './get-page-title';
|
|
6
|
+
export * from './get-page-property';
|
|
7
|
+
export * from './get-date-value';
|
|
8
|
+
export * from './get-block-parent-page';
|
|
9
|
+
export * from './get-page-table-of-contents';
|
|
10
|
+
export * from './get-page-content-block-ids';
|
|
11
|
+
export * from './parse-page-id';
|
|
12
|
+
export * from './id-to-uuid';
|
|
13
|
+
export * from './uuid-to-id';
|
|
14
|
+
export * from './get-all-pages-in-space';
|
|
15
|
+
export * from './get-canonical-page-id';
|
|
16
|
+
export * from './get-page-breadcrumbs';
|
|
17
|
+
export * from './get-page-image-urls';
|
|
18
|
+
export * from './is-url';
|
|
19
|
+
export * from './normalize-url';
|
|
20
|
+
export * from './normalize-title';
|
|
21
|
+
export * from './merge-record-maps';
|
|
22
|
+
export * from './format-date';
|
|
23
|
+
export * from './format-notion-date-time';
|
|
24
|
+
export * from './estimate-page-read-time';
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,kBAAkB,CAAA;AAChC,cAAc,2BAA2B,CAAA;AACzC,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AACnC,cAAc,kBAAkB,CAAA;AAChC,cAAc,yBAAyB,CAAA;AACvC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,0BAA0B,CAAA;AACxC,cAAc,yBAAyB,CAAA;AACvC,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AACrC,cAAc,UAAU,CAAA;AACxB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,eAAe,CAAA;AAC7B,cAAc,2BAA2B,CAAA;AACzC,cAAc,2BAA2B,CAAA"}
|