mirror of
https://github.com/10h30/astroplate.git
synced 2026-06-05 15:08:00 +09:00
content folder name chanded && fn added
This commit is contained in:
@@ -4,9 +4,9 @@ meta_title: ""
|
||||
description: "Ceci est une méta-description"
|
||||
date: 2022-04-04T05:00:00Z
|
||||
image: "/images/image-placeholder.png"
|
||||
categories: ["Application", "Data"]
|
||||
categories: ["french","Application", "Data"]
|
||||
author: "John Doe"
|
||||
tags: ["nextjs", "tailwind"]
|
||||
tags: ["nextjs", "tailwind", "react"]
|
||||
draft: false
|
||||
---
|
||||
|
||||
|
||||
+13
-37
@@ -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;
|
||||
|
||||
@@ -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[] = [];
|
||||
|
||||
@@ -4,8 +4,7 @@ import Base from "@/layouts/Base.astro";
|
||||
import { getListPage } from "@/lib/contentParser.astro";
|
||||
import { supportedLang } from "@/lib/utils/i18nUtils";
|
||||
import { markdownify } from "@/lib/utils/textConverter";
|
||||
import type { ContentEntryMap } from "astro:content";
|
||||
import type { ContentCollectionKey } from "astro:content";
|
||||
import type { ContentCollectionKey, ContentEntryMap } from "astro:content";
|
||||
|
||||
export function getStaticPaths() {
|
||||
const paths = supportedLang.map((lang) => ({
|
||||
@@ -17,11 +16,9 @@ export function getStaticPaths() {
|
||||
const { lang } = Astro.params;
|
||||
const about: any = await getListPage(
|
||||
"about" as ContentCollectionKey,
|
||||
lang as keyof ContentEntryMap
|
||||
lang as keyof ContentEntryMap,
|
||||
);
|
||||
|
||||
console.log(about);
|
||||
|
||||
const { Content } = await about[0].render();
|
||||
const { title, description, meta_title, image } = about[0].data;
|
||||
---
|
||||
|
||||
@@ -3,6 +3,7 @@ import BlogCard from "@/components/BlogCard.astro";
|
||||
import Pagination from "@/components/Pagination.astro";
|
||||
import config from "@/config/config.json";
|
||||
import Base from "@/layouts/Base.astro";
|
||||
import { getListPage, getSinglePage } from "@/lib/contentParser.astro";
|
||||
import { getAllTaxonomy, getTaxonomy } from "@/lib/taxonomyParser.astro";
|
||||
import { supportedLang } from "@/lib/utils/i18nUtils";
|
||||
import { sortByDate } from "@/lib/utils/sortFunctions";
|
||||
@@ -14,24 +15,20 @@ const BLOG_FOLDER = "blog";
|
||||
|
||||
const { slug, lang } = Astro.params;
|
||||
|
||||
const postIndex: any = await getCollection(
|
||||
const postIndex: any = await getListPage(
|
||||
BLOG_FOLDER,
|
||||
lang as keyof ContentEntryMap,
|
||||
({ id }: any) => {
|
||||
return id.startsWith(BLOG_FOLDER);
|
||||
},
|
||||
);
|
||||
|
||||
const posts = await getCollection(
|
||||
const posts = await getSinglePage(BLOG_FOLDER, lang as keyof ContentEntryMap);
|
||||
const allCategories = await getAllTaxonomy(
|
||||
lang as keyof ContentEntryMap,
|
||||
({ id }: any) => {
|
||||
return id.startsWith(BLOG_FOLDER) && !id.endsWith("-index.md");
|
||||
},
|
||||
"categories",
|
||||
);
|
||||
|
||||
const langCollection: keyof ContentEntryMap = lang as keyof ContentEntryMap;
|
||||
const allCategories = await getAllTaxonomy(langCollection, "categories");
|
||||
const categories = await getTaxonomy(langCollection, "categories");
|
||||
const tags = await getTaxonomy(langCollection, "tags");
|
||||
const categories = await getTaxonomy(
|
||||
lang as keyof ContentEntryMap,
|
||||
"categories",
|
||||
);
|
||||
const tags = await getTaxonomy(lang as keyof ContentEntryMap, "tags");
|
||||
const sortedPosts = sortByDate(posts);
|
||||
const totalPages = Math.ceil(posts.length / config.settings.pagination);
|
||||
const currentPage = slug && !isNaN(Number(slug)) ? Number(slug) : 1;
|
||||
|
||||
@@ -16,7 +16,10 @@ export async function getStaticPaths() {
|
||||
|
||||
const paths = await Promise.all(
|
||||
supportedLang.map(async (lang) => {
|
||||
const categories = await getTaxonomy(lang, "categories");
|
||||
const categories = await getTaxonomy(
|
||||
lang as keyof ContentEntryMap,
|
||||
"categories",
|
||||
);
|
||||
|
||||
return categories.map((category) => ({
|
||||
params: {
|
||||
@@ -27,11 +30,14 @@ export async function getStaticPaths() {
|
||||
category,
|
||||
},
|
||||
}));
|
||||
})
|
||||
}),
|
||||
);
|
||||
|
||||
// Handle default path (no lang)
|
||||
const defaultCategories = await getTaxonomy(default_language, "categories");
|
||||
const defaultCategories = await getTaxonomy(
|
||||
default_language as keyof ContentEntryMap,
|
||||
"categories",
|
||||
);
|
||||
const defaultPaths = defaultCategories.map((category) => ({
|
||||
params: {
|
||||
lang: undefined,
|
||||
|
||||
@@ -2,14 +2,13 @@
|
||||
import ImageMod from "@/components/ImageMod.astro";
|
||||
import config from "@/config/config.json";
|
||||
import Base from "@/layouts/Base.astro";
|
||||
import { getListPage } from "@/lib/contentParser.astro";
|
||||
import { getListPage, getSinglePage } from "@/lib/contentParser.astro";
|
||||
import { supportedLang } from "@/lib/utils/i18nUtils";
|
||||
import { markdownify } from "@/lib/utils/textConverter";
|
||||
import CallToAction from "@/partials/CallToAction.astro";
|
||||
import Testimonial from "@/partials/Testimonial.astro";
|
||||
import type { Button, Feature } from "@/types";
|
||||
import type { ContentCollectionKey, ContentEntryMap } from "astro:content";
|
||||
import { getCollection } from "astro:content";
|
||||
import { FaCheck } from "react-icons/fa";
|
||||
const { default_language } = config.settings;
|
||||
|
||||
@@ -37,19 +36,14 @@ const homepage: any = await getListPage(
|
||||
);
|
||||
const { banner, features } = homepage[0].data;
|
||||
|
||||
const testimonial = await getCollection(
|
||||
(lang as keyof ContentEntryMap) || default_language,
|
||||
({ id }: any) => {
|
||||
return id.startsWith("sections/testimonial") && !id.endsWith("-index.md");
|
||||
},
|
||||
const testimonial = await getSinglePage(
|
||||
"sections/testimonial" as ContentCollectionKey,
|
||||
lang as keyof ContentEntryMap,
|
||||
);
|
||||
const call_to_action = await getCollection(
|
||||
(lang as keyof ContentEntryMap) || default_language,
|
||||
({ id }: any) => {
|
||||
return (
|
||||
id.startsWith("sections/call-to-action") && !id.endsWith("-index.md")
|
||||
);
|
||||
},
|
||||
|
||||
const call_to_action = await getSinglePage(
|
||||
"sections/call-to-action" as ContentCollectionKey,
|
||||
lang as keyof ContentEntryMap,
|
||||
);
|
||||
---
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ export async function getStaticPaths() {
|
||||
|
||||
const paths = await Promise.all(
|
||||
supportedLang.map(async (lang) => {
|
||||
const tags = await getTaxonomy(lang, "tags");
|
||||
const tags = await getTaxonomy(lang as keyof ContentEntryMap, "tags");
|
||||
|
||||
return tags.map((tag) => ({
|
||||
params: {
|
||||
@@ -27,11 +27,14 @@ export async function getStaticPaths() {
|
||||
tag,
|
||||
},
|
||||
}));
|
||||
})
|
||||
}),
|
||||
);
|
||||
|
||||
// Handle default path (no lang)
|
||||
const defaultCategories = await getTaxonomy(default_language, "tags");
|
||||
const defaultCategories = await getTaxonomy(
|
||||
default_language as keyof ContentEntryMap,
|
||||
"tags",
|
||||
);
|
||||
const defaultPaths = defaultCategories.map((tag) => ({
|
||||
params: {
|
||||
lang: undefined,
|
||||
|
||||
Vendored
+2
@@ -1,3 +1,5 @@
|
||||
import type { ContentEntryMap } from "astro:content";
|
||||
|
||||
export type Feature = {
|
||||
button: button;
|
||||
image: string;
|
||||
|
||||
Reference in New Issue
Block a user