feat: add research submodule and page
This commit is contained in:
parent
3d450a389b
commit
4a39e535a3
13 changed files with 217 additions and 10 deletions
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
[submodule "research"]
|
||||
path = research
|
||||
url = https://github.com/chora-studio/research
|
||||
|
|
@ -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',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
|
|
|
|||
11
app/research/[id]/page.module.css
Normal file
11
app/research/[id]/page.module.css
Normal file
|
|
@ -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';
|
||||
}
|
||||
34
app/research/[id]/page.tsx
Normal file
34
app/research/[id]/page.tsx
Normal file
|
|
@ -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 (
|
||||
<div className={styles.page}>
|
||||
<div className={styles.banner}>
|
||||
<div>
|
||||
<h3>{post.date}</h3>
|
||||
<h1>{post.title}</h1>
|
||||
<h2>{`by ${post.author}`}</h2>
|
||||
</div>
|
||||
</div>
|
||||
<div className={styles.content}>
|
||||
<div dangerouslySetInnerHTML={{ __html: post.content }} />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default PostPage
|
||||
27
app/research/page.module.css
Normal file
27
app/research/page.module.css
Normal file
|
|
@ -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;
|
||||
}
|
||||
56
app/research/page.tsx
Normal file
56
app/research/page.tsx
Normal file
|
|
@ -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 (
|
||||
<div className={styles.page}>
|
||||
<div className={styles.banner}>
|
||||
<div>
|
||||
<h1 style={{ opacity: '0.75' }}>{'research'}</h1>
|
||||
</div>
|
||||
</div>
|
||||
<div className={styles.content}>
|
||||
{!posts.length ? (
|
||||
<p>{'coming soon...'}</p>
|
||||
) : (
|
||||
<ul>
|
||||
{posts.map(({ id, date, title, author }) => (
|
||||
<li key={id}>
|
||||
<Link href={`/research/${id}`}>
|
||||
<h4>{date}</h4>
|
||||
<h2>{title}</h2>
|
||||
<h3>{`by ${author}`}</h3>
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default ResearchPage
|
||||
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
|
|
@ -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",
|
||||
|
|
|
|||
1
research
Submodule
1
research
Submodule
|
|
@ -0,0 +1 @@
|
|||
Subproject commit e554985a3ece9bf7e7f8abc42155be5f7d6aaa76
|
||||
|
|
@ -18,7 +18,10 @@
|
|||
{
|
||||
"name": "next"
|
||||
}
|
||||
]
|
||||
],
|
||||
"paths": {
|
||||
"@utils": ["utils/index.ts"]
|
||||
}
|
||||
},
|
||||
"include": [
|
||||
"next-env.d.ts",
|
||||
|
|
|
|||
27
utils/getDoc.ts
Normal file
27
utils/getDoc.ts
Normal file
|
|
@ -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
|
||||
}
|
||||
35
utils/getDocs.ts
Normal file
35
utils/getDocs.ts
Normal file
|
|
@ -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[]
|
||||
}
|
||||
2
utils/index.ts
Normal file
2
utils/index.ts
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
export { getDoc } from './getDoc'
|
||||
export { getDocs } from './getDocs'
|
||||
Loading…
Add table
Add a link
Reference in a new issue