diff --git a/src/runtime/components/GithubLink.ts b/src/runtime/components/GithubLink.ts index ec81631..55999d7 100644 --- a/src/runtime/components/GithubLink.ts +++ b/src/runtime/components/GithubLink.ts @@ -80,19 +80,41 @@ export default defineComponent({ throw new Error('If you want to use `GithubLink` component, you must specify: `owner`, `repo` and `branch`.') } - const base = computed(() => joinURL('https://github.com', `${props.owner}/${props.repo}`)) + let repo = props.repo + let owner = props.owner + let branch = props.branch + let contentDir = props.contentDir + let prefix = '' + const { sources } = useRuntimeConfig().content + let source + for (const key in Object.keys(sources)) { + if (props.page._id.startsWith(key)) { + source = sources[key] + break + } + } + + if (source?.driver === 'github') { + repo = source.repo + owner = '' + branch = source.branch || 'main' + contentDir = source.dir || '' + prefix = source.prefix || '' + } + + const base = computed(() => joinURL('https://github.com', `${owner}/${repo}`)) const path = computed(() => { - const dirParts = [] + const dirParts: string[] = [] // @nuxt/content support // Create the URL from a document data. if (props?.page?._path) { // Use content dir - if (props.contentDir) { dirParts.push(props.contentDir) } + if (contentDir) { dirParts.push(contentDir) } // Get page file from page data - dirParts.push(props.page._file) + dirParts.push(props.page._file.substring(prefix.length)) return dirParts } @@ -118,7 +140,7 @@ export default defineComponent({ if (props.edit) { parts.push('edit') } else { parts.push('tree') } - parts.push(props.branch, ...path.value) + parts.push(branch, ...path.value) return parts.filter(Boolean).join('/') })