Skip to content
Merged
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
8 changes: 6 additions & 2 deletions docs/content/en/themes/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,11 @@ You can create a `content/settings.json` file to configure the theme.
- `logo` (`String` | `Object`)
- The logo of your project, can be an `Object` to set a logo per [color mode](https://github.com/nuxt-community/color-mode-module)
- `github` (`String`)
- 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`
- 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`.
- For GitHub Enterprise, you have to assign a full url of your project without a trailing slash. Example: `https://hostname/repos/owner/name`.
- `githubApi` (`String`)
- 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`.
- Releases are fetched from `${githubApi}/releases`.
- `twitter` (`String`)
- The Twitter username `@username` you want to link. Example: `@nuxt_js`
- `defaultBranch` (`String`) <badge>v0.2.0+</badge>
Expand Down Expand Up @@ -580,4 +584,4 @@ link: https://codesandbox.io/embed/nuxt-content-l164h?hidenavigation=1&theme=dar
<img src="https://storybook.nuxtjs.org/preview-dark.png" class="dark-img" />
</a>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion packages/create-nuxt-content-docs/test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const sao = require('sao')

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

test('should write files with good answers', async () => {
test('should write files with good answers (GitHub)', async () => {
const answers = {
name: 'nuxt-content-docs',
title: 'Nuxt Content',
Expand Down
4 changes: 2 additions & 2 deletions packages/theme-docs/src/components/app/AppGithubLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default {
computed: {
...mapGetters([
'settings',
'githubUrls',
'lastRelease'
]),
link () {
Expand All @@ -33,8 +34,7 @@ export default {
}

return [
'https://github.com',
this.settings.github,
this.githubUrls.repo,
'edit',
this.settings.defaultBranch,
this.settings.defaultDir,
Expand Down
3 changes: 2 additions & 1 deletion packages/theme-docs/src/components/app/AppHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
</a>
<a
v-if="settings.github"
:href="`https://github.com/${settings.github}`"
:href="githubUrls.repo"
target="_blank"
rel="noopener noreferrer"
title="Github"
Expand Down Expand Up @@ -93,6 +93,7 @@ export default {
computed: {
...mapGetters([
'settings',
'githubUrls',
'lastRelease'
]),
menu: {
Expand Down
5 changes: 3 additions & 2 deletions packages/theme-docs/src/components/app/AppNav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
</a>
<a
v-if="settings.github"
:href="`https://github.com/${settings.github}`"
:href="githubUrls.repo"
target="_blank"
rel="noopener noreferrer"
title="Github"
Expand All @@ -76,7 +76,8 @@ import { mapGetters } from 'vuex'
export default {
computed: {
...mapGetters([
'settings'
'settings',
'githubUrls'
]),
menu: {
get () {
Expand Down
31 changes: 27 additions & 4 deletions packages/theme-docs/src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,29 @@ export const getters = {
settings (state) {
return state.settings
},
githubUrls (state) {
const { github = '', githubApi = '' } = state.settings

// GitHub Enterprise
if (github.startsWith('http') && githubApi.startsWith('http')) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it enough to check just existence of the 2 settings?

 if (github && githubApi) { ... }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be enough I guess

return {
repo: github,
api: {
repo: githubApi,
releases: `${githubApi}/releases`
}
}
}

// GitHub
return {
repo: `https://github.com/repos/${github}`,
api: {
repo: `https://api.github.com/repos/${github}`,
releases: `https://api.github.com/repos/${github}/releases`
}
}
},
releases (state) {
return state.releases
},
Expand Down Expand Up @@ -54,7 +77,7 @@ export const actions = {

commit('SET_CATEGORIES', categories)
},
async fetchReleases ({ commit, state }) {
async fetchReleases ({ commit, state, getters }) {
if (!state.settings.github) {
return
}
Expand All @@ -65,7 +88,7 @@ export const actions = {
}
let releases = []
try {
const data = await fetch(`https://api.github.com/repos/${state.settings.github}/releases`, options).then((res) => {
const data = await fetch(getters.githubUrls.api.releases, options).then((res) => {
if (!res.ok) {
throw new Error(res.statusText)
}
Expand All @@ -92,7 +115,7 @@ export const actions = {

commit('SET_RELEASES', releases)
},
async fetchDefaultBranch ({ commit, state }) {
async fetchDefaultBranch ({ commit, state, getters }) {
if (!state.settings.github || state.settings.defaultBranch) {
return
}
Expand All @@ -103,7 +126,7 @@ export const actions = {
}
let defaultBranch
try {
const data = await fetch(`https://api.github.com/repos/${state.settings.github}`, options).then((res) => {
const data = await fetch(getters.githubUrls.api.repo, options).then((res) => {
if (!res.ok) {
throw new Error(res.statusText)
}
Expand Down