config ln array changed

This commit is contained in:
Al Murad Uzzaman
2024-05-16 17:11:25 +06:00
parent 97d6f22dcb
commit c137b8afcd
24 changed files with 200 additions and 362 deletions
+12 -22
View File
@@ -1,19 +1,4 @@
---
// import {
// getCollection,
// type CollectionEntry,
// type CollectionKey,
// } from "astro:content";
// export const getSinglePage = async <C extends CollectionKey>(
// collectionName: C,
// ): Promise<CollectionEntry<C>[]> => {
// 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,
@@ -31,15 +16,17 @@ export const getSinglePage = async <C extends CollectionKey>(
const langCollection: keyof ContentEntryMap = lang as keyof ContentEntryMap;
// Explicitly define the type of pages to CollectionEntry<C>[]
const pages: CollectionEntry<C>[] = await getCollection(langCollection || defaultLang, ({ id }) => {
return id.startsWith(collectionName) && !id.endsWith("-index.md");
}) as CollectionEntry<C>[];
const pages: CollectionEntry<C>[] = (await getCollection(
langCollection || defaultLang,
({ id }: any) => {
return id.startsWith(collectionName) && !id.endsWith("-index.md");
}
)) as CollectionEntry<C>[];
const removeDrafts = pages.filter((data) => !data.data.draft);
return removeDrafts;
};
export const getListPage = async <C extends CollectionKey>(
collectionName: C,
lang: keyof ContentEntryMap
@@ -47,9 +34,12 @@ export const getListPage = async <C extends CollectionKey>(
const { defaultLang } = config.language;
const langCollection: keyof ContentEntryMap = lang as keyof ContentEntryMap;
// Fetch the collection based on the language
const pages: CollectionEntry<C>[] = await getCollection(langCollection || defaultLang, ({ id }) => {
return id.startsWith(collectionName);
}) as CollectionEntry<C>[];
const pages: CollectionEntry<C>[] = (await getCollection(
langCollection || defaultLang,
({ id }: any) => {
return id.startsWith(collectionName);
}
)) as CollectionEntry<C>[];
return pages;
};