config ln array changed

This commit is contained in:
Al Murad Uzzaman
2024-05-16 17:11:25 +06:00
parent 97d6f22dcb
commit c137b8afcd
24 changed files with 200 additions and 362 deletions
+3 -3
View File
@@ -13,8 +13,7 @@
}, },
"language": { "language": {
"defaultLang": "en", "defaultLang": "en"
"supported": ["", "en", "fr", "ar"]
}, },
"settings": { "settings": {
@@ -24,7 +23,8 @@
"default_theme": "system", "default_theme": "system",
"pagination": 2, "pagination": 2,
"summary_length": 200, "summary_length": 200,
"blog_folder": "blog" "blog_folder": "blog",
"default_language": "en"
}, },
"params": { "params": {
+17 -42
View File
@@ -1,42 +1,17 @@
[ {
{ "full_name": "الاسم الكامل",
"id": "get_started", "full_name_placeholder": "أدخل اسمك الكامل",
"translation": "البدء" "mail": "البريد الإلكتروني العملي",
}, "mail_placeholder": "john.doe@email.com",
{ "message": "هل هناك شيء آخر؟",
"id": "read_more", "message_placeholder": "رسالتك هنا...",
"translation": "Read More" "submit": "إرسال",
}, "read_more": "اقرأ المزيد",
{ "page_not_found": "الصفحة غير موجودة",
"id": "full_name", "working_mail": "البريد الإلكتروني العملي",
"translation": "الاسم الكامل" "anything_else": "هل هناك شيء آخر؟",
}, "contact_message_placeholder": "رسالتك هنا...",
{ "page_not_found_content": "قد تمت إزالة الصفحة التي تبحث عنها، أو تغيير اسمها، أو أصبحت غير متوفرة مؤقتًا.",
"id": "working_mail", "back_to_home": "العودة إلى الصفحة الرئيسية",
"translation": "بريد العمل" "get_started": "البدئة"
}, }
{
"id": "anything_else",
"translation": "أي شيء آخر؟"
},
{
"id": "contact_message_placeholder",
"translation": "الرسالة تذهب هنا..."
},
{
"id": "submit",
"translation": "يُقدِّم"
},
{
"id": "page_not_found",
"translation": "الصفحة غير موجودة"
},
{
"id": "page_not_found_content",
"translation": "ربما تمت إزالة الصفحة التي تبحث عنها، أو تم تغيير اسمها، أو أنها غير متاحة مؤقتًا."
},
{
"id": "back_to_home",
"translation": "العودة إلى المنزل"
}
]
+17 -42
View File
@@ -1,42 +1,17 @@
[ {
{ "full_name": "Full Name",
"id": "get_started", "full_name_placeholder": "Enter your full name",
"translation": "Get Started" "mail": "Work Email",
}, "mail_placeholder": "john.doe@email.com",
{ "message": "Anything else?",
"id": "read_more", "message_placeholder": "Your message here...",
"translation": "Read More" "submit": "Submit",
}, "read_more": "Read More",
{ "page_not_found": "Page Not Found",
"id": "full_name", "working_mail": "Work Email",
"translation": "Full Name" "anything_else": "Anything else?",
}, "contact_message_placeholder": "Your message here...",
{ "page_not_found_content": "The page you are looking for may have been removed, renamed, or is temporarily unavailable.",
"id": "working_mail", "back_to_home": "Back to Home",
"translation": "Working Mail" "get_started": "Get Started"
}, }
{
"id": "anything_else",
"translation": "Anything else?"
},
{
"id": "contact_message_placeholder",
"translation": "Message goes here..."
},
{
"id": "submit",
"translation": "Submit"
},
{
"id": "page_not_found",
"translation": "Page Not Found"
},
{
"id": "page_not_found_content",
"translation": "The page you are looking for might have been removed, had its name changed, or is temporarily unavailable."
},
{
"id": "back_to_home",
"translation": "Back to home"
}
]
+17 -42
View File
@@ -1,42 +1,17 @@
[ {
{ "full_name": "Nom complet",
"id": "get_started", "full_name_placeholder": "Entrez votre nom complet",
"translation": "Commencer" "mail": "E-mail de travail",
}, "mail_placeholder": "john.doe@email.com",
{ "message": "Autre chose?",
"id": "read_more", "message_placeholder": "Votre message ici...",
"translation": "Read More" "submit": "Soumettre",
}, "read_more": "Lire la suite",
{ "page_not_found": "Page non trouvée",
"id": "full_name", "working_mail": "Courrier de travail",
"translation": "Nom et prénom" "anything_else": "Autre chose ?",
}, "contact_message_placeholder": "Votre message ici...",
{ "page_not_found_content": "La page que vous recherchez a peut-être été supprimée, changée de nom ou temporairement inaccessible.",
"id": "working_mail", "back_to_home": "Retour à l'accueil",
"translation": "Courrier de travail" "get_started": "Commencez à utiliser"
}, }
{
"id": "anything_else",
"translation": "Rien d'autre?"
},
{
"id": "contact_message_placeholder",
"translation": "Le message va ici..."
},
{
"id": "submit",
"translation": "Soumettre"
},
{
"id": "page_not_found",
"translation": "Page non trouvée"
},
{
"id": "page_not_found_content",
"translation": "La page que vous recherchez a peut-être été supprimée, son nom a changé ou est temporairement indisponible."
},
{
"id": "back_to_home",
"translation": "De retour à la maison"
}
]
-63
View File
@@ -1,63 +0,0 @@
import enDataJSON from './en.json';
import frDataJSON from './fr.json';
import arDataJSON from './ar.json';
interface TranslationItem {
id: string;
translation: string;
}
export function convertJsonToUiObject(jsonData: TranslationItem[], language: string): Record<string, Record<string, string>> {
const ui: Record<string, Record<string, string>> = {};
ui[language] = {};
for (const item of jsonData) {
ui[language][item.id] = item.translation;
}
return ui;
}
export const ui = {
...convertJsonToUiObject(enDataJSON, 'en'),
...convertJsonToUiObject(frDataJSON, 'fr'),
...convertJsonToUiObject(arDataJSON, 'ar')
} as const;
// import { readdirSync } from 'fs';
// import path from 'path';
// import { fileURLToPath } from 'url';
// interface TranslationItem {
// id: string;
// translation: string;
// }
// function convertJsonToUiObject(jsonData: TranslationItem[]): Record<string, string> {
// const ui: Record<string, string> = {};
// for (const item of jsonData) {
// ui[item.id] = item.translation;
// }
// return ui;
// }
// const __filename = fileURLToPath(import.meta.url);
// const i18nFolderPath = path.join(path.dirname(__filename));
// const ui: Record<string, Record<string, string>> = {};
// readdirSync(i18nFolderPath).forEach((file) => {
// if (file.endsWith('.json')) {
// const language = file.split('.')[0];
// import(path.join(i18nFolderPath, file)).then((module) => {
// const jsonData: TranslationItem[] = module.default;
// ui[language] = convertJsonToUiObject(jsonData);
// });
// }
// });
// export { ui };
+9 -6
View File
@@ -1,20 +1,23 @@
--- ---
import config from "@/config/config.json"; import config from "@/config/config.json";
import dateFormat from "@/lib/utils/dateFormat"; import dateFormat from "@/lib/utils/dateFormat";
import { getLangFromUrl, getTranslations } from "@/lib/utils/i18nUtils";
import { humanize, plainify, slugify } from "@/lib/utils/textConverter"; import { humanize, plainify, slugify } from "@/lib/utils/textConverter";
import type { ContentEntryMap } from "astro:content";
import { FaRegFolder, FaRegUserCircle } from "react-icons/fa"; import { FaRegFolder, FaRegUserCircle } from "react-icons/fa";
import ImageMod from "./ImageMod.astro"; import ImageMod from "./ImageMod.astro";
import { getLangFromUrl } from "@/lib/utils/i18nUtils";
const { const {
summary_length, summary_length,
blog_folder, blog_folder,
}: { summary_length: number; blog_folder: string } = config.settings; }: { summary_length: number; blog_folder: string } = config.settings;
const { defaultLang } = config.language;
const { data } = Astro.props; const { data } = Astro.props;
const { title, image, date, author, categories } = data.data; const { title, image, date, author, categories } = data.data;
const lang = getLangFromUrl(Astro.url); const lang = getLangFromUrl(Astro.url);
const path = Astro.url.pathname; const path = Astro.url.pathname;
const { read_more } = await getTranslations(lang as keyof ContentEntryMap);
--- ---
<div class="bg-body dark:bg-darkmode-body"> <div class="bg-body dark:bg-darkmode-body">
@@ -33,8 +36,8 @@ const path = Astro.url.pathname;
<h4 class="mb-3"> <h4 class="mb-3">
<a <a
href={path.includes("/categories") href={path.includes("/categories")
? `/${lang === "en" ? "/" : lang}/blog/${data.slug}` ? `${lang === defaultLang ? "" : `/${lang}`}/blog/${data.slug}`
: `/${lang === "en" ? "/" : lang}/${data.slug}`} : `${lang === defaultLang ? "" : `/${lang}`}/${data.slug}`}
> >
{title} {title}
</a> </a>
@@ -63,9 +66,9 @@ const path = Astro.url.pathname;
<a <a
class="btn btn-outline-primary btn-sm" class="btn btn-outline-primary btn-sm"
href={path.includes("/categories") href={path.includes("/categories")
? `/${lang === "en" ? "/" : lang}/blog/${data.slug}` ? `${lang === defaultLang ? "" : `/${lang}`}/blog/${data.slug}`
: `/${lang === "en" ? "/" : lang}/${data.slug}`} : `${lang === defaultLang ? "" : `/${lang}`}/${data.slug}`}
> >
read more {read_more}
</a> </a>
</div> </div>
+6 -6
View File
@@ -1,15 +1,13 @@
--- ---
import { supportedLang } from "@/lib/utils/i18nUtils";
import { humanize } from "@/lib/utils/textConverter"; import { humanize } from "@/lib/utils/textConverter";
import config from "@/config/config.json";
const { supported } = config.language;
const { className }: { className?: string } = Astro.props; const { className }: { className?: string } = Astro.props;
const paths = Astro.url.pathname.split("/").filter((x) => x); const paths = Astro.url.pathname.split("/").filter((x) => x);
let lang = ""; let lang = "";
if (supported.includes(paths[0])) { if (supportedLang.includes(paths[0])) {
lang = paths.shift()!; lang = paths.shift()!;
} }
@@ -17,7 +15,10 @@ let parts = [
{ {
label: "Home", label: "Home",
href: `/${lang}`, href: `/${lang}`,
"aria-label": Astro.url.pathname === `/${lang}` || Astro.url.pathname === `/${lang}/` ? "page" : undefined, "aria-label":
Astro.url.pathname === `/${lang}` || Astro.url.pathname === `/${lang}/`
? "page"
: undefined,
}, },
]; ];
@@ -30,7 +31,6 @@ paths.forEach((label: string, i: number) => {
"aria-label": Astro.url.pathname === href ? "page" : undefined, "aria-label": Astro.url.pathname === href ? "page" : undefined,
}); });
}); });
--- ---
<nav aria-label="Breadcrumb" class={className}> <nav aria-label="Breadcrumb" class={className}>
+9 -8
View File
@@ -1,6 +1,8 @@
import languages from "@/config/language.json";
import React from 'react'; import React from 'react';
const LanguageSwitcher = ({ lang, languages, pathname }: { lang: string; languages: string[]; pathname: string }) => { const LanguageSwitcher = ({ lang, pathname }: { lang: string; pathname: string }) => {
return ( return (
<div className="mr-5"> <div className="mr-5">
<select <select
@@ -12,20 +14,19 @@ const LanguageSwitcher = ({ lang, languages, pathname }: { lang: string; languag
: `/${selectedLang}${pathname.replace(`/${lang}`, "")}`; : `/${selectedLang}${pathname.replace(`/${lang}`, "")}`;
window.location.href = newPath; window.location.href = newPath;
}} }}
value={languages.includes(lang) ? lang : 'en'} value={lang}
> >
{languages.map((child: string) => ( {languages.map((language) => (
<option <option
key={child} key={language.languageCode}
value={child} value={language.languageCode}
> >
{child} {language.languageName}
</option> </option>
))} ))}
</select> </select>
</div> </div>
) )
} }
export default LanguageSwitcher export default LanguageSwitcher;
+7 -15
View File
@@ -3,21 +3,18 @@ import Logo from "@/components/Logo.astro";
import ThemeSwitcher from "@/components/ThemeSwitcher.astro"; import ThemeSwitcher from "@/components/ThemeSwitcher.astro";
import config from "@/config/config.json"; import config from "@/config/config.json";
import LanguageSwitcher from "@/helpers/LanguageSwitcher"; import LanguageSwitcher from "@/helpers/LanguageSwitcher";
import { import { getLangFromUrl, getTranslations } from "@/lib/utils/i18nUtils";
getLangFromUrl,
languages,
useTranslations,
} from "@/lib/utils/i18nUtils";
import { loadMenu } from "@/lib/utils/loadMenu"; import { loadMenu } from "@/lib/utils/loadMenu";
import type { ContentEntryMap } from "astro:content";
import { getRelativeLocaleUrl } from "astro:i18n"; import { getRelativeLocaleUrl } from "astro:i18n";
import { IoSearch } from "react-icons/io5"; import { IoSearch } from "react-icons/io5";
const lang = getLangFromUrl(Astro.url); const lang = getLangFromUrl(Astro.url);
const menu = loadMenu(lang); const menu = loadMenu(lang);
const { navigation_button, settings } = config; const { navigation_button, settings } = config;
const { pathname } = Astro.url; const { pathname } = Astro.url;
const { get_started } = await getTranslations(lang as keyof ContentEntryMap);
const t = useTranslations(lang as any);
--- ---
<header class={`header z-30 ${settings.sticky_header && "sticky top-0"}`}> <header class={`header z-30 ${settings.sticky_header && "sticky top-0"}`}>
@@ -113,7 +110,7 @@ const t = useTranslations(lang as any);
class="btn btn-outline-primary btn-sm" class="btn btn-outline-primary btn-sm"
href={navigation_button.link} href={navigation_button.link}
> >
{t("get_started")} {get_started}
</a> </a>
</li> </li>
) )
@@ -133,19 +130,14 @@ const t = useTranslations(lang as any);
) )
} }
<ThemeSwitcher className="mr-5" /> <ThemeSwitcher className="mr-5" />
<LanguageSwitcher <LanguageSwitcher client:load lang={lang} pathname={pathname} />
client:load
lang={lang}
languages={languages}
pathname={pathname}
/>
{ {
navigation_button.enable && ( navigation_button.enable && (
<a <a
class="btn btn-outline-primary btn-sm hidden lg:inline-block" class="btn btn-outline-primary btn-sm hidden lg:inline-block"
href={navigation_button.link} href={navigation_button.link}
> >
{t("get_started")} {get_started}
</a> </a>
) )
} }
+12 -22
View File
@@ -1,19 +1,4 @@
--- ---
// import {
// getCollection,
// type CollectionEntry,
// type CollectionKey,
// } from "astro:content";
// export const getSinglePage = async <C extends CollectionKey>(
// collectionName: C,
// ): Promise<CollectionEntry<C>[]> => {
// const allPages = await getCollection(collectionName);
// const removeIndex = allPages.filter((data) => data.id.match(/^(?!-)/));
// const removeDrafts = removeIndex.filter((data) => !data.data.draft);
// return removeDrafts;
// };
import { import {
getCollection, getCollection,
type CollectionEntry, type CollectionEntry,
@@ -31,15 +16,17 @@ export const getSinglePage = async <C extends CollectionKey>(
const langCollection: keyof ContentEntryMap = lang as keyof ContentEntryMap; const langCollection: keyof ContentEntryMap = lang as keyof ContentEntryMap;
// Explicitly define the type of pages to CollectionEntry<C>[] // Explicitly define the type of pages to CollectionEntry<C>[]
const pages: CollectionEntry<C>[] = await getCollection(langCollection || defaultLang, ({ id }) => { const pages: CollectionEntry<C>[] = (await getCollection(
return id.startsWith(collectionName) && !id.endsWith("-index.md"); langCollection || defaultLang,
}) as CollectionEntry<C>[]; ({ id }: any) => {
return id.startsWith(collectionName) && !id.endsWith("-index.md");
}
)) as CollectionEntry<C>[];
const removeDrafts = pages.filter((data) => !data.data.draft); const removeDrafts = pages.filter((data) => !data.data.draft);
return removeDrafts; return removeDrafts;
}; };
export const getListPage = async <C extends CollectionKey>( export const getListPage = async <C extends CollectionKey>(
collectionName: C, collectionName: C,
lang: keyof ContentEntryMap lang: keyof ContentEntryMap
@@ -47,9 +34,12 @@ export const getListPage = async <C extends CollectionKey>(
const { defaultLang } = config.language; const { defaultLang } = config.language;
const langCollection: keyof ContentEntryMap = lang as keyof ContentEntryMap; const langCollection: keyof ContentEntryMap = lang as keyof ContentEntryMap;
// Fetch the collection based on the language // Fetch the collection based on the language
const pages: CollectionEntry<C>[] = await getCollection(langCollection || defaultLang, ({ id }) => { const pages: CollectionEntry<C>[] = (await getCollection(
return id.startsWith(collectionName); langCollection || defaultLang,
}) as CollectionEntry<C>[]; ({ id }: any) => {
return id.startsWith(collectionName);
}
)) as CollectionEntry<C>[];
return pages; return pages;
}; };
+2 -4
View File
@@ -1,16 +1,14 @@
--- ---
import { getSinglePage } from "@/lib/contentParser.astro";
import { slugify } from "@/lib/utils/textConverter"; import { slugify } from "@/lib/utils/textConverter";
import type { ContentEntryMap } from "astro:content"; import type { ContentEntryMap } from "astro:content";
import { getCollection } from "astro:content"; import { getCollection } from "astro:content";
// get taxonomy from frontmatter // get taxonomy from frontmatter
export const getTaxonomy = async (collection: any, name: string) => { export const getTaxonomy = async (collection: any, name: string) => {
// const singlePages = await getSinglePage(collection); // const singlePages = await getSinglePage(collection);
const singlePages = await getCollection( const singlePages = await getCollection(
collection as keyof ContentEntryMap, collection as keyof ContentEntryMap,
({ id }) => { ({ id }: any) => {
return id.startsWith("blog") && !id.endsWith("-index.md"); return id.startsWith("blog") && !id.endsWith("-index.md");
} }
); );
@@ -31,7 +29,7 @@ export const getAllTaxonomy = async (collection: any, name: string) => {
// const singlePages = await getSinglePage(collection); // const singlePages = await getSinglePage(collection);
const singlePages = await getCollection( const singlePages = await getCollection(
collection as keyof ContentEntryMap, collection as keyof ContentEntryMap,
({ id }) => { ({ id }: any) => {
return id.startsWith("blog") && !id.endsWith("-index.md"); return id.startsWith("blog") && !id.endsWith("-index.md");
} }
); );
+23 -41
View File
@@ -1,14 +1,18 @@
import fs from 'fs'; import config from "@/config/config.json";
import path from 'path'; import languagesJSON from "@/config/language.json";
import fs from "fs";
import path from "path";
const { defaultLang } = config.language;
const menusFolderPath = './src/config'; const menusFolderPath = "./src/config";
const locales = fs.readdirSync(menusFolderPath) const locales = fs
.filter(file => /^menu\.[a-z]{2}\.json$/.test(file)) .readdirSync(menusFolderPath)
.map(file => { .filter((file) => /^menu\.[a-z]{2}\.json$/.test(file))
.map((file) => {
const filePath = path.join(menusFolderPath, file); const filePath = path.join(menusFolderPath, file);
const localeName = file.split('.')[1]; // Extract language code from file name const localeName = file.split(".")[1]; // Extract language code from file name
const localeData = JSON.parse(fs.readFileSync(filePath, 'utf8')); const localeData = JSON.parse(fs.readFileSync(filePath, "utf8"));
return { [localeName]: localeData }; return { [localeName]: localeData };
}) })
.reduce((accumulator, locale) => { .reduce((accumulator, locale) => {
@@ -19,44 +23,22 @@ const locales = fs.readdirSync(menusFolderPath)
const languages = Object.keys(locales); const languages = Object.keys(locales);
// Export the locales and languages // Export the locales and languages
export { locales, languages }; export { languages, locales };
export function getLangFromUrl(url: URL): string { export function getLangFromUrl(url: URL): string {
const [, lang] = url.pathname.split('/'); const [, lang] = url.pathname.split("/");
if (locales.hasOwnProperty(lang)) { if (locales.hasOwnProperty(lang)) {
return lang; return lang;
} }
return 'en'; return defaultLang;
} }
export const getTranslations = async (lang: string) => {
const menu = await import(`../../config/menu.${lang || defaultLang}.json`);
const dictionary = await import(`../../i18n/${lang || defaultLang}.json`);
return { ...menu, ...dictionary };
};
export const supportedLang = [""].concat(
// import { ui } from '@/i18n/ui'; languagesJSON.map((lang) => lang.languageCode),
// import config from "@/config/config.json"; );
// const {defaultLang}: {defaultLang : keyof typeof ui} = config.language as any;
// export function useTranslations(lang: keyof typeof ui) {
// return function t(key: keyof typeof ui[typeof defaultLang]) {
// return ui[lang][key] || ui[defaultLang][key];
// }
// }
import { ui } from '@/i18n/ui';
import config from "@/config/config.json";
const { defaultLang }: { defaultLang: keyof typeof ui } = config.language as any;
export function useTranslations(lang?: keyof typeof ui) {
const activeLang = lang || defaultLang;
return function t(key: keyof typeof ui[typeof defaultLang]): string {
const translation = ui[activeLang][key];
// If not found, fall back to the default language
if (translation) {
return translation;
} else {
return ui[defaultLang][key];
}
};
}
+13 -9
View File
@@ -1,17 +1,21 @@
--- ---
import Base from "@/layouts/Base.astro";
import config from "@/config/config.json"; import config from "@/config/config.json";
import { getLangFromUrl, useTranslations } from "@/lib/utils/i18nUtils"; import Base from "@/layouts/Base.astro";
import { getLangFromUrl, getTranslations } from "@/lib/utils/i18nUtils";
import type { ContentEntryMap } from "astro:content";
import { supportedLang } from "@/lib/utils/i18nUtils";
export function getStaticPaths() { export function getStaticPaths() {
const {supported} = config.language; const paths = supportedLang.map((lang) => ({
const paths = supported.map((lang) => ({ params: { lang: lang || undefined } })); params: { lang: lang || undefined },
}));
return paths; return paths;
} }
const lang = getLangFromUrl(Astro.url); const lang = getLangFromUrl(Astro.url);
const t = useTranslations(lang as any); const { page_not_found_content, page_not_found, back_to_home } =
const {defaultLang} = config.language; await getTranslations(lang as keyof ContentEntryMap);
const { defaultLang } = config.language;
const href = lang && lang !== defaultLang ? `/${lang}/` : "/"; const href = lang && lang !== defaultLang ? `/${lang}/` : "/";
--- ---
@@ -25,11 +29,11 @@ const href = lang && lang !== defaultLang ? `/${lang}/` : "/";
> >
404 404
</span> </span>
<h1 class="h2 mb-4">{t("page_not_found")}</h1> <h1 class="h2 mb-4">{page_not_found}</h1>
<div class="content"> <div class="content">
<p>{t("page_not_found_content")}</p> <p>{page_not_found_content}</p>
</div> </div>
<a href={href} class="btn btn-primary mt-8">{t("back_to_home")}</a> <a href={href} class="btn btn-primary mt-8">{back_to_home}</a>
</div> </div>
</div> </div>
</div> </div>
+2 -4
View File
@@ -1,15 +1,13 @@
--- ---
import config from "@/config/config.json";
import Base from "@/layouts/Base.astro"; import Base from "@/layouts/Base.astro";
import { getSinglePage } from "@/lib/contentParser.astro"; import { getSinglePage } from "@/lib/contentParser.astro";
import { supportedLang } from "@/lib/utils/i18nUtils";
import PageHeader from "@/partials/PageHeader.astro"; import PageHeader from "@/partials/PageHeader.astro";
import type { ContentEntryMap } from "astro:content"; import type { ContentEntryMap } from "astro:content";
export async function getStaticPaths() { export async function getStaticPaths() {
const { supported } = config.language;
const paths = await Promise.all( const paths = await Promise.all(
supported.map(async (lang) => { supportedLang.map(async (lang) => {
const pages = await getSinglePage("pages", lang as keyof ContentEntryMap); const pages = await getSinglePage("pages", lang as keyof ContentEntryMap);
return pages.map((page) => ({ return pages.map((page) => ({
+6 -7
View File
@@ -1,20 +1,19 @@
--- ---
import ImageMod from "@/components/ImageMod.astro"; import ImageMod from "@/components/ImageMod.astro";
import Base from "@/layouts/Base.astro"; import Base from "@/layouts/Base.astro";
import { markdownify } from "@/lib/utils/textConverter";
import type { ContentEntryMap } from "astro:content";
import { getCollection } from "astro:content";
import config from "@/config/config.json";
import { getListPage } from "@/lib/contentParser.astro"; import { getListPage } from "@/lib/contentParser.astro";
import { supportedLang } from "@/lib/utils/i18nUtils";
import { markdownify } from "@/lib/utils/textConverter";
export function getStaticPaths() { export function getStaticPaths() {
const {supported} = config.language; const paths = supportedLang.map((lang) => ({
const paths = supported.map((lang) => ({ params: { lang: lang || undefined } })); params: { lang: lang || undefined },
}));
return paths; return paths;
} }
const { lang } = Astro.params; const { lang } = Astro.params;
const about = await getListPage("about", lang as keyof ContentEntryMap); const about = await getListPage("about", lang);
const { Content } = await about[0].render(); const { Content } = await about[0].render();
const { title, description, meta_title, image } = about[0].data; const { title, description, meta_title, image } = about[0].data;
+7 -6
View File
@@ -2,21 +2,22 @@
import BlogCard from "@/components/BlogCard.astro"; import BlogCard from "@/components/BlogCard.astro";
import ImageMod from "@/components/ImageMod.astro"; import ImageMod from "@/components/ImageMod.astro";
import Social from "@/components/Social.astro"; import Social from "@/components/Social.astro";
import config from "@/config/config.json";
import Base from "@/layouts/Base.astro"; import Base from "@/layouts/Base.astro";
import { getSinglePage } from "@/lib/contentParser.astro"; import { getSinglePage } from "@/lib/contentParser.astro";
import { supportedLang } from "@/lib/utils/i18nUtils";
import { slugify } from "@/lib/utils/textConverter"; import { slugify } from "@/lib/utils/textConverter";
import type { ContentEntryMap } from "astro:content"; import type { ContentEntryMap } from "astro:content";
import { getCollection } from "astro:content";
// get all static paths for authors // get all static paths for authors
export async function getStaticPaths() { export async function getStaticPaths() {
const { supported } = config.language;
const COLLECTION_FOLDER = "authors"; const COLLECTION_FOLDER = "authors";
const paths = await Promise.all( const paths = await Promise.all(
supported.map(async (lang) => { supportedLang.map(async (lang) => {
const authors = await getSinglePage(COLLECTION_FOLDER, lang as keyof ContentEntryMap); const authors = await getSinglePage(
COLLECTION_FOLDER,
lang as keyof ContentEntryMap
);
return authors.map((author) => ({ return authors.map((author) => ({
params: { params: {
@@ -25,7 +26,7 @@ export async function getStaticPaths() {
}, },
props: { props: {
author, author,
lang lang,
}, },
})); }));
}) })
+2 -3
View File
@@ -1,16 +1,15 @@
--- ---
import AuthorCard from "@/components/AuthorCard.astro"; import AuthorCard from "@/components/AuthorCard.astro";
import config from "@/config/config.json";
import Base from "@/layouts/Base.astro"; import Base from "@/layouts/Base.astro";
import { getListPage, getSinglePage } from "@/lib/contentParser.astro"; import { getListPage, getSinglePage } from "@/lib/contentParser.astro";
import { supportedLang } from "@/lib/utils/i18nUtils";
import PageHeader from "@/partials/PageHeader.astro"; import PageHeader from "@/partials/PageHeader.astro";
import { type ContentEntryMap } from "astro:content"; import { type ContentEntryMap } from "astro:content";
const COLLECTION_FOLDER = "authors"; const COLLECTION_FOLDER = "authors";
export function getStaticPaths() { export function getStaticPaths() {
const { supported } = config.language; const paths = supportedLang.map((lang) => ({
const paths = supported.map((lang) => ({
params: { lang: lang || undefined }, params: { lang: lang || undefined },
})); }));
return paths; return paths;
+7 -5
View File
@@ -1,18 +1,19 @@
--- ---
import config from "@/config/config.json";
import Base from "@/layouts/Base.astro"; import Base from "@/layouts/Base.astro";
import PostSingle from "@/layouts/PostSingle.astro"; import PostSingle from "@/layouts/PostSingle.astro";
import { getSinglePage } from "@/lib/contentParser.astro"; import { getSinglePage } from "@/lib/contentParser.astro";
import { supportedLang } from "@/lib/utils/i18nUtils";
import type { ContentEntryMap } from "astro:content"; import type { ContentEntryMap } from "astro:content";
import { getCollection } from "astro:content";
export async function getStaticPaths() { export async function getStaticPaths() {
const { supported } = config.language;
const BLOG_FOLDER = "blog"; const BLOG_FOLDER = "blog";
const paths = await Promise.all( const paths = await Promise.all(
supported.map(async (lang) => { supportedLang.map(async (lang) => {
const posts = await getSinglePage(BLOG_FOLDER, lang as keyof ContentEntryMap); const posts = await getSinglePage(
BLOG_FOLDER,
lang as keyof ContentEntryMap
);
return posts.map((post) => ({ return posts.map((post) => ({
params: { params: {
@@ -31,6 +32,7 @@ export async function getStaticPaths() {
const { post } = Astro.props; const { post } = Astro.props;
const { title, meta_title, description, image } = post.data; const { title, meta_title, description, image } = post.data;
--- ---
<Base <Base
title={title} title={title}
meta_title={meta_title} meta_title={meta_title}
+2 -2
View File
@@ -5,14 +5,14 @@ import config from "@/config/config.json";
import Base from "@/layouts/Base.astro"; import Base from "@/layouts/Base.astro";
import { getListPage, getSinglePage } from "@/lib/contentParser.astro"; import { getListPage, getSinglePage } from "@/lib/contentParser.astro";
import { getAllTaxonomy, getTaxonomy } from "@/lib/taxonomyParser.astro"; import { getAllTaxonomy, getTaxonomy } from "@/lib/taxonomyParser.astro";
import { supportedLang } from "@/lib/utils/i18nUtils";
import { sortByDate } from "@/lib/utils/sortFunctions"; import { sortByDate } from "@/lib/utils/sortFunctions";
import PageHeader from "@/partials/PageHeader.astro"; import PageHeader from "@/partials/PageHeader.astro";
import PostSidebar from "@/partials/PostSidebar.astro"; import PostSidebar from "@/partials/PostSidebar.astro";
import type { ContentEntryMap } from "astro:content"; import type { ContentEntryMap } from "astro:content";
export function getStaticPaths() { export function getStaticPaths() {
const { supported } = config.language; const paths = supportedLang.map((lang) => ({
const paths = supported.map((lang) => ({
params: { lang: lang || undefined }, params: { lang: lang || undefined },
})); }));
return paths; return paths;
+10 -8
View File
@@ -4,26 +4,29 @@ import Pagination from "@/components/Pagination.astro";
import config from "@/config/config.json"; import config from "@/config/config.json";
import Base from "@/layouts/Base.astro"; import Base from "@/layouts/Base.astro";
import { getAllTaxonomy, getTaxonomy } from "@/lib/taxonomyParser.astro"; import { getAllTaxonomy, getTaxonomy } from "@/lib/taxonomyParser.astro";
import { supportedLang } from "@/lib/utils/i18nUtils";
import { sortByDate } from "@/lib/utils/sortFunctions"; import { sortByDate } from "@/lib/utils/sortFunctions";
import PageHeader from "@/partials/PageHeader.astro"; import PageHeader from "@/partials/PageHeader.astro";
import PostSidebar from "@/partials/PostSidebar.astro"; import PostSidebar from "@/partials/PostSidebar.astro";
import type { ContentEntryMap } from "astro:content"; import type { ContentEntryMap } from "astro:content";
import { getCollection } from "astro:content"; import { getCollection } from "astro:content";
const BLOG_FOLDER = "blog"; const BLOG_FOLDER = "blog";
const { slug, lang } = Astro.params; const { slug, lang } = Astro.params;
const postIndex = await getCollection( const postIndex = await getCollection(
lang as keyof ContentEntryMap, lang as keyof ContentEntryMap,
({ id }) => { ({ id }: any) => {
return id.startsWith(BLOG_FOLDER); return id.startsWith(BLOG_FOLDER);
} }
); );
const posts = await getCollection(lang as keyof ContentEntryMap, ({ id }) => { const posts = await getCollection(
return id.startsWith(BLOG_FOLDER) && !id.endsWith("-index.md"); lang as keyof ContentEntryMap,
}); ({ id }: any) => {
return id.startsWith(BLOG_FOLDER) && !id.endsWith("-index.md");
}
);
const langCollection: keyof ContentEntryMap = lang as keyof ContentEntryMap; const langCollection: keyof ContentEntryMap = lang as keyof ContentEntryMap;
const allCategories = await getAllTaxonomy(langCollection, "categories"); const allCategories = await getAllTaxonomy(langCollection, "categories");
@@ -37,14 +40,13 @@ const indexOfFirstPost = indexOfLastPost - config.settings.pagination;
const currentPosts = sortedPosts.slice(indexOfFirstPost, indexOfLastPost); const currentPosts = sortedPosts.slice(indexOfFirstPost, indexOfLastPost);
export async function getStaticPaths() { export async function getStaticPaths() {
const { supported } = config.language;
const BLOG_FOLDER = "blog"; const BLOG_FOLDER = "blog";
const paths = await Promise.all( const paths = await Promise.all(
supported.map(async (lang) => { supportedLang.map(async (lang) => {
const posts = await getCollection( const posts = await getCollection(
lang as keyof ContentEntryMap, lang as keyof ContentEntryMap,
({ id }) => { ({ id }: any) => {
return id.startsWith(BLOG_FOLDER) && !id.endsWith("-index.md"); return id.startsWith(BLOG_FOLDER) && !id.endsWith("-index.md");
} }
); );
@@ -1,19 +1,17 @@
--- ---
import BlogCard from "@/components/BlogCard.astro"; import BlogCard from "@/components/BlogCard.astro";
import config from "@/config/config.json";
import Base from "@/layouts/Base.astro"; import Base from "@/layouts/Base.astro";
import { getSinglePage } from "@/lib/contentParser.astro"; import { getSinglePage } from "@/lib/contentParser.astro";
import { getTaxonomy } from "@/lib/taxonomyParser.astro"; import { getTaxonomy } from "@/lib/taxonomyParser.astro";
import { supportedLang } from "@/lib/utils/i18nUtils";
import { sortByDate } from "@/lib/utils/sortFunctions"; import { sortByDate } from "@/lib/utils/sortFunctions";
import taxonomyFilter from "@/lib/utils/taxonomyFilter"; import taxonomyFilter from "@/lib/utils/taxonomyFilter";
import PageHeader from "@/partials/PageHeader.astro"; import PageHeader from "@/partials/PageHeader.astro";
// get all static paths for categories // get all static paths for categories
export async function getStaticPaths() { export async function getStaticPaths() {
const { supported } = config.language;
const paths = await Promise.all( const paths = await Promise.all(
supported.map(async (lang) => { supportedLang.map(async (lang) => {
const categories = await getTaxonomy(lang, "categories"); const categories = await getTaxonomy(lang, "categories");
return categories.map((category) => ({ return categories.map((category) => ({
+4 -3
View File
@@ -1,14 +1,15 @@
--- ---
import Base from "@/layouts/Base.astro"; import Base from "@/layouts/Base.astro";
import { getAllTaxonomy, getTaxonomy } from "@/lib/taxonomyParser.astro"; import { getAllTaxonomy, getTaxonomy } from "@/lib/taxonomyParser.astro";
import { supportedLang } from "@/lib/utils/i18nUtils";
import { humanize } from "@/lib/utils/textConverter"; import { humanize } from "@/lib/utils/textConverter";
import PageHeader from "@/partials/PageHeader.astro"; import PageHeader from "@/partials/PageHeader.astro";
import config from "@/config/config.json";
import type { ContentEntryMap } from "astro:content"; import type { ContentEntryMap } from "astro:content";
export function getStaticPaths() { export function getStaticPaths() {
const {supported } = config.language; const paths = supportedLang.map((lang) => ({
const paths = supported.map((lang) => ({ params: { lang: lang || undefined } })); params: { lang: lang || undefined },
}));
return paths; return paths;
} }
+18 -9
View File
@@ -2,13 +2,14 @@
import config from "@/config/config.json"; import config from "@/config/config.json";
import Base from "@/layouts/Base.astro"; import Base from "@/layouts/Base.astro";
import { getListPage } from "@/lib/contentParser.astro"; import { getListPage } from "@/lib/contentParser.astro";
import { useTranslations } from "@/lib/utils/i18nUtils"; import { getTranslations, supportedLang } from "@/lib/utils/i18nUtils";
import PageHeader from "@/partials/PageHeader.astro"; import PageHeader from "@/partials/PageHeader.astro";
import { type ContentEntryMap } from "astro:content"; import { type ContentEntryMap } from "astro:content";
export function getStaticPaths() { export function getStaticPaths() {
const {supported} = config.language; const paths = supportedLang.map((lang) => ({
const paths = supported.map((lang) => ({ params: { lang: lang || undefined } })); params: { lang: lang || undefined },
}));
return paths; return paths;
} }
@@ -18,7 +19,13 @@ const contact = await getListPage("contact", lang as keyof ContentEntryMap);
const { contact_form_action }: { contact_form_action: string } = config.params; const { contact_form_action }: { contact_form_action: string } = config.params;
const { title, description, meta_title, image } = contact[0].data; const { title, description, meta_title, image } = contact[0].data;
const t = useTranslations(lang as any); const {
working_mail,
full_name,
anything_else,
contact_message_placeholder,
submit,
} = await getTranslations(lang as keyof ContentEntryMap);
--- ---
<Base <Base
@@ -35,7 +42,7 @@ const t = useTranslations(lang as any);
<form action={contact_form_action} method="POST"> <form action={contact_form_action} method="POST">
<div class="mb-6"> <div class="mb-6">
<label for="name" class="form-label"> <label for="name" class="form-label">
{t("full_name")} {full_name}
<span class="text-red-500">*</span> <span class="text-red-500">*</span>
</label> </label>
<input <input
@@ -48,7 +55,8 @@ const t = useTranslations(lang as any);
</div> </div>
<div class="mb-6"> <div class="mb-6">
<label for="email" class="form-label"> <label for="email" class="form-label">
{t("working_mail")} <span class="text-red-500">*</span> {working_mail}
<span class="text-red-500">*</span>
</label> </label>
<input <input
id="email" id="email"
@@ -60,16 +68,17 @@ const t = useTranslations(lang as any);
</div> </div>
<div class="mb-6"> <div class="mb-6">
<label for="message" class="form-label"> <label for="message" class="form-label">
{t("anything_else")} <span class="text-red-500">*</span> {anything_else}
<span class="text-red-500">*</span>
</label> </label>
<textarea <textarea
id="message" id="message"
name="message" name="message"
class="form-input" class="form-input"
placeholder={t("contact_message_placeholder")} placeholder={contact_message_placeholder}
rows="8"></textarea> rows="8"></textarea>
</div> </div>
<button type="submit" class="btn btn-primary">{t("submit")}</button> <button type="submit" class="btn btn-primary">{submit}</button>
</form> </form>
</div> </div>
</div> </div>
+5 -8
View File
@@ -11,6 +11,7 @@ import type { ContentEntryMap } from "astro:content";
import { getCollection } from "astro:content"; import { getCollection } from "astro:content";
import { FaCheck } from "react-icons/fa"; import { FaCheck } from "react-icons/fa";
const { defaultLang } = config.language; const { defaultLang } = config.language;
import { supportedLang } from "@/lib/utils/i18nUtils";
interface Homepage { interface Homepage {
banner: { banner: {
@@ -23,29 +24,25 @@ interface Homepage {
} }
export function getStaticPaths() { export function getStaticPaths() {
const { supported } = config.language; const paths = supportedLang.map((lang) => ({
const paths = supported.map((lang) => ({
params: { lang: lang || undefined }, params: { lang: lang || undefined },
})); }));
return paths; return paths;
} }
const { lang } = Astro.params; const { lang } = Astro.params;
const homepage = await getListPage("homepage", lang as keyof ContentEntryMap); const homepage = await getListPage("homepage", lang);
// const testimonial = await getEntry("sections", "testimonial");
// const call_to_action = await getEntry("sections", "call-to-action");
const { banner, features }: Homepage = homepage[0].data; const { banner, features }: Homepage = homepage[0].data;
const testimonial = await getCollection( const testimonial = await getCollection(
(lang as keyof ContentEntryMap) || defaultLang, (lang as keyof ContentEntryMap) || defaultLang,
({ id }) => { ({ id }: any) => {
return id.startsWith("sections/testimonial") && !id.endsWith("-index.md"); return id.startsWith("sections/testimonial") && !id.endsWith("-index.md");
} }
); );
const call_to_action = await getCollection( const call_to_action = await getCollection(
(lang as keyof ContentEntryMap) || defaultLang, (lang as keyof ContentEntryMap) || defaultLang,
({ id }) => { ({ id }: any) => {
return ( return (
id.startsWith("sections/call-to-action") && !id.endsWith("-index.md") id.startsWith("sections/call-to-action") && !id.endsWith("-index.md")
); );