-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add git repo link and edit links (#55)
Co-authored-by: Shintaro Tanaka <s-tanaka@holmescloud.com> Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com>
- Loading branch information
1 parent
a90d971
commit 0ea34cb
Showing
10 changed files
with
199 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { computed } from 'vue' | ||
import OutboundLink from './icons/OutboundLink.vue' | ||
import { endingSlashRE, isExternal } from '/@theme/utils' | ||
import { usePageData, useSiteData } from 'vitepress' | ||
import { DefaultTheme } from '../config' | ||
|
||
function createEditLink( | ||
repo: string, | ||
docsRepo: string, | ||
docsDir: string, | ||
docsBranch: string, | ||
path: string | ||
) { | ||
const bitbucket = /bitbucket.org/ | ||
if (bitbucket.test(repo)) { | ||
const base = isExternal(docsRepo) ? docsRepo : repo | ||
return ( | ||
base.replace(endingSlashRE, '') + | ||
`/src` + | ||
`/${docsBranch}/` + | ||
(docsDir ? docsDir.replace(endingSlashRE, '') + '/' : '') + | ||
path + | ||
`?mode=edit&spa=0&at=${docsBranch}&fileviewer=file-view-default` | ||
) | ||
} | ||
|
||
const base = isExternal(docsRepo) | ||
? docsRepo | ||
: `https://github.com/${docsRepo}` | ||
return ( | ||
base.replace(endingSlashRE, '') + | ||
`/edit` + | ||
`/${docsBranch}/` + | ||
(docsDir ? docsDir.replace(endingSlashRE, '') + '/' : '') + | ||
path | ||
) | ||
} | ||
|
||
export default { | ||
components: { | ||
OutboundLink | ||
}, | ||
|
||
setup() { | ||
const pageData = usePageData() | ||
const siteData = useSiteData<DefaultTheme.Config>() | ||
|
||
const editLink = computed(() => { | ||
const showEditLink: boolean | undefined = | ||
pageData.value.frontmatter.editLink == null | ||
? siteData.value.themeConfig.editLinks | ||
: pageData.value.frontmatter.editLink | ||
const { | ||
repo, | ||
docsDir = '', | ||
docsBranch = 'master', | ||
docsRepo = repo | ||
} = siteData.value.themeConfig | ||
|
||
const { relativePath } = pageData.value | ||
if (showEditLink && relativePath && repo) { | ||
return createEditLink( | ||
repo, | ||
docsRepo || repo, | ||
docsDir, | ||
docsBranch, | ||
relativePath | ||
) | ||
} | ||
return null | ||
}) | ||
const editLinkText = computed( | ||
() => siteData.value.themeConfig.editLinkText || 'Edit this page' | ||
) | ||
|
||
return { | ||
editLink, | ||
editLinkText | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<template> | ||
<footer class="page-edit"> | ||
<a | ||
v-if="editLink" | ||
:href="editLink" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
{{ editLinkText }} | ||
<OutboundLink /> | ||
</a> | ||
</footer> | ||
</template> | ||
|
||
<script src="./PageEdit"></script> | ||
|
||
<style> | ||
.page-edit { | ||
padding-top: 1rem; | ||
padding-bottom: 1rem; | ||
overflow: auto; | ||
} | ||
.page-edit a { | ||
color: var(--text-color); | ||
margin-right: 0.25rem; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters