Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"dependencies": {
"@hookform/resolvers": "^5.0.0",
"@notionhq/client": "^3.0.0",
"@notionhq/client": "^5.0.0",
"@radix-ui/react-accordion": "^1.2.7",
"@radix-ui/react-avatar": "^1.1.0",
"@radix-ui/react-checkbox": "^1.1.1",
Expand Down
26 changes: 21 additions & 5 deletions src/lib/notion-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Client } from "@notionhq/client";
import { PageObjectResponse } from "@notionhq/client/build/src/api-endpoints";
import type {
DatabaseObjectResponse,
PageObjectResponse,
} from "@notionhq/client";

export const notion = new Client({
auth: process.env.NOTION_API_SECRET,
Expand All @@ -10,9 +13,21 @@ if (dbId === "") {
throw new Error("Notion DB ID not set!! Check env var");
}

let _dataSourceId: string | undefined;

async function getDataSourceId(): Promise<string> {
if (_dataSourceId) return _dataSourceId;
const db = await notion.databases.retrieve({ database_id: dbId });
const ds = (db as DatabaseObjectResponse).data_sources?.[0];
if (!ds) throw new Error(`No data source found for database ${dbId}`);
_dataSourceId = ds.id;
return _dataSourceId;
}

export async function getNotionPagesWithTag(tag: string) {
const pages = await notion.databases.query({
database_id: dbId,
const dsId = await getDataSourceId();
const pages = await notion.dataSources.query({
data_source_id: dsId,
filter: {
property: "tags",
multi_select: {
Expand All @@ -25,12 +40,13 @@ export async function getNotionPagesWithTag(tag: string) {
}

export async function fetchAllPages(): Promise<PageObjectResponse[]> {
const dsId = await getDataSourceId();
let allPages: PageObjectResponse[] = [];
let cursor: string | undefined = undefined;

while (true) {
const response = await notion.databases.query({
database_id: dbId,
const response = await notion.dataSources.query({
data_source_id: dsId,
start_cursor: cursor,
});

Expand Down
2 changes: 1 addition & 1 deletion src/lib/searchUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PageObjectResponse } from "@notionhq/client/build/src/api-endpoints";
import type { PageObjectResponse } from "@notionhq/client";
import path from "path";

export interface IndexItem {
Expand Down
7 changes: 6 additions & 1 deletion src/scripts/build-search-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ import path from "path";

async function main() {
const notion = new Client({ auth: process.env.NOTION_API_SECRET! });
const { results } = await notion.databases.query({
const db = await notion.databases.retrieve({
database_id: process.env.NOTION_DB_ID!,
});
const dataSourceId = (db as any).data_sources?.[0]?.id as string | undefined;
if (!dataSourceId) throw new Error("No data source found for database");
const { results } = await notion.dataSources.query({
data_source_id: dataSourceId,
});

const index: SearchIndex = createSearchIndex(results as any[]);
const outPath = path.join(process.cwd(), "public/search-index.json");
Expand Down
7 changes: 5 additions & 2 deletions src/scripts/download-notion-images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ const OUT_DIR = path.join(process.cwd(), "public/notion-images");
async function main() {
await fs.mkdir(OUT_DIR, { recursive: true });

const { results } = await notion.databases.query({
database_id: DB_ID,
const db = await notion.databases.retrieve({ database_id: DB_ID });
const dataSourceId = (db as any).data_sources?.[0]?.id as string | undefined;
if (!dataSourceId) throw new Error("No data source found for database");
const { results } = await notion.dataSources.query({
data_source_id: dataSourceId,
});

for (const page of results as any[]) {
Expand Down