feat: some shit
This commit is contained in:
@ -1,18 +1,15 @@
|
||||
import { defaultLocale, getLocale } from 'astro-i18n-aut';
|
||||
import { ui, defaultLang, showDefaultLang } from './ui';
|
||||
import type { AstroGlobal } from 'astro';
|
||||
|
||||
|
||||
export function useTranslatedPath(astro: AstroGlobal) {
|
||||
const locale = getLocale(astro.url);
|
||||
export function useTranslatedPath(url: URL) {
|
||||
const locale = getLocale(url);
|
||||
return function translatePath(path: string, l: string = locale) {
|
||||
return !showDefaultLang && l === defaultLang ? path : `/${l}${path}`.replace(/\/$/g, '');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export function useTranslations(astro: AstroGlobal) {
|
||||
const lang = getLocale(astro.url);
|
||||
export function useTranslations(url: URL) {
|
||||
const lang = getLocale(url);
|
||||
return function t(key: keyof typeof ui[typeof defaultLang]) {
|
||||
return ui[lang as keyof typeof ui][key] || ui[defaultLang][key];
|
||||
}
|
||||
@ -25,11 +22,11 @@ export function parseSlug(id: string) {
|
||||
return [splitPath.join("/"), lang]
|
||||
}
|
||||
|
||||
export function filterCollection<T extends { id: string }>(collection: T[], locale: string): T[] {
|
||||
export function filterCollection<T extends { id: string, data: { date: Date } }>(collection: T[], locale: string): T[] {
|
||||
return collection.filter(post => {
|
||||
const [_, lang] = parseSlug(post?.id);
|
||||
return lang === locale;
|
||||
}).sort((a, b) => {
|
||||
return a.data.date > b.data.date ? -1 : 1;
|
||||
return (a?.data?.date > b?.data?.date) ? -1 : 1;
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user