mirror of
https://github.com/10h30/astroplate.git
synced 2026-07-12 03:06:14 +09:00
45 lines
927 B
Plaintext
45 lines
927 B
Plaintext
---
|
|
import {
|
|
getCollection,
|
|
getEntry,
|
|
type CollectionEntry,
|
|
type CollectionKey,
|
|
} from "astro:content";
|
|
|
|
type PageData = {
|
|
title: string;
|
|
meta_title?: string;
|
|
description?: string;
|
|
image?: string;
|
|
draft?: boolean;
|
|
};
|
|
|
|
export const getSinglePage = async <C extends CollectionKey>(
|
|
collectionName: C
|
|
): Promise<CollectionEntry<C>[]> => {
|
|
const allPages = await getCollection(
|
|
collectionName,
|
|
({ data, id }) => !(data as PageData)?.draft && !id.startsWith("-")
|
|
);
|
|
return allPages;
|
|
};
|
|
|
|
export const getListPage = async <C extends CollectionKey>(
|
|
collectionName: C,
|
|
documentId: "-index" | string
|
|
): Promise<CollectionEntry<C>> => {
|
|
const data = (await getEntry(
|
|
collectionName,
|
|
documentId
|
|
)) as CollectionEntry<C> | null;
|
|
|
|
if (!data) {
|
|
throw new Error(
|
|
`No page found for the collection: ${collectionName} with filename: ${documentId}`
|
|
);
|
|
}
|
|
|
|
return data;
|
|
};
|
|
---
|