Skip to content
Merged
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
32 changes: 27 additions & 5 deletions src/runtime/components/GithubLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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('/')
})
Expand Down