UNPKG

notion-page-tree

Version:

Recursively fetch nested Notion pages from the root page/database/block node.

54 lines (53 loc) 2.53 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createPageSearchIndex = void 0; var lunr_1 = __importDefault(require("lunr")); var extractPlainTextFromPageProperty_1 = require("../../fetcher/utils/extractPlainTextFromPageProperty"); var createPageSearchIndex = function (page_collection, propertyNames) { var idx = (0, lunr_1.default)(function () { var _this = this; this.pipeline.reset(); this.pipeline.add(lunr_1.default.stopWordFilter, lunr_1.default.stemmer); this.ref('id'); this.field('title'); this.field('plainText'); propertyNames.forEach(function (propertyName) { _this.field(propertyName); }); Object.values(page_collection).forEach(function (page) { var _a; page.type === 'page' && page.metadata.properties && _this.add(__assign({ id: page.id, title: page.metadata.properties['title'] ? (0, extractPlainTextFromPageProperty_1.extractPlainTextFromPageProperty)((_a = page.metadata.properties) === null || _a === void 0 ? void 0 : _a['title']) : '', plainText: page.blockContentPlainText }, propertyNames.map(function (propertyName) { var _a; var _b, _c; return (_a = {}, _a[propertyName] = ((_b = page.metadata.properties) === null || _b === void 0 ? void 0 : _b[propertyName]) ? (0, extractPlainTextFromPageProperty_1.extractPlainTextFromPageProperty)((_c = page.metadata.properties) === null || _c === void 0 ? void 0 : _c[propertyName]) : '', _a); }))); }); }); return { idx: idx, tkn: JSON.parse(JSON.stringify(idx.toJSON())).invertedIndex.map(function (tokenSet) { return tokenSet[0]; }) }; }; exports.createPageSearchIndex = createPageSearchIndex;