-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[topics,#13][l]: working topics section with data pulled from github.…
…com/datasets/awesome-data - fixes #13. * index page: (crude atm) just a listing of the page with their markdown names * topic pages: load and run through data literate processing Loading is done via github graphql. May be some inefficiency here in that we load all the data for every page but i hope apollo helps with caching.
- Loading branch information
1 parent
eba78e8
commit 8473729
Showing
4 changed files
with
119 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import DataLiterate from '../../components/DataLiterate' | ||
import parse from '../../lib/markdown.js' | ||
import { getTopics } from '../../utils/topicsData' | ||
|
||
export default function Topic({source, frontMatter}) { | ||
return ( | ||
<DataLiterate source={source} frontMatter={frontMatter} /> | ||
) | ||
} | ||
|
||
export async function getStaticProps({ params }) { | ||
const topics = await getTopics() | ||
const filename = params.id + '.md' | ||
const topic = topics.find(t => t.name == filename) | ||
|
||
const source = topic.object.text | ||
const { mdxSource, frontMatter } = await parse(source) | ||
|
||
// HACK: can't have date types in data we pass around as does not json serialize | ||
// see e.g. https://github.com/vercel/next.js/discussions/11498 | ||
// you could try to disable gray-matter auto-parsing of dates - see https://github.com/jonschlinkert/gray-matter/issues/62 | ||
// however simplest for now is to reconvert | ||
for (const [key, value] of Object.entries(frontMatter)) { | ||
if (value instanceof Date) { | ||
frontMatter[key] = value.toJSON() | ||
} | ||
} | ||
|
||
return { | ||
props: { | ||
source: mdxSource, | ||
frontMatter: frontMatter, | ||
}, | ||
} | ||
} | ||
|
||
export async function getStaticPaths() { | ||
const topics = await getTopics() | ||
const paths = topics.map((topic) => { | ||
return { | ||
params: { | ||
id: [topic.name.replace(/\.mdx?$/, '')] | ||
} | ||
} | ||
}) | ||
|
||
return { | ||
paths, | ||
fallback: false | ||
} | ||
} |
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,30 @@ | ||
import Link from 'next/link' | ||
|
||
import Layout from '../../components/Layout' | ||
import { getTopics } from '../../utils/topicsData' | ||
|
||
|
||
export default function Index({ topics }) { | ||
return ( | ||
<Layout> | ||
<h2>Topics</h2> | ||
<ul> | ||
{topics.map((topic) => ( | ||
<li> | ||
<Link | ||
href={`/topics/${topic.name.replace(/\.mdx?$/, '')}`} | ||
> | ||
<a>{topic.name}</a> | ||
</Link> | ||
</li> | ||
))} | ||
</ul> | ||
</Layout> | ||
) | ||
} | ||
|
||
export async function getStaticProps() { | ||
const topics = await getTopics() | ||
|
||
return { props: { topics } } | ||
} |
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,37 @@ | ||
import { gql } from '@apollo/client' | ||
import client from '../lib/github' | ||
|
||
export async function getTopics() { | ||
// github query inspired by https://gist.github.com/MichaelCurrin/6777b91e6374cdb5662b64b8249070ea | ||
const { data, loading, error } = await client.query({ | ||
query: gql` | ||
query RepoFiles($owner: String!, $name: String!) { | ||
repository(owner: $owner, name: $name) { | ||
object(expression: "HEAD:") { | ||
... on Tree { | ||
entries { | ||
name | ||
type | ||
mode | ||
object { | ||
... on Blob { | ||
byteSize | ||
text | ||
isBinary | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`, | ||
variables: { | ||
"owner": "datasets", | ||
"name": "awesome-data" | ||
} | ||
}); | ||
|
||
return data.repository.object.entries | ||
} |
8473729
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: