mirror of
https://github.com/ProjectSegfault/website
synced 2026-03-27 17:17:54 +05:30
fix blog (#115)
This commit is contained in:
@@ -41,6 +41,9 @@ The website has the following **mandatory** environment variables
|
||||
| :----------------- | :--------------------------------------------- |
|
||||
| GHOST_URL | Your Ghost CMS URL |
|
||||
| GHOST_API_KEY | Your Ghost CMS API key |
|
||||
| GHOST_ALLPOSTS_URL | Your URL for all ghost posts, see below |
|
||||
| KUMA_URL | Your Uptime Kuma announcements URL |
|
||||
| ORIGIN | Your domain |
|
||||
| ADDRESS_HEADER | Header used to retrieve client IP (Caddy only) |
|
||||
|
||||
> GHOST_ALLPOSTS_URL should be of the form `https://GHOST_URL/ghost/api/content/posts/?key=GHOST_API_KEY&include=authors,tags&limit=all&formats=html,plaintext`
|
||||
@@ -58,7 +58,10 @@ const updateMap = async () => {
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetchGhost("posts");
|
||||
const res = await axios(env.GHOST_ALLPOSTS_URL, {
|
||||
httpsAgent: agent,
|
||||
timeout: 10000
|
||||
});
|
||||
|
||||
if (res.status === 200) {
|
||||
blogPosts.set(res.data);
|
||||
|
||||
@@ -13,9 +13,7 @@
|
||||
text: "Wiki",
|
||||
external: true
|
||||
},
|
||||
// Temporary workaround.
|
||||
//{ href: "/blog", text: "Blog" },
|
||||
{ href: "https://blog.projectsegfau.lt", text: "Blog" },
|
||||
{ href: "/blog", text: "Blog" },
|
||||
|
||||
{ href: "/donate", text: "Donate" },
|
||||
{ href: "/contact", text: "Contact" },
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
import type { PageServerLoad } from "./$types";
|
||||
import fetchGhost from "../fetchGhost";
|
||||
import type { PageServerLoad, PageServerLoadEvent } from "./$types";
|
||||
import { blogPosts } from "../../../stores";
|
||||
import { get } from "svelte/store";
|
||||
|
||||
export const load = (async ({ params, fetch }) => {
|
||||
const data = await fetchGhost("posts/slug/" + params.title);
|
||||
// yes this was made by gitbub copilot
|
||||
|
||||
const allPosts = get(blogPosts);
|
||||
const meta = {
|
||||
title: !allPosts.error ? data.posts[0].title : ""
|
||||
};
|
||||
const load: PageServerLoad = async ({ params }: PageServerLoadEvent) => {
|
||||
const allPosts = get(blogPosts) as { error?: boolean; posts?: any[] };
|
||||
let post: any = {};
|
||||
let title = "";
|
||||
if (allPosts && !allPosts.error && Array.isArray(allPosts.posts)) {
|
||||
post = allPosts.posts.find((p: any) => p.slug === params.title) || {};
|
||||
title = post.title || "";
|
||||
}
|
||||
return {
|
||||
post,
|
||||
allPosts,
|
||||
title
|
||||
};
|
||||
};
|
||||
|
||||
return {
|
||||
post: !allPosts.error ? data.posts[0] : {},
|
||||
allPosts: allPosts,
|
||||
...meta
|
||||
};
|
||||
}) satisfies PageServerLoad;
|
||||
export { load };
|
||||
|
||||
Reference in New Issue
Block a user