Skip to content

Commit e6bf06f

Browse files
walefarnabaz
andauthored
feat: shallow clone git repository sources (#3542)
Co-authored-by: Farnabaz <farnabaz@gmail.com>
1 parent 1391235 commit e6bf06f

File tree

13 files changed

+434
-313
lines changed

13 files changed

+434
-313
lines changed

docs/content/docs/2.collections/3.sources.md

Lines changed: 78 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ source: {
8080

8181
### `repository`
8282

83-
External source representing a remote git repository URL (e.g., <https://github.com/nuxt/content>).
83+
External source representing a remote git repository URL (e.g., <https://github.com/nuxt/content>), or an object containing Git branch / tag information, or optionally authentication
8484

8585
When defining an external source you must also define the `include` option.
8686
`include` pattern is essential for the module to know which files to use for the collection.
@@ -101,26 +101,95 @@ export default defineContentConfig({
101101
})
102102
```
103103

104-
### `authToken`
104+
#### `branch` / `tag`
105+
This option allows for cloning a Git repository by its tag or branch.
105106

106-
Authentication token for private repositories (e.g., GitHub personal access token).
107+
**Example:**
108+
If you want to clone by a tag, make the `repository` attribute an object, with the `url` of your repository, and set the `tag` attribute.
109+
110+
```js
111+
import { defineCollection, defineContentConfig } from '@nuxt/content'
112+
113+
export default defineContentConfig({
114+
collections: {
115+
docs: defineCollection({
116+
type: 'page',
117+
source: {
118+
repository: {
119+
url: 'https://github.com/nuxt/content',
120+
tag: 'v1'
121+
},
122+
include: 'docs/content/**',
123+
},
124+
})
125+
}
126+
})
127+
```
128+
129+
**Example:**
130+
131+
If you want to clone by a remote branch, make the `repository` attribute an object, with the `url` of your repository, and set the `branch` attribute.
132+
133+
```js
134+
import { defineCollection, defineContentConfig } from '@nuxt/content'
135+
136+
export default defineContentConfig({
137+
collections: {
138+
docs: defineCollection({
139+
type: 'page',
140+
source: {
141+
repository: {
142+
url: 'https://github.com/nuxt/content',
143+
branch: 'dev'
144+
},
145+
include: 'docs/content/**',
146+
},
147+
})
148+
}
149+
})
150+
```
151+
152+
#### `auth`
153+
154+
This option allows for basic and token-based authentication for Git repositories.
107155

108156
::warning{icon="i-lucide-shield-alert"}
109157
Never commit authentication tokens or credentials directly in your code. Use environment variables or other secure methods to provide these values at runtime.
110158
::
111159

112-
### `authBasic`
160+
**Example:**
113161

114-
Basic authentication for private repositories (e.g., Bitbucket username and password).
162+
If you want to use basic authentication (e.g. for BitBucket repositories), you can use:
115163

116164
```ts
117165
defineCollection({
118166
type: 'page',
119167
source: {
120-
repository: 'https://bitbucket.org/username/repo',
121-
authBasic: {
122-
username: 'username',
123-
password: 'password',
168+
repository: {
169+
url: 'https://bitbucket.org/username/repo',
170+
auth: {
171+
username: 'username',
172+
password: 'password',
173+
},
174+
},
175+
},
176+
})
177+
```
178+
179+
**Example:**
180+
181+
If you need to use authentication tokens (e.g. for Github, Gitlab, some Forgejo providers), you can do the following:
182+
183+
```ts
184+
defineCollection({
185+
type: 'page',
186+
source: {
187+
repository: {
188+
url: 'https://github.com/username/repo',
189+
auth: {
190+
username: 'username',
191+
token: 'password',
192+
},
124193
},
125194
},
126195
})

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"destr": "^2.0.5",
7474
"git-url-parse": "^16.1.0",
7575
"hookable": "^5.5.3",
76+
"isomorphic-git": "^1.33.1",
7677
"jiti": "^2.6.1",
7778
"json-schema-to-typescript": "^15.0.4",
7879
"knitwork": "^1.3.0",
@@ -86,7 +87,6 @@
8687
"micromatch": "^4.0.8",
8788
"minimark": "^0.2.0",
8889
"minimatch": "^10.1.1",
89-
"modern-tar": "^0.7.2",
9090
"nuxt-component-meta": "0.15.0",
9191
"nypm": "^0.6.2",
9292
"ohash": "^2.0.11",

playground/content.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const collections = {
9090
nuxt: defineCollection({
9191
type: 'page',
9292
source: {
93-
repository: 'https://github.com/nuxt/nuxt',
93+
repository: 'https://github.com/nuxt/nuxt/tree/main',
9494
include: 'docs/**',
9595
prefix: '/nuxt',
9696
exclude: [

0 commit comments

Comments
 (0)