--- 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 ( collectionName: C, lang: keyof ContentEntryMap | undefined ): Promise[]> => { 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[] = (await getCollection( contentDir as any, ({ id }: any) => { return id.startsWith(collectionName) && !id.endsWith("-index.md"); } )) as CollectionEntry[]; // @ts-ignore const removeDrafts = pages.filter((data) => !data.data.draft); return removeDrafts; }; export const getLP = async ( collectionName: C, lang: keyof ContentEntryMap | undefined ): Promise[]> => { 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[] = (await getCollection( contentDir as any, ({ id }: any) => { return id.startsWith(collectionName); } )) as CollectionEntry[]; return pages; }; export const getSinglePage = async ( collectionName: C, lang: keyof ContentEntryMap | undefined, subCollectionName?: string ): Promise[]> => { 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[] = (await getCollection( collectionName as any, ({ id }: any) => { return id.startsWith(path) && !id.endsWith("-index.md"); } )) as CollectionEntry[]; // @ts-ignore const removeDrafts = pages.filter((data) => !data.data.draft); return removeDrafts; }; export const getListPage = async ( collectionName: C, lang: keyof ContentEntryMap | undefined ): Promise[]> => { 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[] = (await getCollection( collectionName as any, ({ id }: any) => { return id.startsWith(contentDir); } )) as CollectionEntry[]; return pages; }; ---