Skip to content

Commit 96bd428

Browse files
larbishTahul
andauthored
feat(releases): create comp and composable to fetch one by tag (#31)
Co-authored-by: Yaël Guilloux <[email protected]>
1 parent e858f66 commit 96bd428

File tree

19 files changed

+1800
-1714
lines changed

19 files changed

+1800
-1714
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<template>
2+
<GithubRelease v-slot="{ release }" :query="{ tag: 'v0.0.1' }">
3+
{{ release.name }}
4+
</GithubRelease>
5+
</template>

docs/content/3.components.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ This component is useful if you want to display last release of the repository.
138138

139139
::
140140

141-
::props{of="GithubContributors"}
141+
::props{of="GithubLastRelease"}
142142
::
143143

144144
::source-link
@@ -149,6 +149,41 @@ source: "packages/github/src/runtime/components/GithubLastRelease.ts"
149149

150150
---
151151

152+
## `<GithubRelease />`
153+
154+
This component is useful if you want to display release fetched by tag.
155+
156+
::code-group
157+
158+
::code-block{label="Preview"}
159+
::div{class="max-h-[300px] pb-8"}
160+
::release-example
161+
::
162+
::
163+
::
164+
165+
```vue [Code]
166+
<template>
167+
<GithubRelease v-slot="{ release }" :query={ tag: 'v1.0.0'}>
168+
<ProseH1>{{ release.name }}</ProseH1>
169+
<ContentRenderer :value="release" />
170+
</GithubRelease>
171+
</template>
172+
```
173+
174+
::
175+
176+
::props{of="GithubRelease"}
177+
::
178+
179+
::source-link
180+
---
181+
source: "packages/github/src/runtime/components/GithubRelease.ts"
182+
---
183+
::
184+
185+
---
186+
152187
## `<GithubReleases />`
153188

154189
This component is useful if you want to display all the releases of the repository.

docs/content/4.composables.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const {
1313
fetchRepository,
1414
// Fetch repository releases
1515
fetchReleases,
16+
// Fetch repository release by tag
17+
fetchRelease,
1618
// Fetch repository last release
1719
fetchLastRelease,
1820
// Fetch repository contributors
@@ -21,7 +23,7 @@ const {
2123
fetchFileContributors,
2224
// Fetch a readme file
2325
fetchReadme
24-
} = useDocus()
26+
} = useGithub()
2527
```
2628

2729
These helpers makes it easy to use the Github API with `useAsyncData`.

docs/nuxt.config.ts

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { defineNuxtConfig } from 'nuxt'
22

33
export default defineNuxtConfig({
4+
app: {
5+
},
46
extends: [
57
'../node_modules/@nuxt-themes/docus'
68
],
@@ -16,28 +18,5 @@ export default defineNuxtConfig({
1618
prefix: '',
1719
global: true
1820
}
19-
],
20-
tailwindcss: {
21-
config: {
22-
theme: {
23-
extend: {
24-
colors: {
25-
primary: {
26-
DEFAULT: '#4183C4',
27-
50: '#CDDEF0',
28-
100: '#BED4EB',
29-
200: '#9EC0E1',
30-
300: '#7FACD7',
31-
400: '#6097CE',
32-
500: '#4183C4',
33-
600: '#31679C',
34-
700: '#234B72',
35-
800: '#162F47',
36-
900: '#09121C'
37-
}
38-
}
39-
}
40-
}
41-
}
42-
}
21+
]
4322
})

docs/theme.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineTheme } from '@nuxt-themes/kit'
1+
import { defineTheme } from '@nuxt-themes/config'
22

33
export default defineTheme(
44
{

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"@nuxt/test-utils": "^3.0.0-rc.6",
4242
"@nuxtjs/eslint-config-typescript": "latest",
4343
"eslint": "latest",
44-
"nuxt": "npm:nuxt3@latest",
44+
"nuxt": "3.0.0-rc.6",
4545
"release-it": "^15.1.3",
4646
"standard-version": "^9.5.0",
4747
"vitest": "^0.18.1"

playground/components/Navigation.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ const nav = [
1414
name: 'Releases',
1515
path: '/releases'
1616
},
17+
{
18+
name: 'Release by tag',
19+
path: '/release'
20+
},
1721
{
1822
name: 'Last Release',
1923
path: '/last-release'

playground/pages/last-release.vue

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
<script setup lang="ts">
2-
const { owner, repo } = useRuntimeConfig().github
2+
const qOwner = ref('nuxt-community')
3+
const qRepo = ref('supabase-module')
34
</script>
45

56
<template>
67
<div>
7-
<GithubLastRelease v-slot="{ release }">
8-
Fetch last release from config: {{ owner }} / {{ repo }}
8+
<GithubLastRelease v-slot="{ release, refresh }" :query="{ owner: qOwner, repo: qRepo }">
9+
Fetch last release from query:
10+
<input v-model="qOwner" style="margin-left: 1rem;" type="text"> /
11+
<input v-model="qRepo" type="text">
12+
<button style="margin-left: 1rem;" @click="refresh">
13+
Search
14+
</button>
915
<div v-if="release">
1016
<ProseH2 :id="release.name || '#'">
1117
Last Release: {{ release.name }}

playground/pages/release.vue

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<script setup lang="ts">
2+
const qOwner = ref('nuxt-community')
3+
const qRepo = ref('supabase-module')
4+
const tag = ref('v0.1.18')
5+
</script>
6+
7+
<template>
8+
<div>
9+
<GithubRelease v-slot="{ release, refresh }" :query="{ owner: qOwner, repo: qRepo, tag }">
10+
Fetch last release from query:
11+
<div>
12+
Owner: <input v-model="qOwner" type="text">
13+
</div>
14+
<div>
15+
Repo: <input v-model="qRepo" type="text">
16+
</div>
17+
<div>
18+
Tag: <input v-model="tag" type="text">
19+
</div>
20+
<button @click="refresh">
21+
Search
22+
</button>
23+
<div v-if="release">
24+
<ProseH2 :id="release.name || '#'">
25+
Release: {{ release.name }}
26+
</ProseH2>
27+
28+
<p>Version: {{ release.v }}</p>
29+
30+
<p>URL: {{ release.url }}</p>
31+
32+
<p>Zipball: {{ release.zipall }}</p>
33+
34+
<p>Tarball: {{ release.tarball }}</p>
35+
36+
<p>Prerelease: {{ release.prerelease }}</p>
37+
38+
<p>Reactions: {{ release.reactions }}</p>
39+
40+
<p>Author: {{ release.author }}</p>
41+
</div>
42+
</GithubRelease>
43+
</div>
44+
</template>

src/module.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,6 @@ export default defineNuxtModule<ModuleOptions>({
135135

136136
// Setup releases API
137137
if (options.releases) {
138-
// Last release (pre-render friendly)
139-
//
140-
// Have to use `last-release` instead of `release/last` otherwise pre-rendering will throw
141-
// an error as the cached file will try to overwrite `/releases` one.
142-
nitroConfig.handlers.push({
143-
route: '/api/_github/last-release',
144-
handler: resolveModule('./server/api/releases/last', { paths: runtimeDir })
145-
})
146-
nitroConfig.prerender.routes.push('/api/_github/last-release')
147-
148138
// Releases list
149139
nitroConfig.handlers.push({
150140
route: '/api/_github/releases',
@@ -163,6 +153,11 @@ export default defineNuxtModule<ModuleOptions>({
163153
filePath: resolveModule('./components/GithubLastRelease', { paths: runtimeDir }),
164154
global: true
165155
})
156+
addComponent({
157+
name: 'GithubRelease',
158+
filePath: resolveModule('./components/GithubRelease', { paths: runtimeDir }),
159+
global: true
160+
})
166161
}
167162

168163
// Setup contributors API

0 commit comments

Comments
 (0)