Files
astroplate/src/lib/taxonomyParser.astro
T

33 lines
1.1 KiB
Plaintext
Raw Normal View History

2023-04-17 12:50:29 +06:00
---
import { getSinglePage } from "./contentParser.astro";
import { slugify } from "./utils/textConverter";
// get all taxonomies from frontmatter
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;
};
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;
};
---