-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add git repo link and edit links #55
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c3be547
feat: add git repo link
8b50db8
feat: add edit links
0bf149f
fix conflict resolution mistakes
b3cab2e
refactor: add back the changes
posva 3b6f174
refactor(editLinks): match structure with vuepress
posva a832cca
Update src/client/theme-default/components/NavBarLinks.ts
posva a4ff6db
refactor: remove unecessary wrapper
posva File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sin-tanaka What does this represent? Why are you replacing
/
with/
? is it for Windows? I saw it in the vuepress code base too