-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #4
- Loading branch information
Showing
10 changed files
with
5,768 additions
and
29 deletions.
There are no files selected for viewing
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
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
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,73 @@ | ||
/** | ||
* MIT LICENSE *** | ||
* ------------------------------------------------------------------------- | ||
* This code may be modified and distributed under the MIT license. | ||
* See the LICENSE file for details. | ||
* ------------------------------------------------------------------------- | ||
* @summary Create pages via Gatsby Node API | ||
* @author Alvis HT Tang <alvis@hilbert.space> | ||
* @license MIT | ||
* @copyright Copyright (c) 2022 - All Rights Reserved. | ||
* ------------------------------------------------------------------------- | ||
*/ | ||
|
||
import { resolve } from 'node:path'; | ||
|
||
import type { Actions, CreatePagesArgs, GatsbyNode } from 'gatsby'; | ||
|
||
export const createPages: GatsbyNode['createPages'] = async ({ | ||
actions: { createPage }, | ||
graphql, | ||
}) => { | ||
createProjectPages(await queryProjects(graphql), createPage); | ||
}; | ||
|
||
/** | ||
* create project pages | ||
* @param projects projects metadata | ||
* @param createPage the createPage function | ||
*/ | ||
function createProjectPages( | ||
projects: Queries.ProjectsQuery | undefined, | ||
createPage: Actions['createPage'], | ||
): void { | ||
projects?.notionDatabase?.childrenNotionPage?.forEach((page) => { | ||
const mdx = page?.childMarkdownRemark; | ||
const path = page?.properties?.path; | ||
|
||
if (mdx && path) { | ||
createPage({ | ||
path, | ||
// NOTE: must resolve to the absolute path of the component | ||
component: resolve(__dirname, 'src', 'templates', 'project.tsx'), | ||
context: { id: mdx.id }, | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* get projects metadata | ||
* @param graphql the graphql query function | ||
* @returns projects metadata | ||
*/ | ||
async function queryProjects( | ||
graphql: CreatePagesArgs['graphql'], | ||
): Promise<Queries.ProjectsQuery | undefined> { | ||
const { data } = await graphql<Queries.ProjectsQuery>(` | ||
query Projects { | ||
notionDatabase(title: { eq: "Projects" }) { | ||
childrenNotionPage { | ||
childMarkdownRemark { | ||
id | ||
} | ||
properties { | ||
path | ||
} | ||
} | ||
} | ||
} | ||
`); | ||
|
||
return data; | ||
} |
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
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
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,50 @@ | ||
/** | ||
* MIT LICENSE *** | ||
* ------------------------------------------------------------------------- | ||
* This code may be modified and distributed under the MIT license. | ||
* See the LICENSE file for details. | ||
* ------------------------------------------------------------------------- | ||
* @summary Collection of layouts | ||
* @author Alvis HT Tang <alvis@hilbert.space> | ||
* @license MIT | ||
* @copyright Copyright (c) 2021 - All Rights Reserved. | ||
* ------------------------------------------------------------------------- | ||
*/ | ||
|
||
import { graphql } from 'gatsby'; | ||
|
||
import type { PageProps } from 'gatsby'; | ||
|
||
export const query = graphql` | ||
query Project($id: String!) { | ||
markdownRemark(id: { eq: $id }) { | ||
frontmatter { | ||
title | ||
} | ||
html | ||
} | ||
} | ||
`; | ||
|
||
const Project: React.FC<PageProps<Queries.ProjectQuery>> = ({ data }) => { | ||
// since this page is referred from the createPages API, it's safe to assume the mdx node is there | ||
const mdx = data.markdownRemark!; | ||
|
||
const title = mdx.frontmatter?.title; | ||
const html = mdx.html || ''; | ||
|
||
return ( | ||
<section className="py-12 px-4"> | ||
<div className="mx-auto w-full max-w-2xl font-sans main"> | ||
<h1 className="mt-2 mb-6 font-sans text-5xl font-semibold leading-tight text-center font-heading"> | ||
{title} | ||
</h1> | ||
<div | ||
className="prose-sm" | ||
dangerouslySetInnerHTML={{ __html: html }}></div> | ||
</div> | ||
</section> | ||
); | ||
}; | ||
|
||
export default Project; |
Oops, something went wrong.