mirror of
https://github.com/10h30/astroplate.git
synced 2026-07-15 12:43:27 +09:00
remove multilingual and create a new multilingual branch
This commit is contained in:
+3
-121
@@ -3,132 +3,14 @@ import {
|
||||
getCollection,
|
||||
type CollectionEntry,
|
||||
type CollectionKey,
|
||||
type ContentEntryMap,
|
||||
} from "astro:content";
|
||||
|
||||
import config from "@/config/config.json";
|
||||
import languages from "@/config/language.json";
|
||||
|
||||
export const getSP = async <C extends CollectionKey>(
|
||||
collectionName: C,
|
||||
lang: keyof ContentEntryMap | undefined
|
||||
): Promise<CollectionEntry<C>[]> => {
|
||||
const { default_language } = config.settings;
|
||||
|
||||
const selectedLanguageCode = lang || default_language;
|
||||
|
||||
const language = languages.find(
|
||||
(l: any) => l.languageCode === selectedLanguageCode
|
||||
);
|
||||
|
||||
if (!language) {
|
||||
throw new Error("Language not found");
|
||||
}
|
||||
|
||||
const { contentDir } = language;
|
||||
|
||||
const pages: CollectionEntry<C>[] = (await getCollection(
|
||||
contentDir as any,
|
||||
({ id }: any) => {
|
||||
return id.startsWith(collectionName) && !id.endsWith("-index.md");
|
||||
}
|
||||
)) as CollectionEntry<C>[];
|
||||
|
||||
// @ts-ignore
|
||||
const removeDrafts = pages.filter((data) => !data.data.draft);
|
||||
|
||||
return removeDrafts;
|
||||
};
|
||||
|
||||
export const getLP = async <C extends CollectionKey>(
|
||||
collectionName: C,
|
||||
lang: keyof ContentEntryMap | undefined
|
||||
): Promise<CollectionEntry<C>[]> => {
|
||||
const { default_language } = config.settings;
|
||||
|
||||
const selectedLanguageCode = lang || default_language;
|
||||
|
||||
const language = languages.find(
|
||||
(l: any) => l.languageCode == selectedLanguageCode
|
||||
);
|
||||
|
||||
if (!language) {
|
||||
throw new Error("Language not found");
|
||||
}
|
||||
|
||||
const { contentDir } = language;
|
||||
|
||||
const pages: CollectionEntry<C>[] = (await getCollection(
|
||||
contentDir as any,
|
||||
({ id }: any) => {
|
||||
return id.startsWith(collectionName);
|
||||
}
|
||||
)) as CollectionEntry<C>[];
|
||||
|
||||
return pages;
|
||||
};
|
||||
|
||||
export const getSinglePage = async <C extends CollectionKey>(
|
||||
collectionName: C,
|
||||
lang: keyof ContentEntryMap | undefined,
|
||||
subCollectionName?: string
|
||||
): Promise<CollectionEntry<C>[]> => {
|
||||
const { default_language } = config.settings;
|
||||
|
||||
const selectedLanguageCode = lang || default_language;
|
||||
|
||||
const language = languages.find(
|
||||
(l: any) => l.languageCode === selectedLanguageCode
|
||||
);
|
||||
|
||||
if (!language) {
|
||||
throw new Error("Language not found");
|
||||
}
|
||||
|
||||
const { contentDir } = language;
|
||||
|
||||
const path = subCollectionName
|
||||
? `${contentDir}/${subCollectionName}`
|
||||
: contentDir;
|
||||
|
||||
const pages: CollectionEntry<C>[] = (await getCollection(
|
||||
collectionName as any,
|
||||
({ id }: any) => {
|
||||
return id.startsWith(path) && !id.endsWith("-index.md");
|
||||
}
|
||||
)) as CollectionEntry<C>[];
|
||||
|
||||
// @ts-ignore
|
||||
const removeDrafts = pages.filter((data) => !data.data.draft);
|
||||
|
||||
const allPages = await getCollection(collectionName);
|
||||
const removeIndex = allPages.filter((data) => data.id.match(/^(?!-)/));
|
||||
const removeDrafts = removeIndex.filter((data) => !data.data.draft);
|
||||
return removeDrafts;
|
||||
};
|
||||
|
||||
export const getListPage = async <C extends CollectionKey>(
|
||||
collectionName: C,
|
||||
lang: keyof ContentEntryMap | undefined
|
||||
): Promise<CollectionEntry<C>[]> => {
|
||||
const { default_language } = config.settings;
|
||||
|
||||
const selectedLanguageCode = lang || default_language;
|
||||
|
||||
const language = languages.find(
|
||||
(l: any) => l.languageCode == selectedLanguageCode
|
||||
);
|
||||
|
||||
if (!language) {
|
||||
throw new Error("Language not found");
|
||||
}
|
||||
|
||||
const { contentDir } = language;
|
||||
|
||||
const pages: CollectionEntry<C>[] = (await getCollection(
|
||||
collectionName as any,
|
||||
({ id }: any) => {
|
||||
return id.startsWith(contentDir);
|
||||
}
|
||||
)) as CollectionEntry<C>[];
|
||||
|
||||
return pages;
|
||||
};
|
||||
---
|
||||
|
||||
Reference in New Issue
Block a user