mirror of
https://github.com/10h30/astroplate.git
synced 2026-07-18 22:23:27 +09:00
slugSelector fn added
This commit is contained in:
@@ -1,28 +1,13 @@
|
||||
---
|
||||
import { constructUrl, getLangFromUrl } from "@/lib/utils/i18nUtils";
|
||||
import { slugSelector } from "@/lib/languageParser.astro";
|
||||
import { getLangFromUrl } from "@/lib/utils/i18nUtils";
|
||||
import { plainify } from "@/lib/utils/textConverter";
|
||||
import ImageMod from "./ImageMod.astro";
|
||||
import Social from "./Social.astro";
|
||||
import config from "@/config/config.json";
|
||||
const { default_language, default_language_in_path } = config.settings;
|
||||
const { trailing_slash } = config.site;
|
||||
|
||||
const { data } = Astro.props;
|
||||
const { title, image, social } = data.data;
|
||||
const lang = getLangFromUrl(Astro.url);
|
||||
|
||||
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, default_language, trailing_slash);
|
||||
}
|
||||
};
|
||||
---
|
||||
|
||||
<div
|
||||
@@ -41,7 +26,7 @@ const constructLocalizedUrl = (url: string) => {
|
||||
)
|
||||
}
|
||||
<h4 class="mb-3">
|
||||
<a href={constructLocalizedUrl(`/${data.slug}`)}>{title}</a>
|
||||
<a href={slugSelector(`/${data.slug}`, lang)}>{title}</a>
|
||||
</h4>
|
||||
<p class="mb-4">
|
||||
{plainify(data.body?.slice(0, 100))}
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
---
|
||||
import config from "@/config/config.json";
|
||||
import { slugSelector } from "@/lib/languageParser.astro";
|
||||
import dateFormat from "@/lib/utils/dateFormat";
|
||||
import {
|
||||
constructUrl,
|
||||
getLangFromUrl,
|
||||
getTranslations,
|
||||
} from "@/lib/utils/i18nUtils";
|
||||
import { getLangFromUrl, getTranslations } from "@/lib/utils/i18nUtils";
|
||||
import { humanize, plainify, slugify } from "@/lib/utils/textConverter";
|
||||
import type { ContentEntryMap } from "astro:content";
|
||||
import { FaRegFolder, FaRegUserCircle } from "react-icons/fa";
|
||||
@@ -13,26 +10,11 @@ import ImageMod from "./ImageMod.astro";
|
||||
|
||||
const { summary_length }: { summary_length: number; blog_folder: string } =
|
||||
config.settings;
|
||||
const { default_language, default_language_in_path } = config.settings;
|
||||
const { trailing_slash } = config.site;
|
||||
const { data } = Astro.props;
|
||||
const { title, image, date, author, categories } = data.data;
|
||||
|
||||
const lang = getLangFromUrl(Astro.url);
|
||||
const { read_more } = await getTranslations(lang as keyof ContentEntryMap);
|
||||
|
||||
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, default_language, trailing_slash);
|
||||
}
|
||||
};
|
||||
---
|
||||
|
||||
<div class="bg-body dark:bg-darkmode-body">
|
||||
@@ -49,13 +31,13 @@ const constructLocalizedUrl = (url: string) => {
|
||||
)
|
||||
}
|
||||
<h4 class="mb-3">
|
||||
<a href={constructLocalizedUrl(`/${data.slug}`)}>
|
||||
<a href={slugSelector(`/${data.slug}`, lang)}>
|
||||
{title}
|
||||
</a>
|
||||
</h4>
|
||||
<ul class="mb-4">
|
||||
<li class="mr-4 inline-block">
|
||||
<a href={constructLocalizedUrl(`/authors/${slugify(author)}`)}>
|
||||
<a href={slugSelector(`/authors/${slugify(author)}`, lang)}>
|
||||
<FaRegUserCircle className={"mr-2 -mt-1 inline-block"} />
|
||||
{humanize(author)}
|
||||
</a>
|
||||
@@ -65,7 +47,7 @@ const constructLocalizedUrl = (url: string) => {
|
||||
<FaRegFolder className={"mr-2 -mt-1 inline-block"} />
|
||||
{
|
||||
categories.map((category: string, index: number) => (
|
||||
<a href={constructLocalizedUrl(`/categories/${slugify(category)}`)}>
|
||||
<a href={slugSelector(`/categories/${slugify(category)}`, lang)}>
|
||||
{humanize(category)}
|
||||
{index !== categories.length - 1 && ","}
|
||||
</a>
|
||||
@@ -77,7 +59,7 @@ const constructLocalizedUrl = (url: string) => {
|
||||
<p class="mb-6">{plainify(data.body?.slice(0, Number(summary_length)))}</p>
|
||||
<a
|
||||
class="btn btn-outline-primary btn-sm"
|
||||
href={constructLocalizedUrl(`/${data.slug}`)}
|
||||
href={slugSelector(`/${data.slug}`, lang)}
|
||||
>
|
||||
{read_more}
|
||||
</a>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
---
|
||||
import config from "@/config/config.json";
|
||||
import { constructUrl, getLangFromUrl } from "@/lib/utils/i18nUtils";
|
||||
import { slugSelector } from "@/lib/languageParser.astro";
|
||||
import { getLangFromUrl } from "@/lib/utils/i18nUtils";
|
||||
import ImageMod from "./ImageMod.astro";
|
||||
|
||||
const { src, srcDarkmode }: { src?: string; srcDarkmode?: string } =
|
||||
@@ -22,33 +23,17 @@ const {
|
||||
} = config.site;
|
||||
|
||||
const { theme_switcher }: { theme_switcher: boolean } = config.settings;
|
||||
const { default_language, default_language_in_path } = config.settings;
|
||||
const { trailing_slash } = config.site;
|
||||
const { default_language } = config.settings;
|
||||
|
||||
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 = default_language;
|
||||
}
|
||||
|
||||
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, default_language, trailing_slash);
|
||||
}
|
||||
};
|
||||
---
|
||||
|
||||
<a href={constructLocalizedUrl("/")} class="navbar-brand inline-block">
|
||||
<a href={slugSelector("/", lang)} class="navbar-brand inline-block">
|
||||
{
|
||||
src || srcDarkmode || logo || logo_darkmode ? (
|
||||
<>
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
---
|
||||
import { constructUrl, getLangFromUrl } from "@/lib/utils/i18nUtils";
|
||||
import config from "@/config/config.json";
|
||||
import type { ContentEntryMap } from "astro:content";
|
||||
const { default_language, default_language_in_path } = config.settings;
|
||||
const { trailing_slash } = config.site;
|
||||
import { slugSelector } from "@/lib/languageParser.astro";
|
||||
import { getLangFromUrl } from "@/lib/utils/i18nUtils";
|
||||
|
||||
const lang = getLangFromUrl(Astro.url);
|
||||
|
||||
@@ -22,24 +19,6 @@ let pageList: number[] = [];
|
||||
for (let i = 1; i <= totalPages; i++) {
|
||||
pageList.push(i);
|
||||
}
|
||||
|
||||
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,
|
||||
);
|
||||
}
|
||||
};
|
||||
---
|
||||
|
||||
{
|
||||
@@ -53,9 +32,10 @@ const constructLocalizedUrl = (url: string) => {
|
||||
<a
|
||||
href={
|
||||
indexPageLink
|
||||
? constructLocalizedUrl(`/${section ? section : ""}`)
|
||||
: constructLocalizedUrl(
|
||||
? slugSelector(`/${section ? section : ""}`, lang)
|
||||
: slugSelector(
|
||||
`/${section ? section : ""}/page/${currentPage - 1}`,
|
||||
lang
|
||||
)
|
||||
}
|
||||
class="rounded px-2 py-1.5 text-dark hover:bg-theme-light dark:text-darkmode-dark dark:hover:bg-darkmode-theme-light"
|
||||
@@ -105,24 +85,26 @@ const constructLocalizedUrl = (url: string) => {
|
||||
</span>
|
||||
) : (
|
||||
<a
|
||||
href={constructLocalizedUrl(
|
||||
href={slugSelector(
|
||||
i === 0
|
||||
? `/${section ? section : ""}`
|
||||
: `/${section ? section : ""}/page/${pagination}`,
|
||||
lang
|
||||
)}
|
||||
aria-current="page"
|
||||
class="rounded px-4 py-2 text-dark hover:bg-theme-light dark:text-darkmode-dark dark:hover:bg-darkmode-theme-light"
|
||||
>
|
||||
{pagination}
|
||||
</a>
|
||||
),
|
||||
)
|
||||
)}
|
||||
|
||||
{/* next page */}
|
||||
{hasNextPage ? (
|
||||
<a
|
||||
href={constructLocalizedUrl(
|
||||
href={slugSelector(
|
||||
`/${section ? section : ""}/page/${currentPage + 1}`,
|
||||
lang
|
||||
)}
|
||||
class="rounded px-2 py-1.5 text-dark hover:bg-theme-light dark:text-darkmode-dark dark:hover:bg-darkmode-theme-light"
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user