diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..1020fa1 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "research"] + path = research + url = https://github.com/chora-studio/research diff --git a/app/layout.tsx b/app/layout.tsx index a004ecf..f24c362 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -34,9 +34,9 @@ const Layout = ({ children }: any) => ( }, 'divider', { - link: 'https://chora.blog', - title: 'blog', - target: '_blank', + link: '/research', + title: 'research', + target: '', }, ]} showMenuButton={true} @@ -64,6 +64,11 @@ const Layout = ({ children }: any) => ( target: '', title: 'validator', }, + { + link: 'research', + target: '', + title: 'research', + }, 'divider', { link: 'https://chora.blog', @@ -89,11 +94,6 @@ const Layout = ({ children }: any) => ( { title: 'chora studio', items: [ - { - link: 'https://chora.blog', - target: '_blank', - title: 'blog', - }, { link: '/products', target: '', @@ -109,6 +109,11 @@ const Layout = ({ children }: any) => ( target: '', title: 'validator', }, + { + link: '/research', + target: '', + title: 'research', + }, ], }, { diff --git a/app/research/[id]/page.module.css b/app/research/[id]/page.module.css new file mode 100644 index 0000000..8f3e108 --- /dev/null +++ b/app/research/[id]/page.module.css @@ -0,0 +1,11 @@ +.page { + composes: page from 'chora/styles/page.css'; +} + +.banner { + composes: banner-document from 'chora/styles/main.css'; +} + +.content { + composes: content-full from 'chora/styles/main.css'; +} diff --git a/app/research/[id]/page.tsx b/app/research/[id]/page.tsx new file mode 100644 index 0000000..c2ef814 --- /dev/null +++ b/app/research/[id]/page.tsx @@ -0,0 +1,34 @@ +import { Metadata } from 'next' + +import { getDoc, getDocs } from '@utils' + +import styles from './page.module.css' + +export const metadata: Metadata = { + title: 'chora blog | news', +} + +export const generateStaticParams = () => { + return getDocs() +} + +const PostPage = async ({ params }: any) => { + const post = await getDoc(params.id) + + return ( +
+
+
+

{post.date}

+

{post.title}

+

{`by ${post.author}`}

+
+
+
+
+
+
+ ) +} + +export default PostPage diff --git a/app/research/page.module.css b/app/research/page.module.css new file mode 100644 index 0000000..b12cd92 --- /dev/null +++ b/app/research/page.module.css @@ -0,0 +1,27 @@ +.page { + composes: page from 'chora/styles/page.css'; +} + +.banner { + composes: banner from 'chora/styles/main.css'; +} + +.content { + composes: content-full from 'chora/styles/main.css'; +} + +.content h2 { + margin: 0.5em 0; +} + +.content h3 { + color: var(--color-text); +} + +.content h4 { + color: var(--color-text); +} + +.content ul { + list-style: none inside none; +} diff --git a/app/research/page.tsx b/app/research/page.tsx new file mode 100644 index 0000000..30a4602 --- /dev/null +++ b/app/research/page.tsx @@ -0,0 +1,56 @@ +import { Metadata } from 'next' +import Link from 'next/link' + +import { getDocs } from '@utils' + +import styles from './page.module.css' + +export const metadata: Metadata = { + title: 'chora blog | research', +} + +async function getPosts() { + const allPosts = getDocs().filter((p) => p.tags.includes('research')) + + // sort posts by date + return allPosts.sort((a, b) => { + if (a.date < b.date) { + return 1 + } else { + return -1 + } + }) +} + +const ResearchPage = async () => { + const posts = await getPosts() + + return ( +
+
+
+

{'research'}

+
+
+
+ {!posts.length ? ( +

{'coming soon...'}

+ ) : ( +
    + {posts.map(({ id, date, title, author }) => ( +
  • + +

    {date}

    +

    {title}

    +

    {`by ${author}`}

    + +
  • + ))} +
+ )} +
+
+ ) +} + +export default ResearchPage diff --git a/bun.lockb b/bun.lockb index 1510969..6eb5282 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index e255c84..1c77b0f 100644 --- a/package.json +++ b/package.json @@ -21,9 +21,12 @@ }, "dependencies": { "chora": "npm:@chora-io/chora@v0.1.0-beta12", + "gray-matter": "^4", "next": "^14", "react": "^18", - "react-dom": "^18" + "react-dom": "^18", + "remark": "^15", + "remark-html": "^16" }, "devDependencies": { "@types/node": "^20", diff --git a/research b/research new file mode 160000 index 0000000..e554985 --- /dev/null +++ b/research @@ -0,0 +1 @@ +Subproject commit e554985a3ece9bf7e7f8abc42155be5f7d6aaa76 diff --git a/tsconfig.json b/tsconfig.json index 9ca4887..a4667fd 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,7 +18,10 @@ { "name": "next" } - ] + ], + "paths": { + "@utils": ["utils/index.ts"] + } }, "include": [ "next-env.d.ts", diff --git a/utils/getDoc.ts b/utils/getDoc.ts new file mode 100644 index 0000000..f47047d --- /dev/null +++ b/utils/getDoc.ts @@ -0,0 +1,27 @@ +import fs from 'fs' +import path from 'path' +import matter from 'gray-matter' +import { remark } from 'remark' +import html from 'remark-html' + +const docsDirectory = path.join(process.cwd(), 'research/docs') + +export async function getDoc(id: string) { + const fullPath = path.join(docsDirectory, `${id}.md`) + + // read file contents + const fileContents = fs.readFileSync(fullPath, 'utf8') + + // parse file contents + const { content, data } = matter(fileContents) + + // convert markdown to html + const processedContent = await remark().use(html).process(content) + + // return id, content, and data + return { + id, + content: processedContent.toString(), + ...data, + } as any +} diff --git a/utils/getDocs.ts b/utils/getDocs.ts new file mode 100644 index 0000000..f0cf58d --- /dev/null +++ b/utils/getDocs.ts @@ -0,0 +1,35 @@ +import fs from 'fs' +import path from 'path' +import matter from 'gray-matter' + +const docsDirectory = path.join(process.cwd(), 'research/docs') + +export const getDocs = () => { + const fileNames = fs.readdirSync(docsDirectory) + return fileNames.map((fileName) => { + + console.log("HERE", fileName) + + if (!fileName || fileName.includes('README.md')) { + return { + id: 'readme', + data: {}, + } + } + // set id and full path + const id = fileName.replace(/\.md$/, '') + const fullPath = path.join(docsDirectory, fileName) + + // read file contents + const fileContents = fs.readFileSync(fullPath, 'utf8') + + // parse file contents + const { data } = matter(fileContents) + + // return id and data + return { + id, + ...data, + } + }) as any[] +} diff --git a/utils/index.ts b/utils/index.ts new file mode 100644 index 0000000..8165489 --- /dev/null +++ b/utils/index.ts @@ -0,0 +1,2 @@ +export { getDoc } from './getDoc' +export { getDocs } from './getDocs'