Files
astroplate/src/lib/taxonomyParser.astro
T

49 lines
1.6 KiB
Plaintext
Raw Normal View History

2023-04-17 12:50:29 +06:00
---
2023-12-09 11:14:43 +06:00
import { getSinglePage } from "@/lib/contentParser.astro";
import { slugify } from "@/lib/utils/textConverter";
2024-05-14 15:34:22 +06:00
import type { ContentEntryMap } from "astro:content";
import { getCollection } from "astro:content";
2023-12-03 15:28:12 +06:00
// get taxonomy from frontmatter
2023-12-09 11:14:43 +06:00
export const getTaxonomy = async (collection: any, name: string) => {
2024-05-14 15:34:22 +06:00
// const singlePages = await getSinglePage(collection);
const singlePages = await getCollection(
collection as keyof ContentEntryMap,
({ id }) => {
return id.startsWith("blog") && !id.endsWith("-index.md");
}
);
2023-08-19 09:05:26 +06:00
const taxonomyPages = singlePages.map((page: any) => page.data[name]);
2023-05-21 11:42:20 +06:00
let taxonomies: string[] = [];
2023-04-17 12:50:29 +06:00
for (let i = 0; i < taxonomyPages.length; i++) {
const categoryArray = taxonomyPages[i];
for (let j = 0; j < categoryArray.length; j++) {
taxonomies.push(slugify(categoryArray[j]));
}
}
const taxonomy = [...new Set(taxonomies)];
return taxonomy;
};
2023-12-03 15:28:12 +06:00
// get all taxonomies from frontmatter
2023-12-09 11:14:43 +06:00
export const getAllTaxonomy = async (collection: any, name: string) => {
2024-05-14 15:34:22 +06:00
// const singlePages = await getSinglePage(collection);
const singlePages = await getCollection(
collection as keyof ContentEntryMap,
({ id }) => {
return id.startsWith("blog") && !id.endsWith("-index.md");
}
);
2023-08-19 09:05:26 +06:00
const taxonomyPages = singlePages.map((page: any) => page.data[name]);
2023-05-21 11:42:20 +06:00
let taxonomies: string[] = [];
2023-04-17 12:50:29 +06:00
for (let i = 0; i < taxonomyPages.length; i++) {
const categoryArray = taxonomyPages[i];
for (let j = 0; j < categoryArray.length; j++) {
taxonomies.push(slugify(categoryArray[j]));
}
}
return taxonomies;
};
---