update
This commit is contained in:
parent
68ae0281ba
commit
8ca1b417c4
@ -112,7 +112,6 @@ export const scoreComponent = writable(<boolean>false);
|
|||||||
|
|
||||||
export const goBackToPostId = writable(<string>"");
|
export const goBackToPostId = writable(<string>"");
|
||||||
export const strategyId = writable(<string>"");
|
export const strategyId = writable(<string>"");
|
||||||
export const articleId = writable(<string>"");
|
|
||||||
|
|
||||||
export const traded = writable(<boolean>false);
|
export const traded = writable(<boolean>false);
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,6 @@ export const load = async ({locals}) => {
|
|||||||
|
|
||||||
// make the POST request to the endpoint
|
// make the POST request to the endpoint
|
||||||
const output = await pb.collection("articles").getFullList({
|
const output = await pb.collection("articles").getFullList({
|
||||||
expand: "user",
|
|
||||||
sort: "-created",
|
sort: "-created",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,16 +1,26 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { articleId, numberOfUnreadNotification } from "$lib/store";
|
import { numberOfUnreadNotification } from "$lib/store";
|
||||||
import { goto } from "$app/navigation";
|
|
||||||
import { getImageURL } from "$lib/utils";
|
import { getImageURL } from "$lib/utils";
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
|
|
||||||
function blogSelector(state: string) {
|
|
||||||
$articleId = state;
|
|
||||||
goto("/blog/article/" + $articleId);
|
|
||||||
}
|
|
||||||
|
|
||||||
let allBlogPosts = data?.getAllBlogPost;
|
let allBlogPosts = data?.getAllBlogPost;
|
||||||
|
|
||||||
|
function convertToSlug(title) {
|
||||||
|
// Remove punctuation and special characters
|
||||||
|
const cleanedTitle = title
|
||||||
|
.replace(/[.,?!:"]/g, "") // Remove punctuation
|
||||||
|
.replace(/\s+/g, " ") // Replace multiple spaces with a single space
|
||||||
|
.trim(); // Remove leading and trailing spaces
|
||||||
|
|
||||||
|
// Convert to lowercase, split by spaces, and join with hyphens
|
||||||
|
const words = cleanedTitle.toLowerCase().split(" ");
|
||||||
|
const truncatedWords = words;
|
||||||
|
|
||||||
|
// Join with hyphens and add ellipsis if necessary
|
||||||
|
const slug = truncatedWords.join("-");
|
||||||
|
return slug;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
@ -66,7 +76,7 @@
|
|||||||
class="flex flex-col overflow-hidden rounded-lg shadow-lg sm:hover:shadow-2xl border border-gray-600"
|
class="flex flex-col overflow-hidden rounded-lg shadow-lg sm:hover:shadow-2xl border border-gray-600"
|
||||||
>
|
>
|
||||||
<div class="flex-shrink-0">
|
<div class="flex-shrink-0">
|
||||||
<a href={"/blog/article/" + item?.id}
|
<a href={"/blog/article/" + convertToSlug(item?.title)}
|
||||||
><img
|
><img
|
||||||
class="h-48 w-full object-cover"
|
class="h-48 w-full object-cover"
|
||||||
src={getImageURL(
|
src={getImageURL(
|
||||||
@ -83,7 +93,9 @@
|
|||||||
class="flex flex-1 flex-col justify-between bg-table p-4 xs:p-5 sm:p-6"
|
class="flex flex-1 flex-col justify-between bg-table p-4 xs:p-5 sm:p-6"
|
||||||
>
|
>
|
||||||
<div class="flex-1">
|
<div class="flex-1">
|
||||||
<a href={"/blog/article/" + item?.id} class="mt-2 block"
|
<a
|
||||||
|
href={"/blog/article/" + convertToSlug(item?.title)}
|
||||||
|
class="mt-2 block"
|
||||||
><h2 class="text-xl font-semibold text-white">
|
><h2 class="text-xl font-semibold text-white">
|
||||||
{item?.title}
|
{item?.title}
|
||||||
</h2>
|
</h2>
|
||||||
|
|||||||
@ -1,21 +1,36 @@
|
|||||||
|
function convertToSlug(title) {
|
||||||
|
// Remove punctuation and special characters
|
||||||
|
const cleanedTitle = title
|
||||||
|
.replace(/[.,?!:"]/g, "") // Remove punctuation
|
||||||
|
.replace(/\s+/g, " ") // Replace multiple spaces with a single space
|
||||||
|
.trim(); // Remove leading and trailing spaces
|
||||||
|
|
||||||
|
// Convert to lowercase, split by spaces, and join with hyphens
|
||||||
|
const words = cleanedTitle.toLowerCase().split(" ");
|
||||||
|
const slug = words.join("-");
|
||||||
|
return slug;
|
||||||
|
}
|
||||||
|
|
||||||
export const load = async ({ locals, params }) => {
|
export const load = async ({ locals, params }) => {
|
||||||
const { pb } = locals;
|
const { pb } = locals;
|
||||||
|
|
||||||
const getArticle = async () => {
|
const getArticle = async () => {
|
||||||
|
// Make the POST request to the endpoint
|
||||||
|
const output = await pb.collection("articles").getFullList({
|
||||||
const output = await pb
|
sort: "-created",
|
||||||
?.collection("articles")
|
});
|
||||||
?.getOne(params?.slug, { expand: "user" });
|
|
||||||
|
|
||||||
|
|
||||||
return output;
|
// Find the matching article based on params.slug
|
||||||
|
const matchingArticle = output?.find(
|
||||||
|
(article) => convertToSlug(article?.title) === params?.slug
|
||||||
|
);
|
||||||
|
|
||||||
|
return matchingArticle;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Make sure to return a promise
|
// Make sure to return a promise
|
||||||
return {
|
return {
|
||||||
getArticle: await getArticle(),
|
getArticle: await getArticle(),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user