An open API service indexing awesome lists of open source software.

https://github.com/sinanbekar/next-github-source

[WIP] Use GitHub repo as CMS in Next.js (similar Hashnode's Github as source)
https://github.com/sinanbekar/next-github-source

cms markdown nextjs typescript

Last synced: about 2 months ago
JSON representation

[WIP] Use GitHub repo as CMS in Next.js (similar Hashnode's Github as source)

Awesome Lists containing this project

README

          

# next-github-source

Use GitHub repo as CMS in Next.js (similar Hashnode's Github as source)

> **Warning** This package is early in development. Do NOT use in production environment.

## 🚀 Quick Start

```bash
npm install next-github-source
```

`lib/githubSourceClient.js`

```js
import { createClient } from "next-github-source";

export const client = createClient({
repo: {
remote: `https://github.com/Hashnode/Hashnode-source-from-github-template`,
},
pattern: [`**`, "!README.md"], // list all except README.md
});
```

`pages/index.js`

```js
import Link from "next/link";
import { client } from "../../lib/githubSourceClient";

export const getStaticProps = async () => {
const posts = await client.getAllEntries();

return {
props: { posts },
};
};

export default function Posts({ posts }) {
return (


{posts.map((post, idx) => (


[{post.source}]({post.slug})


))}

);
}
```

`pages/posts/[slug].js`

```js
import { client } from "../../lib/githubSourceClient";

export const getStaticPaths = async () => {
return {
paths: await client.getAllEntryPaths(),
fallback: false,
};
};

export const getStaticProps = async ({ params }) => {
const post = await client.getEntry(params.slug);

return {
props: { post },
};
};

export default function Post({ post }) {
return

{JSON.stringify(post)}
;
}
```

## TODO

- [ ] Examples with `next-mdx-remote`
- [ ] On-demand revalidation support with examples
- [ ] Matter support with types & validation
- [ ] High test coverage
- [ ] Docs

## License

[MIT](./LICENSE) License © 2022 [Sinan Bekar](https://github.com/sinanbekar)