test02/node_modules/@vuepress/theme-default/lib/client/composables/useEditLink.js
罗佳鸿 6aa1ebe342
Some checks are pending
部署文档 / deploy-gh-pages (push) Waiting to run
first commit
2024-08-13 10:11:19 +08:00

32 lines
1.1 KiB
JavaScript

import { useThemeLocaleData } from '@theme/useThemeData';
import { computed } from 'vue';
import { usePageData, usePageFrontmatter } from 'vuepress/client';
import { resolveEditLink } from '../utils/index.js';
export const useEditLink = () => {
const themeLocale = useThemeLocaleData();
const page = usePageData();
const frontmatter = usePageFrontmatter();
return computed(() => {
const showEditLink = frontmatter.value.editLink ?? themeLocale.value.editLink ?? true;
if (!showEditLink) {
return null;
}
const { repo, docsRepo = repo, docsBranch = 'main', docsDir = '', editLinkText, } = themeLocale.value;
if (!docsRepo)
return null;
const editLink = resolveEditLink({
docsRepo,
docsBranch,
docsDir,
filePathRelative: page.value.filePathRelative,
editLinkPattern: frontmatter.value.editLinkPattern ?? themeLocale.value.editLinkPattern,
});
if (!editLink)
return null;
return {
text: editLinkText ?? 'Edit this page',
link: editLink,
};
});
};