Vitepress

This commit is contained in:
Robert Jelic
2025-02-10 06:53:23 +01:00
parent 3818128521
commit b0a4a6da9c
2428 changed files with 1005324 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
import { computed } from 'vue';
import { useData } from './data';
import { ensureStartingSlash } from '../support/utils';
export function useLangs({ removeCurrent = true, correspondingLink = false } = {}) {
const { site, localeIndex, page, theme } = useData();
const currentLang = computed(() => ({
label: site.value.locales[localeIndex.value]?.label,
link: site.value.locales[localeIndex.value]?.link ||
(localeIndex.value === 'root' ? '/' : `/${localeIndex.value}/`)
}));
const localeLinks = computed(() => Object.entries(site.value.locales).flatMap(([key, value]) => removeCurrent && currentLang.value.label === value.label
? []
: {
text: value.label,
link: normalizeLink(value.link || (key === 'root' ? '/' : `/${key}/`), theme.value.i18nRouting !== false && correspondingLink, page.value.relativePath.slice(currentLang.value.link.length - 1), !site.value.cleanUrls)
}));
return { localeLinks, currentLang };
}
function normalizeLink(link, addPath, path, addExt) {
return addPath
? link.replace(/\/$/, '') +
ensureStartingSlash(path
.replace(/(^|\/)index\.md$/, '$1')
.replace(/\.md$/, addExt ? '.html' : ''))
: link;
}