content folder name chanded && fn added

This commit is contained in:
Al Murad Uzzaman
2024-05-18 22:20:40 +06:00
parent 76f1b5b6c1
commit 742c67c3d5
9 changed files with 87 additions and 86 deletions
+13 -37
View File
@@ -7,32 +7,19 @@ import {
} from "astro:content";
import config from "@/config/config.json";
import languages from "@/config/language.json";
export const getSinglePage = async <C extends CollectionKey>(
collectionName: C,
lang: keyof ContentEntryMap
lang: keyof ContentEntryMap | undefined,
): Promise<CollectionEntry<C>[]> => {
const { default_language } = config.settings;
const langCollection: keyof ContentEntryMap = lang as keyof ContentEntryMap;
const languages = [
{
languageName: "En",
languageCode: "en",
contentDir: "english",
weight: 1,
},
{
languageName: "Fr",
languageCode: "fr",
contentDir: "french",
weight: 2,
},
];
// If lang is undefined, use the default language
const selectedLanguageCode = lang || default_language;
const language = languages.find(
(l) =>
l.languageCode === langCollection || l.languageCode === default_language
(l: any) => l.languageCode === selectedLanguageCode,
);
if (!language) {
@@ -46,37 +33,26 @@ export const getSinglePage = async <C extends CollectionKey>(
contentDir as any,
({ id }: any) => {
return id.startsWith(collectionName) && !id.endsWith("-index.md");
}
},
)) as CollectionEntry<C>[];
//@ts-ignore
// @ts-ignore
const removeDrafts = pages.filter((data) => !data.data.draft);
return removeDrafts;
};
export const getListPage = async <C extends CollectionKey>(
collectionName: C,
lang: keyof ContentEntryMap
lang: keyof ContentEntryMap | undefined,
): Promise<CollectionEntry<C>[]> => {
const { default_language } = config.settings;
const languages = [
{
languageName: "En",
languageCode: "en",
contentDir: "english",
weight: 1,
},
{
languageName: "Fr",
languageCode: "fr",
contentDir: "french",
weight: 2,
},
];
// If lang is undefined, use the default language
const selectedLanguageCode = lang || default_language;
const language = languages.find(
(l) => l.languageCode == lang || l.languageCode == default_language
(l: any) => l.languageCode == selectedLanguageCode,
);
if (!language) {
@@ -90,7 +66,7 @@ export const getListPage = async <C extends CollectionKey>(
contentDir as any,
({ id }: any) => {
return id.startsWith(collectionName);
}
},
)) as CollectionEntry<C>[];
return pages;
+34 -8
View File
@@ -1,20 +1,33 @@
---
import config from "@/config/config.json";
import languages from "@/config/language.json";
import { slugify } from "@/lib/utils/textConverter";
import type { ContentEntryMap } from "astro:content";
import { getCollection } from "astro:content";
// get taxonomy from frontmatter
export const getTaxonomy = async (collection: any, name: string) => {
export const getTaxonomy = async (collection: string, name: string) => {
const { default_language } = config.settings;
const actualCollection =
collection !== ("" || undefined) ? collection : default_language;
const language = languages.find((l) => l.languageCode === collection);
let actualCollection = default_language;
if (language) {
actualCollection = language.contentDir;
} else {
const defaultLanguageMatch = languages.find(
(l) => l.languageCode === default_language,
);
if (defaultLanguageMatch) {
actualCollection = defaultLanguageMatch.contentDir;
}
}
const singlePages = await getCollection(
actualCollection as keyof ContentEntryMap,
({ id }: any) => {
return id.startsWith("blog") && !id.endsWith("-index.md");
}
},
);
const taxonomyPages = singlePages.map((page: any) => page.data[name]);
let taxonomies: string[] = [];
@@ -29,15 +42,28 @@ export const getTaxonomy = async (collection: any, name: string) => {
};
// get all taxonomies from frontmatter
export const getAllTaxonomy = async (collection: any, name: string) => {
export const getAllTaxonomy = async (collection: string, name: string) => {
const { default_language } = config.settings;
const actualCollection =
collection !== ("" || undefined) ? collection : default_language;
const language = languages.find((l) => l.languageCode === collection);
let actualCollection = default_language;
if (language) {
actualCollection = language.contentDir;
} else {
const defaultLanguageMatch = languages.find(
(l) => l.languageCode === default_language,
);
if (defaultLanguageMatch) {
actualCollection = defaultLanguageMatch.contentDir;
}
}
const singlePages = await getCollection(
actualCollection as keyof ContentEntryMap,
({ id }: any) => {
return id.startsWith("blog") && !id.endsWith("-index.md");
}
},
);
const taxonomyPages = singlePages.map((page: any) => page.data[name]);
let taxonomies: string[] = [];