trailing_slash && pagination fn changed

This commit is contained in:
Al Murad Uzzaman
2024-05-19 22:54:59 +06:00
parent 340500efcc
commit 2acaa9534b
9 changed files with 133 additions and 46 deletions
+2 -2
View File
@@ -10,7 +10,7 @@ export async function getStaticPaths() {
supportedLang.map(async (lang) => {
const pages = await getSinglePage("pages", lang as keyof ContentEntryMap);
return pages.map((page) => ({
return pages.map((page: any) => ({
params: {
lang: lang || undefined,
regular: page.slug.split("/").pop(),
@@ -19,7 +19,7 @@ export async function getStaticPaths() {
page,
},
}));
})
}),
);
return paths.flat();
}
+3 -3
View File
@@ -16,13 +16,13 @@ export function getStaticPaths() {
}
const { lang } = Astro.params;
const authorIndex = await getListPage(
const authorIndex: any = await getListPage(
COLLECTION_FOLDER,
lang as keyof ContentEntryMap
lang as keyof ContentEntryMap,
);
const authors = await getSinglePage(
COLLECTION_FOLDER,
lang as keyof ContentEntryMap
lang as keyof ContentEntryMap,
);
---
+9 -8
View File
@@ -10,10 +10,14 @@ import { sortByDate } from "@/lib/utils/sortFunctions";
import PageHeader from "@/partials/PageHeader.astro";
import PostSidebar from "@/partials/PostSidebar.astro";
import type { ContentEntryMap } from "astro:content";
import { getCollection } from "astro:content";
const BLOG_FOLDER = "blog";
const { default_language } = config.settings;
const { slug, lang } = Astro.params;
let { slug, lang } = Astro.params;
if (!lang) {
lang = default_language;
}
const postIndex: any = await getListPage(
BLOG_FOLDER,
@@ -41,13 +45,10 @@ export async function getStaticPaths() {
const paths = await Promise.all(
supportedLang.map(async (lang) => {
const posts = await getCollection(
const posts = await getSinglePage(
BLOG_FOLDER,
lang as keyof ContentEntryMap,
({ id }: any) => {
return id.startsWith(BLOG_FOLDER) && !id.endsWith("-index.md");
},
);
const totalPages = Math.ceil(posts.length / config.settings.pagination);
const langString = lang.toString();
const langPaths = [];
@@ -55,7 +56,7 @@ export async function getStaticPaths() {
for (let i = 1; i < totalPages; i++) {
langPaths.push({
params: {
lang: langString,
lang: langString || undefined,
slug: (i + 1).toString(),
},
});
+28 -3
View File
@@ -1,10 +1,13 @@
---
import config from "@/config/config.json";
import Base from "@/layouts/Base.astro";
import { getAllTaxonomy, getTaxonomy } from "@/lib/taxonomyParser.astro";
import { supportedLang } from "@/lib/utils/i18nUtils";
import { constructUrl, supportedLang } from "@/lib/utils/i18nUtils";
import { humanize } from "@/lib/utils/textConverter";
import PageHeader from "@/partials/PageHeader.astro";
import type { ContentEntryMap } from "astro:content";
const { default_language, default_language_in_path } = config.settings;
const { trailing_slash } = config.site;
export function getStaticPaths() {
const paths = supportedLang.map((lang) => ({
@@ -13,10 +16,32 @@ export function getStaticPaths() {
return paths;
}
const { lang } = Astro.params;
let { lang } = Astro.params;
if (!lang) {
lang = default_language;
}
const langCollection: keyof ContentEntryMap = lang as keyof ContentEntryMap;
const categories = await getTaxonomy(langCollection, "categories");
const allCategories = await getAllTaxonomy(langCollection, "categories");
const constructLocalizedUrl = (url: string) => {
if (lang === default_language) {
return constructUrl(
default_language_in_path ? `/${lang}${url}` : url,
lang,
default_language,
trailing_slash,
);
} else {
return constructUrl(
url,
lang as keyof ContentEntryMap,
default_language,
trailing_slash,
);
}
};
---
<Base title={"Categories"}>
@@ -30,7 +55,7 @@ const allCategories = await getAllTaxonomy(langCollection, "categories");
return (
<li class="m-3 inline-block">
<a
href={`/${lang === "" ? "categories" + "/" : lang}/categories/${category}`}
href={constructLocalizedUrl(`/categories/${category}`)}
class="block rounded bg-theme-light px-4 py-2 text-xl text-dark dark:bg-darkmode-theme-light dark:text-darkmode-dark"
>
{humanize(category)}{" "}
+28 -3
View File
@@ -1,10 +1,13 @@
---
import config from "@/config/config.json";
import Base from "@/layouts/Base.astro";
import { getAllTaxonomy, getTaxonomy } from "@/lib/taxonomyParser.astro";
import { supportedLang } from "@/lib/utils/i18nUtils";
import { constructUrl, supportedLang } from "@/lib/utils/i18nUtils";
import { humanize } from "@/lib/utils/textConverter";
import PageHeader from "@/partials/PageHeader.astro";
import type { ContentEntryMap } from "astro:content";
const { default_language, default_language_in_path } = config.settings;
const { trailing_slash } = config.site;
export function getStaticPaths() {
const paths = supportedLang.map((lang) => ({
@@ -13,10 +16,32 @@ export function getStaticPaths() {
return paths;
}
const { lang } = Astro.params;
let { lang } = Astro.params;
if (!lang) {
lang = default_language;
}
const langCollection: keyof ContentEntryMap = lang as keyof ContentEntryMap;
const tags = await getTaxonomy(langCollection, "tags");
const allTags = await getAllTaxonomy(langCollection, "tags");
const constructLocalizedUrl = (url: string) => {
if (lang === default_language) {
return constructUrl(
default_language_in_path ? `/${lang}${url}` : url,
lang,
default_language,
trailing_slash,
);
} else {
return constructUrl(
url,
lang as keyof ContentEntryMap,
default_language,
trailing_slash,
);
}
};
---
<Base title={"Tags"}>
@@ -30,7 +55,7 @@ const allTags = await getAllTaxonomy(langCollection, "tags");
return (
<li class="m-3 inline-block">
<a
href={`/${lang === "" ? "tags" + "/" : lang}/tags/${tag}`}
href={constructLocalizedUrl(`/tags/${tag}`)}
class="block rounded bg-theme-light px-4 py-2 text-xl text-dark dark:bg-darkmode-theme-light dark:text-darkmode-dark"
>
{humanize(tag)}{" "}