Migrate to limax for slugify (CKJ languages bug)
This commit is contained in:
@ -18,8 +18,8 @@
|
|||||||
"@tailwindcss/typography": "^0.5.4",
|
"@tailwindcss/typography": "^0.5.4",
|
||||||
"astro": "^1.0.0",
|
"astro": "^1.0.0",
|
||||||
"astro-icon": "^0.7.3",
|
"astro-icon": "^0.7.3",
|
||||||
|
"limax": "^3.0.0",
|
||||||
"reading-time": "^1.5.0",
|
"reading-time": "^1.5.0",
|
||||||
"slugify": "^1.6.5",
|
|
||||||
"subfont": "^6.9.0"
|
"subfont": "^6.9.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
---
|
---
|
||||||
import BlogListItem from "~/components/widgets/BlogListItem.astro";
|
import BlogListItem from "~/components/widgets/BlogListItem.astro";
|
||||||
|
|
||||||
const { page } = Astro.props;
|
const { posts } = Astro.props;
|
||||||
---
|
---
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
{
|
{
|
||||||
page.data.map((post) => (
|
posts.map((post) => (
|
||||||
<li class="mb-10 md:mb-16">
|
<li class="mb-10 md:mb-16">
|
||||||
<BlogListItem post={post} />
|
<BlogListItem post={post} />
|
||||||
</li>
|
</li>
|
||||||
|
@ -31,9 +31,9 @@ const meta = {
|
|||||||
<Layout meta={meta}>
|
<Layout meta={meta}>
|
||||||
<Fragment slot="title">
|
<Fragment slot="title">
|
||||||
News and step-by-step guides about
|
News and step-by-step guides about
|
||||||
<span class="bg-clip-text text-transparent bg-gradient-to-r from-blue-500 to-pink-500">AstroWind
|
<span class="bg-clip-text text-transparent bg-gradient-to-r from-primary-500 to-secondary-500">AstroWind
|
||||||
</span>
|
</span>
|
||||||
</Fragment>
|
</Fragment>
|
||||||
<BlogList page={page} />
|
<BlogList posts={page.data} />
|
||||||
<Pagination prevUrl={page.url.prev} nextUrl={page.url.next} />
|
<Pagination prevUrl={page.url.prev} nextUrl={page.url.next} />
|
||||||
</Layout>
|
</Layout>
|
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
import { SITE, BLOG } from "~/config.mjs";
|
import { SITE, BLOG } from "~/config.mjs";
|
||||||
import { getCanonical, getPermalink } from "~/utils/permalinks";
|
import { getCanonical, getPermalink, cleanSlug, BLOG_BASE } from "~/utils/permalinks";
|
||||||
import { fetchPosts } from "~/utils/fetchPosts";
|
import { fetchPosts } from "~/utils/fetchPosts";
|
||||||
import { findImage } from "~/utils/findImage";
|
import { findImage } from "~/utils/findImage";
|
||||||
import Layout from "~/layouts/PageLayout.astro";
|
import Layout from "~/layouts/PageLayout.astro";
|
||||||
@ -13,7 +13,7 @@ export async function getStaticPaths() {
|
|||||||
const posts = await fetchPosts();
|
const posts = await fetchPosts();
|
||||||
|
|
||||||
return posts.map((post) => ({
|
return posts.map((post) => ({
|
||||||
params: { slug: post.slug, blog: BLOG.postsWithoutBlogSlug ? undefined : BLOG?.slug || undefined },
|
params: { slug: cleanSlug(post.slug), blog: BLOG.postsWithoutBlogSlug ? undefined : BLOG_BASE || undefined },
|
||||||
props: { post },
|
props: { post },
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import { fetchPosts } from "~/utils/fetchPosts";
|
|||||||
import Layout from "~/layouts/BlogLayout.astro";
|
import Layout from "~/layouts/BlogLayout.astro";
|
||||||
import BlogList from "~/components/widgets/BlogList.astro";
|
import BlogList from "~/components/widgets/BlogList.astro";
|
||||||
import Pagination from "~/components/widgets/Pagination.astro";
|
import Pagination from "~/components/widgets/Pagination.astro";
|
||||||
import { getCanonical, getPermalink, getSlug, CATEGORY_BASE } from "~/utils/permalinks";
|
import { getCanonical, getPermalink, cleanSlug, CATEGORY_BASE } from "~/utils/permalinks";
|
||||||
|
|
||||||
|
|
||||||
export async function getStaticPaths({ paginate }) {
|
export async function getStaticPaths({ paginate }) {
|
||||||
@ -20,7 +20,7 @@ export async function getStaticPaths({ paginate }) {
|
|||||||
|
|
||||||
return Array.from(categories).map((category) => (
|
return Array.from(categories).map((category) => (
|
||||||
paginate(posts.filter((post) => typeof post.category === "string" && category === post.category.toLowerCase()), {
|
paginate(posts.filter((post) => typeof post.category === "string" && category === post.category.toLowerCase()), {
|
||||||
params: { category: getSlug(category), categories: CATEGORY_BASE || undefined },
|
params: { category: cleanSlug(category), categories: CATEGORY_BASE || undefined },
|
||||||
pageSize: BLOG.postsPerPage,
|
pageSize: BLOG.postsPerPage,
|
||||||
props: { category }
|
props: { category }
|
||||||
})
|
})
|
||||||
@ -42,6 +42,6 @@ const meta = {
|
|||||||
<Fragment slot="title">
|
<Fragment slot="title">
|
||||||
Category: {category}
|
Category: {category}
|
||||||
</Fragment>
|
</Fragment>
|
||||||
<BlogList page={page} />
|
<BlogList posts={page.data} />
|
||||||
<Pagination prevUrl={page.url.prev} nextUrl={page.url.next} />
|
<Pagination prevUrl={page.url.prev} nextUrl={page.url.next} />
|
||||||
</Layout>
|
</Layout>
|
@ -4,7 +4,7 @@ import { fetchPosts } from "~/utils/fetchPosts";
|
|||||||
import Layout from "~/layouts/BlogLayout.astro";
|
import Layout from "~/layouts/BlogLayout.astro";
|
||||||
import BlogList from "~/components/widgets/BlogList.astro";
|
import BlogList from "~/components/widgets/BlogList.astro";
|
||||||
import Pagination from "~/components/widgets/Pagination.astro";
|
import Pagination from "~/components/widgets/Pagination.astro";
|
||||||
import { getCanonical, getPermalink, getSlug, TAG_BASE } from "~/utils/permalinks";
|
import { getCanonical, getPermalink, cleanSlug, TAG_BASE } from "~/utils/permalinks";
|
||||||
|
|
||||||
|
|
||||||
export async function getStaticPaths({ paginate }) {
|
export async function getStaticPaths({ paginate }) {
|
||||||
@ -19,7 +19,7 @@ export async function getStaticPaths({ paginate }) {
|
|||||||
|
|
||||||
return Array.from(tags).map((tag) => (
|
return Array.from(tags).map((tag) => (
|
||||||
paginate(posts.filter((post) => Array.isArray(post.tags) && post.tags.includes(tag)), {
|
paginate(posts.filter((post) => Array.isArray(post.tags) && post.tags.includes(tag)), {
|
||||||
params: { tag: getSlug(tag), tags: TAG_BASE || undefined },
|
params: { tag: cleanSlug(tag), tags: TAG_BASE || undefined },
|
||||||
pageSize: BLOG.postsPerPage,
|
pageSize: BLOG.postsPerPage,
|
||||||
props: { tag },
|
props: { tag },
|
||||||
})
|
})
|
||||||
@ -41,6 +41,6 @@ const meta = {
|
|||||||
<Fragment slot="title">
|
<Fragment slot="title">
|
||||||
Tag: {tag}
|
Tag: {tag}
|
||||||
</Fragment>
|
</Fragment>
|
||||||
<BlogList page={page} />
|
<BlogList posts={page.data} />
|
||||||
<Pagination prevUrl={page.url.prev} nextUrl={page.url.next} />
|
<Pagination prevUrl={page.url.prev} nextUrl={page.url.next} />
|
||||||
</Layout>
|
</Layout>
|
@ -1,4 +1,4 @@
|
|||||||
import slugify from 'slugify'
|
import slugify from 'limax';
|
||||||
import { SITE, BLOG } from "~/config.mjs";
|
import { SITE, BLOG } from "~/config.mjs";
|
||||||
|
|
||||||
const trim = (str, ch) => {
|
const trim = (str, ch) => {
|
||||||
@ -10,16 +10,16 @@ const trim = (str, ch) => {
|
|||||||
return (start > 0 || end < str.length) ? str.substring(start, end) : str;
|
return (start > 0 || end < str.length) ? str.substring(start, end) : str;
|
||||||
}
|
}
|
||||||
|
|
||||||
const trimSlash = (s) => trim(s, "/");
|
const trimSlash = (s) => trim(trim(s, "/"));
|
||||||
const createPath = (...params) => "/" + params.filter((el) => !!el).join("/")
|
const createPath = (...params) => "/" + params.filter((el) => !!el).join("/")
|
||||||
|
|
||||||
const baseUrl = trimSlash(SITE.baseUrl);
|
const baseUrl = trimSlash(SITE.baseUrl);
|
||||||
|
|
||||||
export const BLOG_BASE = slugify(trimSlash(BLOG.slug), { lower: true });
|
export const cleanSlug = (text) => slugify(trimSlash(text));
|
||||||
export const CATEGORY_BASE = slugify(trim(BLOG?.category?.slug), { lower: true });
|
|
||||||
export const TAG_BASE = slugify(trim(BLOG?.tag?.slug), { lower: true });
|
|
||||||
|
|
||||||
const cleanSlug = (slug) => trimSlash(slug);
|
export const BLOG_BASE = cleanSlug(BLOG.slug);
|
||||||
|
export const CATEGORY_BASE = cleanSlug(BLOG?.category?.slug);
|
||||||
|
export const TAG_BASE = cleanSlug(BLOG?.tag?.slug);
|
||||||
|
|
||||||
export const getCanonical = (path = "") => new URL(path, SITE.domain);
|
export const getCanonical = (path = "") => new URL(path, SITE.domain);
|
||||||
|
|
||||||
@ -47,5 +47,3 @@ export const getHomePermalink = () => {
|
|||||||
const permalink = getPermalink();
|
const permalink = getPermalink();
|
||||||
return permalink !== "/" ? permalink + "/" : permalink;
|
return permalink !== "/" ? permalink + "/" : permalink;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getSlug = (text) => slugify(text);
|
|
Reference in New Issue
Block a user