mirror of
https://github.com/10h30/astroplate.git
synced 2026-07-18 06:03:27 +09:00
added contentParser with type support
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
---
|
||||
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;
|
||||
};
|
||||
---
|
||||
@@ -1,17 +1,9 @@
|
||||
---
|
||||
import { getCollection } from "astro:content";
|
||||
import { slugify } from "./utils/textConverter";
|
||||
|
||||
// get all pages from collection
|
||||
export const getSinglePage = async (collection: any) => {
|
||||
const allPage = await getCollection(collection);
|
||||
const removeIndex = allPage.filter((data: any) => data.id.match(/^(?!-)/));
|
||||
const removeDrafts = removeIndex.filter((data: any) => !data.data.draft);
|
||||
return removeDrafts;
|
||||
};
|
||||
import { getSinglePage } from "@/lib/contentParser.astro";
|
||||
import { slugify } from "@/lib/utils/textConverter";
|
||||
|
||||
// get taxonomy from frontmatter
|
||||
export const getTaxonomy = async (collection: string, name: string) => {
|
||||
export const getTaxonomy = async (collection: any, name: string) => {
|
||||
const singlePages = await getSinglePage(collection);
|
||||
const taxonomyPages = singlePages.map((page: any) => page.data[name]);
|
||||
let taxonomies: string[] = [];
|
||||
@@ -26,7 +18,7 @@ export const getTaxonomy = async (collection: string, name: string) => {
|
||||
};
|
||||
|
||||
// get all taxonomies from frontmatter
|
||||
export const getAllTaxonomy = async (collection: string, name: string) => {
|
||||
export const getAllTaxonomy = async (collection: any, name: string) => {
|
||||
const singlePages = await getSinglePage(collection);
|
||||
const taxonomyPages = singlePages.map((page: any) => page.data[name]);
|
||||
let taxonomies: string[] = [];
|
||||
|
||||
Reference in New Issue
Block a user