Skip to content

Commit d01e134

Browse files
authored
feat: support github custom domain (#458)
1 parent 83a2cd6 commit d01e134

File tree

6 files changed

+41
-12
lines changed

6 files changed

+41
-12
lines changed

docs/content/en/themes/docs.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,11 @@ You can create a `content/settings.json` file to configure the theme.
359359
- `logo` (`String` | `Object`)
360360
- The logo of your project, can be an `Object` to set a logo per [color mode](https://github.com/nuxt-community/color-mode-module)
361361
- `github` (`String`)
362-
- The GitHub repository of your project `owner/name` to display the last version, the releases page, the link at the top and the `Edit this page on GitHub link` on each page. Example: `nuxt/content`
362+
- The GitHub repository of your project `owner/name` to display the last version, the releases page, the link at the top and the `Edit this page on GitHub link` on each page Example: `nuxt/content`.
363+
- For GitHub Enterprise, you have to assign a full url of your project without a trailing slash. Example: `https://hostname/repos/owner/name`.
364+
- `githubApi` (`String`)
365+
- For GitHub Enterprise, in addition to `github`, you have to assign a API full url of your project without a trailing slash. Example: `https://hostname/api/v3/repos/owner/name`.
366+
- Releases are fetched from `${githubApi}/releases`.
363367
- `twitter` (`String`)
364368
- The Twitter username `@username` you want to link. Example: `@nuxt_js`
365369
- `defaultBranch` (`String`) <badge>v0.2.0+</badge>
@@ -580,4 +584,4 @@ link: https://codesandbox.io/embed/nuxt-content-l164h?hidenavigation=1&theme=dar
580584
<img src="https://storybook.nuxtjs.org/preview-dark.png" class="dark-img" />
581585
</a>
582586
</div>
583-
</div>
587+
</div>

packages/create-nuxt-content-docs/test/cli.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const sao = require('sao')
33

44
const generator = path.join(__dirname, '../src')
55

6-
test('should write files with good answers', async () => {
6+
test('should write files with good answers (GitHub)', async () => {
77
const answers = {
88
name: 'nuxt-content-docs',
99
title: 'Nuxt Content',

packages/theme-docs/src/components/app/AppGithubLink.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export default {
2525
computed: {
2626
...mapGetters([
2727
'settings',
28+
'githubUrls',
2829
'lastRelease'
2930
]),
3031
link () {
@@ -33,8 +34,7 @@ export default {
3334
}
3435
3536
return [
36-
'https://github.com',
37-
this.settings.github,
37+
this.githubUrls.repo,
3838
'edit',
3939
this.settings.defaultBranch,
4040
this.settings.defaultDir,

packages/theme-docs/src/components/app/AppHeader.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
</a>
5454
<a
5555
v-if="settings.github"
56-
:href="`https://github.com/${settings.github}`"
56+
:href="githubUrls.repo"
5757
target="_blank"
5858
rel="noopener noreferrer"
5959
title="Github"
@@ -93,6 +93,7 @@ export default {
9393
computed: {
9494
...mapGetters([
9595
'settings',
96+
'githubUrls',
9697
'lastRelease'
9798
]),
9899
menu: {

packages/theme-docs/src/components/app/AppNav.vue

+3-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
</a>
5252
<a
5353
v-if="settings.github"
54-
:href="`https://github.com/${settings.github}`"
54+
:href="githubUrls.repo"
5555
target="_blank"
5656
rel="noopener noreferrer"
5757
title="Github"
@@ -76,7 +76,8 @@ import { mapGetters } from 'vuex'
7676
export default {
7777
computed: {
7878
...mapGetters([
79-
'settings'
79+
'settings',
80+
'githubUrls'
8081
]),
8182
menu: {
8283
get () {

packages/theme-docs/src/store/index.js

+27-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,29 @@ export const getters = {
1616
settings (state) {
1717
return state.settings
1818
},
19+
githubUrls (state) {
20+
const { github = '', githubApi = '' } = state.settings
21+
22+
// GitHub Enterprise
23+
if (github.startsWith('http') && githubApi.startsWith('http')) {
24+
return {
25+
repo: github,
26+
api: {
27+
repo: githubApi,
28+
releases: `${githubApi}/releases`
29+
}
30+
}
31+
}
32+
33+
// GitHub
34+
return {
35+
repo: `https://github.com/repos/${github}`,
36+
api: {
37+
repo: `https://api.github.com/repos/${github}`,
38+
releases: `https://api.github.com/repos/${github}/releases`
39+
}
40+
}
41+
},
1942
releases (state) {
2043
return state.releases
2144
},
@@ -54,7 +77,7 @@ export const actions = {
5477

5578
commit('SET_CATEGORIES', categories)
5679
},
57-
async fetchReleases ({ commit, state }) {
80+
async fetchReleases ({ commit, state, getters }) {
5881
if (!state.settings.github) {
5982
return
6083
}
@@ -65,7 +88,7 @@ export const actions = {
6588
}
6689
let releases = []
6790
try {
68-
const data = await fetch(`https://api.github.com/repos/${state.settings.github}/releases`, options).then((res) => {
91+
const data = await fetch(getters.githubUrls.api.releases, options).then((res) => {
6992
if (!res.ok) {
7093
throw new Error(res.statusText)
7194
}
@@ -92,7 +115,7 @@ export const actions = {
92115

93116
commit('SET_RELEASES', releases)
94117
},
95-
async fetchDefaultBranch ({ commit, state }) {
118+
async fetchDefaultBranch ({ commit, state, getters }) {
96119
if (!state.settings.github || state.settings.defaultBranch) {
97120
return
98121
}
@@ -103,7 +126,7 @@ export const actions = {
103126
}
104127
let defaultBranch
105128
try {
106-
const data = await fetch(`https://api.github.com/repos/${state.settings.github}`, options).then((res) => {
129+
const data = await fetch(getters.githubUrls.api.repo, options).then((res) => {
107130
if (!res.ok) {
108131
throw new Error(res.statusText)
109132
}

0 commit comments

Comments
 (0)