Skip to content

Commit c45a060

Browse files
committed
feat: cache for one minute
1 parent fe924a8 commit c45a060

File tree

3 files changed

+563
-475
lines changed

3 files changed

+563
-475
lines changed

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,19 @@ export default defineNuxtConfig({
2222
modules: [
2323
'@nuxt/content', // Required
2424
'@docus/github'
25-
]
25+
],
26+
github: {
27+
repo: 'nuxt/framework'
28+
}
2629
})
2730
```
2831

32+
Lastly, create a [personal access token](https://github.com/settings/tokens) on GitHub and add it into your `.env`:
33+
34+
```env
35+
GITHUB_TOKEN='<your-personal-token>'
36+
```
37+
2938
## Usage
3039

3140
```vue
@@ -43,6 +52,27 @@ const { data: releases } = await useAsyncData('releases', () => githubReleases()
4352
</template>
4453
```
4554

55+
## Options
56+
57+
```ts
58+
github: {
59+
repo: string,
60+
releases: false | {
61+
api: string
62+
repo: string
63+
token: string
64+
/**
65+
* Parse release notes markdown and return AST tree
66+
*
67+
* Note: This option is only available when you have `@nuxt/content` installed in your project.
68+
*
69+
* @default true
70+
*/
71+
parse: boolean
72+
}
73+
}
74+
```
75+
4676
## Development
4777

4878
1. Run `npm run dev:prepare` to generate type stubs.

src/runtime/server/api/releases.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { defineEventHandler } from 'h3'
21
import * as imports from '#imports'
32

43
interface GithubRawRelease {
@@ -17,7 +16,7 @@ interface GithubReleasesOptions {
1716
token: string
1817
}
1918

20-
export default defineEventHandler(async () => {
19+
export default imports.defineCachedEventHandler(async () => {
2120
const { releases: releasesConfig } = imports.useRuntimeConfig().github
2221

2322
// Fetches releases from GitHub
@@ -39,6 +38,8 @@ export default defineEventHandler(async () => {
3938
releases.sort((a, b) => a.v !== b.v ? b.v - a.v : a.date - b.date)
4039

4140
return releases
41+
}, {
42+
maxAge: 60 // cache for one minute
4243
})
4344

4445
const normalizeReleaseName = (name: string) => {

0 commit comments

Comments
 (0)