--- // import { // getCollection, // type CollectionEntry, // type CollectionKey, // } from "astro:content"; // export const getSinglePage = async ( // collectionName: C, // ): Promise[]> => { // const allPages = await getCollection(collectionName); // const removeIndex = allPages.filter((data) => data.id.match(/^(?!-)/)); // const removeDrafts = removeIndex.filter((data) => !data.data.draft); // return removeDrafts; // }; import { getCollection, type CollectionEntry, type CollectionKey, type ContentEntryMap, } from "astro:content"; import config from "@/config/config.json"; export const getSinglePage = async ( collectionName: C, lang: keyof ContentEntryMap ): Promise[]> => { const { defaultLang } = config.language; const langCollection: keyof ContentEntryMap = lang as keyof ContentEntryMap; // Explicitly define the type of pages to CollectionEntry[] const pages: CollectionEntry[] = await getCollection(langCollection || defaultLang, ({ id }) => { return id.startsWith(collectionName) && !id.endsWith("-index.md"); }) as CollectionEntry[]; const removeDrafts = pages.filter((data) => !data.data.draft); return removeDrafts; }; export const getListPage = async ( collectionName: C, lang: keyof ContentEntryMap ): Promise[]> => { const { defaultLang } = config.language; const langCollection: keyof ContentEntryMap = lang as keyof ContentEntryMap; // Fetch the collection based on the language const pages: CollectionEntry[] = await getCollection(langCollection || defaultLang, ({ id }) => { return id.startsWith(collectionName); }) as CollectionEntry[]; return pages; }; ---