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

39 lines
1.2 KiB
JavaScript

import { useThemeLocaleData } from '@theme/useThemeData';
import { computed } from 'vue';
import { isLinkHttp } from 'vuepress/shared';
import { resolveRepoType } from '../utils/index.js';
/**
* Get navbar config of repository link
*/
export const useNavbarRepo = () => {
const themeLocale = useThemeLocaleData();
const repo = computed(() => themeLocale.value.repo);
const repoType = computed(() => repo.value ? resolveRepoType(repo.value) : null);
const repoLink = computed(() => {
if (repo.value && !isLinkHttp(repo.value)) {
return `https://github.com/${repo.value}`;
}
return repo.value;
});
const repoLabel = computed(() => {
if (!repoLink.value)
return null;
if (themeLocale.value.repoLabel)
return themeLocale.value.repoLabel;
if (repoType.value === null)
return 'Source';
return repoType.value;
});
return computed(() => {
if (!repoLink.value || !repoLabel.value) {
return [];
}
return [
{
text: repoLabel.value,
link: repoLink.value,
},
];
});
};