mirror of
https://github.com/10h30/astroplate.git
synced 2026-07-19 06:33:33 +09:00
slugSelector fn added
This commit is contained in:
+4
-11
@@ -1,14 +1,13 @@
|
||||
---
|
||||
import config from "@/config/config.json";
|
||||
import Base from "@/layouts/Base.astro";
|
||||
import { slugSelector } from "@/lib/languageParser.astro";
|
||||
import {
|
||||
constructUrl,
|
||||
getLangFromUrl,
|
||||
getTranslations,
|
||||
supportedLang,
|
||||
} from "@/lib/utils/i18nUtils";
|
||||
import type { ContentEntryMap } from "astro:content";
|
||||
const { trailing_slash } = config.site;
|
||||
|
||||
export function getStaticPaths() {
|
||||
const paths = supportedLang.map((lang) => ({
|
||||
@@ -19,21 +18,13 @@ export function getStaticPaths() {
|
||||
|
||||
let lang = getLangFromUrl(Astro.url);
|
||||
|
||||
// Check if the current language is disabled
|
||||
const disabledLanguages = config.settings.disable_languages as string[];
|
||||
if (disabledLanguages.includes(lang)) {
|
||||
// Redirect to the default language or handle as per your application logic
|
||||
lang = config.settings.default_language;
|
||||
}
|
||||
|
||||
const { page_not_found_content, page_not_found, back_to_home } =
|
||||
await getTranslations(lang as keyof ContentEntryMap);
|
||||
const href = constructUrl(
|
||||
"/",
|
||||
lang,
|
||||
config.settings.default_language,
|
||||
trailing_slash
|
||||
);
|
||||
---
|
||||
|
||||
<Base title="Page Not Found">
|
||||
@@ -50,7 +41,9 @@ const href = constructUrl(
|
||||
<div class="content">
|
||||
<p>{page_not_found_content}</p>
|
||||
</div>
|
||||
<a href={href} class="btn btn-primary mt-8">{back_to_home}</a>
|
||||
<a href={slugSelector("/", lang)} class="btn btn-primary mt-8"
|
||||
>{back_to_home}</a
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
---
|
||||
import config from "@/config/config.json";
|
||||
import Base from "@/layouts/Base.astro";
|
||||
import { slugSelector } from "@/lib/languageParser.astro";
|
||||
import { getAllTaxonomy, getTaxonomy } from "@/lib/taxonomyParser.astro";
|
||||
import { constructUrl, supportedLang } from "@/lib/utils/i18nUtils";
|
||||
import { 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;
|
||||
const { default_language } = config.settings;
|
||||
|
||||
export function getStaticPaths() {
|
||||
const paths = supportedLang.map((lang) => ({
|
||||
@@ -24,24 +24,6 @@ if (!lang) {
|
||||
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"}>
|
||||
@@ -55,7 +37,7 @@ const constructLocalizedUrl = (url: string) => {
|
||||
return (
|
||||
<li class="m-3 inline-block">
|
||||
<a
|
||||
href={constructLocalizedUrl(`/categories/${category}`)}
|
||||
href={slugSelector(`/categories/${category}`, lang)}
|
||||
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)}{" "}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
---
|
||||
import config from "@/config/config.json";
|
||||
import Base from "@/layouts/Base.astro";
|
||||
import { slugSelector } from "@/lib/languageParser.astro";
|
||||
import { getAllTaxonomy, getTaxonomy } from "@/lib/taxonomyParser.astro";
|
||||
import { constructUrl, supportedLang } from "@/lib/utils/i18nUtils";
|
||||
import { 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;
|
||||
const { default_language } = config.settings;
|
||||
|
||||
export function getStaticPaths() {
|
||||
const paths = supportedLang.map((lang) => ({
|
||||
@@ -24,24 +24,6 @@ if (!lang) {
|
||||
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"}>
|
||||
@@ -55,7 +37,7 @@ const constructLocalizedUrl = (url: string) => {
|
||||
return (
|
||||
<li class="m-3 inline-block">
|
||||
<a
|
||||
href={constructLocalizedUrl(`/tags/${tag}`)}
|
||||
href={slugSelector(`/tags/${tag}`, lang)}
|
||||
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)}{" "}
|
||||
|
||||
Reference in New Issue
Block a user