mirror of
https://github.com/10h30/astroplate.git
synced 2026-07-19 14:43:29 +09:00
slugSelector fn added
This commit is contained in:
@@ -4,15 +4,14 @@ import Share from "@/components/Share.astro";
|
||||
import config from "@/config/config.json";
|
||||
import Disqus from "@/helpers/Disqus";
|
||||
import { getSinglePage } from "@/lib/contentParser.astro";
|
||||
import { slugSelector } from "@/lib/languageParser.astro";
|
||||
import dateFormat from "@/lib/utils/dateFormat";
|
||||
import { constructUrl } from "@/lib/utils/i18nUtils";
|
||||
import similarItems from "@/lib/utils/similarItems";
|
||||
import { humanize, markdownify, slugify } from "@/lib/utils/textConverter";
|
||||
import type { ContentEntryMap } from "astro:content";
|
||||
import { FaRegClock, FaRegFolder, FaRegUserCircle } from "react-icons/fa";
|
||||
import ImageMod from "./components/ImageMod.astro";
|
||||
const { default_language, default_language_in_path } = config.settings;
|
||||
const { trailing_slash } = config.site;
|
||||
const { default_language } = config.settings;
|
||||
|
||||
const COLLECTION_FOLDER = "blog";
|
||||
const { post } = Astro.props;
|
||||
@@ -24,29 +23,11 @@ if (!lang) {
|
||||
|
||||
const posts = await getSinglePage(
|
||||
COLLECTION_FOLDER,
|
||||
lang as keyof ContentEntryMap,
|
||||
lang as keyof ContentEntryMap
|
||||
);
|
||||
const similarPosts = similarItems(post, posts);
|
||||
const { Content } = await post.render();
|
||||
const { title, description, author, categories, image, date, tags } = post.data;
|
||||
|
||||
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,
|
||||
);
|
||||
}
|
||||
};
|
||||
---
|
||||
|
||||
<section class="section pt-7">
|
||||
@@ -70,7 +51,7 @@ const constructLocalizedUrl = (url: string) => {
|
||||
<h1 set:html={markdownify(title)} class="h2 mb-4" />
|
||||
<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>
|
||||
@@ -80,9 +61,7 @@ const constructLocalizedUrl = (url: string) => {
|
||||
{
|
||||
categories.map((category: string, index: number) => (
|
||||
<a
|
||||
href={constructLocalizedUrl(
|
||||
`/categories/${slugify(category)}`,
|
||||
)}
|
||||
href={slugSelector(`/categories/${slugify(category)}`, lang)}
|
||||
>
|
||||
{humanize(category)}
|
||||
{index !== categories.length - 1 && ","}
|
||||
@@ -107,7 +86,7 @@ const constructLocalizedUrl = (url: string) => {
|
||||
<li class="inline-block">
|
||||
<a
|
||||
class="m-1 block rounded bg-theme-light px-3 py-1 hover:bg-primary hover:text-white dark:bg-darkmode-theme-light dark:hover:bg-darkmode-primary dark:hover:text-dark"
|
||||
href={constructLocalizedUrl(`/tags/${slugify(tag)}`)}
|
||||
href={slugSelector(`/tags/${slugify(tag)}`, lang)}
|
||||
>
|
||||
{humanize(tag)}
|
||||
</a>
|
||||
|
||||
@@ -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"
|
||||
>
|
||||
|
||||
@@ -3,17 +3,10 @@ import Logo from "@/components/Logo.astro";
|
||||
import Social from "@/components/Social.astro";
|
||||
import config from "@/config/config.json";
|
||||
import social from "@/config/social.json";
|
||||
import {
|
||||
constructUrl,
|
||||
getLangFromUrl,
|
||||
getTranslations,
|
||||
} from "@/lib/utils/i18nUtils";
|
||||
import { slugSelector } from "@/lib/languageParser.astro";
|
||||
import { getLangFromUrl, getTranslations } from "@/lib/utils/i18nUtils";
|
||||
import { markdownify } from "@/lib/utils/textConverter";
|
||||
import type { ContentEntryMap } from "astro:content";
|
||||
import { getRelativeLocaleUrl } from "astro:i18n";
|
||||
|
||||
const { default_language, default_language_in_path } = config.settings;
|
||||
const { trailing_slash } = config.site;
|
||||
|
||||
const lang = getLangFromUrl(Astro.url);
|
||||
const menu = await getTranslations(lang as keyof ContentEntryMap);
|
||||
@@ -21,19 +14,6 @@ let footer: any = [];
|
||||
if (menu) {
|
||||
footer = menu.footer;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
---
|
||||
|
||||
<footer class="bg-theme-light dark:bg-darkmode-theme-light">
|
||||
@@ -47,7 +27,7 @@ const constructLocalizedUrl = (url: string) => {
|
||||
{
|
||||
footer.map((menu: any) => (
|
||||
<li class="m-3 inline-block">
|
||||
<a href={constructLocalizedUrl(menu.url)}>{menu.name}</a>
|
||||
<a href={slugSelector(menu.url, lang)}>{menu.name}</a>
|
||||
</li>
|
||||
))
|
||||
}
|
||||
|
||||
@@ -4,11 +4,8 @@ import ThemeSwitcher from "@/components/ThemeSwitcher.astro";
|
||||
import config from "@/config/config.json";
|
||||
import languages from "@/config/language.json";
|
||||
import LanguageSwitcher from "@/helpers/LanguageSwitcher";
|
||||
import {
|
||||
constructUrl,
|
||||
getLangFromUrl,
|
||||
getTranslations,
|
||||
} from "@/lib/utils/i18nUtils";
|
||||
import { slugSelector } from "@/lib/languageParser.astro";
|
||||
import { getLangFromUrl, getTranslations } from "@/lib/utils/i18nUtils";
|
||||
import type { ContentEntryMap } from "astro:content";
|
||||
import { IoSearch } from "react-icons/io5";
|
||||
|
||||
@@ -16,30 +13,14 @@ let lang = getLangFromUrl(Astro.url);
|
||||
const menu = await getTranslations(lang as keyof ContentEntryMap);
|
||||
|
||||
const { navigation_button, settings } = config;
|
||||
const { default_language, default_language_in_path } = config.settings;
|
||||
const { trailing_slash } = config.site;
|
||||
const { default_language } = config.settings;
|
||||
const { pathname } = Astro.url;
|
||||
const { get_started } = await getTranslations(lang as keyof ContentEntryMap);
|
||||
|
||||
// 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);
|
||||
}
|
||||
};
|
||||
---
|
||||
|
||||
<header class={`header z-30 ${settings.sticky_header && "sticky top-0"}`}>
|
||||
@@ -79,8 +60,8 @@ const constructLocalizedUrl = (url: string) => {
|
||||
<span
|
||||
class={`nav-link inline-flex items-center ${
|
||||
menu.children
|
||||
?.map(({ url }: { url: any }) =>
|
||||
constructLocalizedUrl(url)
|
||||
?.map(({ url }: { url: string }) =>
|
||||
slugSelector(url, lang)
|
||||
)
|
||||
.includes(pathname)
|
||||
? "active"
|
||||
@@ -96,11 +77,10 @@ const constructLocalizedUrl = (url: string) => {
|
||||
{menu.children?.map((child: any) => (
|
||||
<li class="nav-dropdown-item">
|
||||
<a
|
||||
href={constructLocalizedUrl(child.url)}
|
||||
href={slugSelector(child.url, lang)}
|
||||
aria-label={child.name}
|
||||
class={`nav-dropdown-link block ${
|
||||
pathname === constructLocalizedUrl(child.url) &&
|
||||
"active"
|
||||
pathname === slugSelector(child.url, lang) && "active"
|
||||
}`}
|
||||
>
|
||||
{child.name}
|
||||
@@ -112,9 +92,9 @@ const constructLocalizedUrl = (url: string) => {
|
||||
) : (
|
||||
<li class="nav-item">
|
||||
<a
|
||||
href={constructLocalizedUrl(menu.url)}
|
||||
href={slugSelector(menu.url, lang)}
|
||||
class={`nav-link block ${
|
||||
pathname === constructLocalizedUrl(menu.url) && "active"
|
||||
pathname === slugSelector(menu.url, lang) && "active"
|
||||
}`}
|
||||
>
|
||||
{menu.name}
|
||||
|
||||
@@ -1,25 +1,10 @@
|
||||
---
|
||||
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 { humanize } from "@/lib/utils/textConverter";
|
||||
const { default_language, default_language_in_path } = config.settings;
|
||||
const { trailing_slash } = config.site;
|
||||
|
||||
const { tags, categories, allCategories } = Astro.props;
|
||||
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 class="lg:col-4">
|
||||
@@ -37,7 +22,7 @@ const constructLocalizedUrl = (url: string) => {
|
||||
<li>
|
||||
<a
|
||||
class="flex justify-between hover:text-primary dark:hover:text-darkmode-primary"
|
||||
href={constructLocalizedUrl(`/categories/${category}`)}
|
||||
href={slugSelector(`/categories/${category}`, lang)}
|
||||
>
|
||||
{humanize(category)} <span>({count})</span>
|
||||
</a>
|
||||
@@ -59,7 +44,7 @@ const constructLocalizedUrl = (url: string) => {
|
||||
<li class="inline-block">
|
||||
<a
|
||||
class="m-1 block rounded bg-white px-3 py-1 hover:bg-primary hover:text-white dark:bg-darkmode-body dark:hover:bg-darkmode-primary dark:hover:text-dark"
|
||||
href={constructLocalizedUrl(`/tags/${tag}`)}
|
||||
href={slugSelector(`/tags/${tag}`, lang)}
|
||||
>
|
||||
{humanize(tag)}
|
||||
</a>
|
||||
|
||||
Reference in New Issue
Block a user