2023-04-17 12:50:29 +06:00
|
|
|
---
|
2023-12-03 15:28:12 +06:00
|
|
|
import { getCollection } from "astro:content";
|
2023-04-17 12:50:29 +06:00
|
|
|
import { slugify } from "./utils/textConverter";
|
|
|
|
|
|
2023-12-03 15:28:12 +06:00
|
|
|
// 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;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// get taxonomy from frontmatter
|
2023-04-17 12:50:29 +06:00
|
|
|
export const getTaxonomy = async (collection: string, name: string) => {
|
|
|
|
|
const singlePages = await getSinglePage(collection);
|
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-04-17 12:50:29 +06:00
|
|
|
export const getAllTaxonomy = async (collection: string, name: string) => {
|
|
|
|
|
const singlePages = await getSinglePage(collection);
|
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;
|
|
|
|
|
};
|
|
|
|
|
---
|