fix strapi urls and shit
All checks were successful
Deployment / Deploy website (push) Successful in 2m32s
Deployment / Deploy strapi (push) Successful in 3m5s

This commit is contained in:
Benjamin Palko 2025-05-06 12:31:44 -04:00
parent 0e94cb95ca
commit 0eb91d67dd
8 changed files with 92 additions and 66 deletions

View file

@ -1,39 +1,31 @@
import { env } from '$env/dynamic/private';
import { strapi } from '@strapi/client';
import type { PageServerLoad } from './$types';
import { error } from "@sveltejs/kit";
import type { PageServerLoad } from "./$types";
export const load: PageServerLoad = async ({ locals }) => {
const { Strapi } = locals;
const { strapi } = locals;
const client = strapi({
baseURL: Strapi.url,
auth: env.STRAPI_TOKEN
});
try {
const { data, meta } = await strapi.Blogs();
const blogs = client.collection('blogs');
const { data, meta } = await blogs.find({
populate: ['Header', 'Topics']
});
return {
strapi: {
url: Strapi.url
},
posts: data.map((post) => ({
id: post.documentId,
image: {
url: `${Strapi.url}${post.Header.formats.medium.url}`,
alt: post.Header.alternativeText
},
title: post.Title,
body: post.Body,
topics: post.Topics.map((topic: { id: string; Topic: string }) => ({
id: topic.id,
name: topic.Topic
return {
posts: data.map((post) => ({
id: post.documentId,
image: {
url: post.Header.formats.medium.url,
alt: post.Header.alternativeText,
},
title: post.Title,
body: post.Body,
topics: post.Topics.map((topic: { id: string; Topic: string }) => ({
id: topic.id,
name: topic.Topic,
})),
published: post.publishedAt,
})),
published: post.publishedAt
})),
meta
};
meta,
};
} catch (err) {
console.log("Uh-oh!");
error(500, err.message);
}
};

View file

@ -1,4 +1,5 @@
<script lang="ts">
import { env } from '$env/dynamic/public';
import BlogCard from '$lib/components/BlogCard.svelte';
import type { PageProps } from './$types';
@ -15,7 +16,7 @@
{#each posts as post (post.id)}
<BlogCard
id={post.id}
img={post.image.url}
img={`${env.PUBLIC_STRAPI_HOST}${post.image.url}`}
img-alt={post.image.alt}
title={post.title}
published={post.published}

View file

@ -1,37 +1,27 @@
import { env } from '$env/dynamic/private';
import { strapi } from '@strapi/client';
import type { PageServerLoad } from './$types';
import type { PageServerLoad } from "./$types";
export const load: PageServerLoad = async ({ locals, params }) => {
const { slug } = params;
const { Strapi } = locals;
const { strapi } = locals;
const client = strapi({
baseURL: Strapi.url,
auth: env.STRAPI_TOKEN
});
const blogs = client.collection('blogs');
const { data: post, meta } = await blogs.findOne(slug, {
populate: ['Header', 'Topics']
});
const { data: post, meta } = await strapi.Blog(slug);
return {
post: {
id: post.documentId,
image: {
url: `${Strapi.url}${post.Header.url}`,
alt: post.Header.alternativeText
url: post.Header.url,
alt: post.Header.alternativeText,
caption: post.Header.caption,
},
title: post.Title,
body: post.Body,
topics: post.Topics.map((topic: { id: string; Topic: string }) => ({
id: topic.id,
name: topic.Topic
name: topic.Topic,
})),
published: post.publishedAt
published: post.publishedAt,
},
meta
meta,
};
};

View file

@ -1,8 +1,8 @@
<script lang="ts">
import dayjs from 'dayjs';
import type { PageProps } from './$types';
import { compile } from 'mdsvex';
import { env } from '$env/dynamic/public';
import dayjs from 'dayjs';
import { compile } from 'mdsvex';
import type { PageProps } from './$types';
let { data }: PageProps = $props();