Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 77 additions & 12 deletions docs/content/docs/2.collections/3.sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ source: {

### `repository`

External source representing a remote git repository URL (e.g., <https://github.com/nuxt/content>).
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

When defining an external source you must also define the `include` option.
`include` pattern is essential for the module to know which files to use for the collection.
Expand All @@ -101,27 +101,92 @@ export default defineContentConfig({
})
```

### `authToken`
#### `branch` / `tag`
This option allows for cloning a Git repository by its tag or branch.

Authentication token for private repositories (e.g., GitHub personal access token).
**Example:**
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.

::warning{icon="i-lucide-shield-alert"}
Never commit authentication tokens or credentials directly in your code. Use environment variables or other secure methods to provide these values at runtime.
::
```js
import { defineCollection, defineContentConfig } from '@nuxt/content'

export default defineContentConfig({
collections: {
docs: defineCollection({
type: 'page',
source: {
repository: {
url: 'https://github.com/nuxt/content',
tag: 'v1'
},
include: 'docs/content/**',
},
})
}
})
```

**Example:**

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.

### `authBasic`

Basic authentication for private repositories (e.g., Bitbucket username and password).
```js
import { defineCollection, defineContentConfig } from '@nuxt/content'

export default defineContentConfig({
collections: {
docs: defineCollection({
type: 'page',
source: {
repository: {
url: 'https://github.com/nuxt/content',
branch: 'dev'
},
include: 'docs/content/**',
},
})
}
})
```

#### `auth`
This option allows for basic and token-based authentication for Git repositories.

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

**Example:**

If you want to use basic authentication (e.g. for BitBucket repositories), you can use:
```ts
defineCollection({
type: 'page',
source: {
repository: 'https://bitbucket.org/username/repo',
authBasic: {
username: 'username',
password: 'password',
repository: {
url: 'https://bitbucket.org/username/repo',
auth: {
username: 'username',
password: 'password',
},
},
},
})
```

**Example:**

If you need to use authentication tokens (e.g. for Github, Gitlab, some Forgejo providers), you can do the following:
```ts
defineCollection({
type: 'page',
source: {
repository: {
url: 'https://github.com/username/repo',
auth: {
username: 'username',
token: 'password',
},
},
},
})
```
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"defu": "^6.1.4",
"destr": "^2.0.5",
"git-url-parse": "^16.1.0",
"isomorphic-git": "^1.33.1",
"jiti": "^2.5.1",
"json-schema-to-typescript": "^15.0.4",
"knitwork": "^1.2.0",
Expand Down
Loading
Loading