diff --git a/src/env.d.ts b/src/env.d.ts index acef35f..bcb8e36 100644 --- a/src/env.d.ts +++ b/src/env.d.ts @@ -1,2 +1,5 @@ /// /// +interface ImportMetaEnv { + readonly CONTENT_API_KEY: string; +} \ No newline at end of file diff --git a/src/library/ghost.ts b/src/library/ghost.ts new file mode 100644 index 0000000..21431b7 --- /dev/null +++ b/src/library/ghost.ts @@ -0,0 +1,7 @@ +import GhostContentAPI from '@tryghost/content-api' + +export const ghostClient = new GhostContentAPI({ + url: 'https://blog.ghost.sudovanilla.org', + key: import.meta.env.CONTENT_API_KEY, + version: 'v5.0', +}) \ No newline at end of file diff --git a/src/pages/blog/[...slug].astro b/src/pages/blog/[...slug].astro index 048630c..5d8680c 100644 --- a/src/pages/blog/[...slug].astro +++ b/src/pages/blog/[...slug].astro @@ -2,34 +2,60 @@ // Layout import Default from "@layouts/Default.astro"; -// Components -import Hero from "@components/Hero.astro"; -import Heading from "@components/Heading.astro"; -import Posts from "@components/blog/posts.astro"; -import LargeCard from "@components/Feature.astro"; -import {Zorn} from "@minpluto/zorn" +// Fetch Post (Ghost) +import { ghostClient } from "@library/ghost"; + +export async function getStaticPaths() { + const posts = await ghostClient.posts + .browse({ + limit: "all", + }) + .catch((err) => { + console.error(err); + }); + + return posts.map((post) => { + return { + params: { + slug: post.slug, + }, + props: { + post: post, + }, + }; + }); +} + +const { post } = Astro.props; +export const prerender = true; // Icons import { Calendar } from "@iconoir/vue"; const Id = Astro.url.href.split("?postid=").pop(); -const GhostPostFetch = 'https://blog.ghost.sudovanilla.org/ghost/api/content/posts/' + Id + '/?key=bef2ed15d9e38f7703be9412b3' +const GhostPostFetch = + "https://blog.ghost.sudovanilla.org/ghost/api/content/posts/" + + Id + + "/?key=bef2ed15d9e38f7703be9412b3"; const GhostPostResponse = await fetch(GhostPostFetch); const GhostPost = await GhostPostResponse.json(); --- -
- -

{GhostPost.posts[0].title}

+ +

{post.title}

- {new Date(GhostPost.posts[0].published_at).toLocaleDateString()} + {new Date(post.published_at).toLocaleDateString()}

- +
diff --git a/src/pages/blog/index.astro b/src/pages/blog/index.astro index 5d3e27a..10c4ecd 100644 --- a/src/pages/blog/index.astro +++ b/src/pages/blog/index.astro @@ -3,11 +3,7 @@ import Default from "@layouts/Default.astro"; // Components -import Hero from "@components/Hero.astro"; -import Heading from "@components/Heading.astro"; import Posts from "@components/blog/posts.astro"; -import LargeCard from "@components/Feature.astro"; -import {Zorn} from "@minpluto/zorn" // List Posts const GhostFetch = 'https://blog.ghost.sudovanilla.org/ghost/api/content/posts/?key=bef2ed15d9e38f7703be9412b3' @@ -20,18 +16,7 @@ import { BookmarkBook, ReportColumns } from "@iconoir/vue"; -