-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 166fb74
Showing
26 changed files
with
6,123 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules | ||
jspm_packages | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
.next | ||
|
||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
ISC License | ||
|
||
Copyright (c) 2018-2021, Iain Collins | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted, provided that the above | ||
copyright notice and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# NotionGPT | ||
|
||
Notion + ChatGPT = 🔥 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import React from "react"; | ||
import { signIn, signOut, useSession } from "next-auth/react"; | ||
import Link from "next/link"; | ||
|
||
const AuthButton = () => { | ||
const { data: session, status } = useSession(); | ||
const loading = status === "loading"; | ||
|
||
return ( | ||
<div className="flex"> | ||
<div | ||
className={`nojs-show ${!session && loading ? "animate-pulse" : ""}`} | ||
> | ||
{!session && ( | ||
<div> | ||
<div className="flex mx-auto"> | ||
<Link | ||
href="/api/auth/signin" | ||
className="border-2 py-4 px-8 ml-2 rounded-lg" | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
signIn("notion"); | ||
}} | ||
> | ||
<div className="flex m-be"> | ||
<img | ||
loading="lazy" | ||
height="24" | ||
width="24" | ||
id="provider-logo-dark" | ||
src="https://authjs.dev/img/providers/notion.svg" | ||
></img> | ||
<p className="mx-5">Sign in with Notion</p> | ||
</div> | ||
</Link> | ||
</div> | ||
</div> | ||
)} | ||
{session?.user && ( | ||
<div className=""> | ||
{session.user.image && ( | ||
<span | ||
style={{ backgroundImage: `url('${session.user.image}')` }} | ||
className="bg-cover bg-center w-10 h-10 rounded-full inline-block" | ||
/> | ||
)} | ||
<span className="ml-2 text-gray-600"> | ||
<strong>{session.user.email ?? session.user.name}</strong> | ||
</span> | ||
<a | ||
href="/api/auth/signout" | ||
className="ml-2 bg-gray-300 hover:bg-gray-400 text-gray-800 font-bold py-2 px-4 rounded" | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
signOut(); | ||
}} | ||
> | ||
Sign out | ||
</a> | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default AuthButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import Header from "./header"; | ||
import Footer from "./footer"; | ||
import Content from "./Content"; | ||
import Head from "next/head"; | ||
import PropTypes from "prop-types"; | ||
|
||
const Container = ({ children, title }) => { | ||
return ( | ||
<div> | ||
<Head> | ||
<title>{title}</title> | ||
</Head> | ||
<div className={`wrapper font-sans`}> | ||
<Header /> | ||
<main> | ||
<Content>{children}</Content> | ||
</main> | ||
<Footer /> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
Container.propTypes = { | ||
children: PropTypes.node, | ||
}; | ||
|
||
export default Container; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const Content = ({ children }) => { | ||
return ( | ||
<div className="container mx-auto px-10 lg:w-5/6 py-5 ">{children}</div> | ||
); | ||
}; | ||
|
||
export default Content; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import Link from "next/link"; | ||
|
||
const Footer = ({}) => { | ||
return ( | ||
<div className="bg-[hsla(0,0%,7%,.02)] text-sm"> | ||
<div className="py-8 grid justify-items-center"> | ||
<p> | ||
Made by{" "} | ||
<Link href="jbesomi.com" className=""> | ||
Jonathan Besomi | ||
</Link> | ||
</p> | ||
|
||
<p> | ||
<Link href="https://github.com/jbesomi/notionGPT" target="_blank"> | ||
GitHub: I am open-source | ||
</Link> | ||
</p> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Footer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import Link from "next/link"; | ||
|
||
const Header = () => { | ||
return ( | ||
<div className="text-base"> | ||
<div className="container mx-auto w-3/6 py-5"> | ||
<ul className="flex flex-row flex-nowrap justify-evenly"> | ||
<li className="sans text-5xl font-semibold"> | ||
<Link href="/">notionGPT</Link> | ||
</li> | ||
</ul> | ||
<p className="text-center mt-1">Notion + ChatGPT = 🔥</p> | ||
</div> | ||
<div | ||
className="bg-gradient-to-r from-yellow-200 to-yellow-600" | ||
style={{ height: "2px" }} | ||
></div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Header; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import { Client } from "@notionhq/client"; | ||
import { NotionToMarkdown } from "notion-to-md"; | ||
|
||
export type Page = { | ||
id: string; | ||
title: string; | ||
content: string; | ||
}; | ||
|
||
export async function getAllPageIds(auth: string): Promise<string[]> { | ||
const notion = new Client({ auth }); | ||
const pageIds = []; | ||
let cursor = undefined; | ||
do { | ||
const response = await notion.search({ | ||
query: "", | ||
start_cursor: cursor, | ||
filter: { | ||
property: "object", | ||
value: "page", | ||
}, | ||
}); | ||
|
||
const pages = response.results.filter((result) => result.object === "page"); | ||
|
||
for (const page of pages) { | ||
pageIds.push(page.id); | ||
} | ||
|
||
cursor = response.next_cursor; | ||
} while (cursor !== null); | ||
|
||
return pageIds; | ||
} | ||
|
||
export async function getAllPageIds2(auth: string) { | ||
return await notion.search({}); | ||
} | ||
|
||
export async function getPagesWithWorkspaceParent(auth: string) { | ||
const notion = new Client({ auth }); | ||
const response = await notion.search({ | ||
workspace: true, | ||
}); | ||
return response.results; | ||
} | ||
|
||
export async function getWorkspacePageIds(auth: string) { | ||
const notion = new Client({ auth }); | ||
|
||
const { results } = await notion.search({}); | ||
const workspacePages = results.filter( | ||
(result) => | ||
result.object === "page" && | ||
result.parent.type === "workspace" && | ||
result.parent.workspace === true | ||
); | ||
|
||
const pageIds = workspacePages.map((page) => page.id); | ||
return pageIds; | ||
} | ||
|
||
export async function getAllPageIds3(auth) { | ||
const notion = new Client({ auth }); | ||
|
||
const databaseResults = await notion.search({ | ||
query: "", | ||
filter: { | ||
property: "object", | ||
value: "database", | ||
}, | ||
}); | ||
|
||
const databases = databaseResults.results; | ||
const pageIds = []; | ||
|
||
for (const database of databases) { | ||
const databaseId = database.id; | ||
const databasePages = await notion.databases.query({ | ||
database_id: databaseId, | ||
}); | ||
const pages = databasePages.results; | ||
for (const page of pages) { | ||
pageIds.push(page.id); | ||
} | ||
} | ||
|
||
return pageIds; | ||
} | ||
|
||
export async function getPageContent( | ||
auth: string, | ||
pageIds: string[] | ||
): Promise<Page[]> { | ||
const notion = new Client({ auth }); | ||
const n2m = new NotionToMarkdown({ notionClient: notion }); | ||
const pages: Page[] = []; | ||
|
||
for (const pageId of pageIds) { | ||
const mdblocks = await n2m.pageToMarkdown(pageId); | ||
const pageContentText = n2m.toMarkdownString(mdblocks); | ||
|
||
const page = await notion.pages.retrieve({ page_id: pageId }); | ||
const pageTitle = page.properties.title.title[0].plain_text; | ||
|
||
pages.push({ | ||
id: pageId, | ||
title: pageTitle, | ||
content: pageContentText, | ||
}); | ||
} | ||
|
||
return pages; | ||
} | ||
|
||
export async function getPages(auth: string): Promise<Page[]> { | ||
const pageIds = await getWorkspacePageIds(auth); | ||
const pages = await getPageContent(auth, pageIds); | ||
return pages; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/image-types/global" /> | ||
|
||
// NOTE: This file should not be edited | ||
// see https://nextjs.org/docs/basic-features/typescript for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
typescript: { | ||
// !! WARN !! | ||
// Dangerously allow production builds to successfully complete even if | ||
// your project has type errors. | ||
// !! WARN !! | ||
ignoreBuildErrors: true, | ||
}, | ||
}; |
Oops, something went wrong.