Properly integrate Ghost API as followed by Astro documentation
This commit is contained in:
parent
b1f0116c6a
commit
65ad06a7c0
6 changed files with 53 additions and 46 deletions
3
src/env.d.ts
vendored
3
src/env.d.ts
vendored
|
@ -1,2 +1,5 @@
|
||||||
/// <reference path="../.astro/types.d.ts" />
|
/// <reference path="../.astro/types.d.ts" />
|
||||||
/// <reference types="astro/client" />
|
/// <reference types="astro/client" />
|
||||||
|
interface ImportMetaEnv {
|
||||||
|
readonly CONTENT_API_KEY: string;
|
||||||
|
}
|
7
src/library/ghost.ts
Normal file
7
src/library/ghost.ts
Normal file
|
@ -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',
|
||||||
|
})
|
|
@ -2,34 +2,60 @@
|
||||||
// Layout
|
// Layout
|
||||||
import Default from "@layouts/Default.astro";
|
import Default from "@layouts/Default.astro";
|
||||||
|
|
||||||
// Components
|
// Fetch Post (Ghost)
|
||||||
import Hero from "@components/Hero.astro";
|
import { ghostClient } from "@library/ghost";
|
||||||
import Heading from "@components/Heading.astro";
|
|
||||||
import Posts from "@components/blog/posts.astro";
|
export async function getStaticPaths() {
|
||||||
import LargeCard from "@components/Feature.astro";
|
const posts = await ghostClient.posts
|
||||||
import {Zorn} from "@minpluto/zorn"
|
.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
|
// Icons
|
||||||
import { Calendar } from "@iconoir/vue";
|
import { Calendar } from "@iconoir/vue";
|
||||||
|
|
||||||
const Id = Astro.url.href.split("?postid=").pop();
|
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 GhostPostResponse = await fetch(GhostPostFetch);
|
||||||
const GhostPost = await GhostPostResponse.json();
|
const GhostPost = await GhostPostResponse.json();
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
||||||
<Default MobileTitle="Blog" NoSubHeader>
|
<Default MobileTitle="Blog" NoSubHeader>
|
||||||
<slot slot="body">
|
<slot slot="body">
|
||||||
<div class="blog-post">
|
<div class="blog-post">
|
||||||
<img width="100%" class="blog-banner" src={GhostPost.posts[0].custom_excerpt} />
|
<img
|
||||||
<h1>{GhostPost.posts[0].title}</h1>
|
width="100%"
|
||||||
|
class="blog-banner"
|
||||||
|
src={post.custom_excerpt}
|
||||||
|
/>
|
||||||
|
<h1>{post.title}</h1>
|
||||||
<p id="date">
|
<p id="date">
|
||||||
<Calendar />
|
<Calendar />
|
||||||
{new Date(GhostPost.posts[0].published_at).toLocaleDateString()}
|
{new Date(post.published_at).toLocaleDateString()}
|
||||||
</p>
|
</p>
|
||||||
<div class="blog-post-content">
|
<div class="blog-post-content">
|
||||||
<Fragment set:html={GhostPost.posts[0].html}/>
|
<Fragment set:html={post.html} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</slot>
|
</slot>
|
||||||
|
|
|
@ -3,11 +3,7 @@
|
||||||
import Default from "@layouts/Default.astro";
|
import Default from "@layouts/Default.astro";
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
import Hero from "@components/Hero.astro";
|
|
||||||
import Heading from "@components/Heading.astro";
|
|
||||||
import Posts from "@components/blog/posts.astro";
|
import Posts from "@components/blog/posts.astro";
|
||||||
import LargeCard from "@components/Feature.astro";
|
|
||||||
import {Zorn} from "@minpluto/zorn"
|
|
||||||
|
|
||||||
// List Posts
|
// List Posts
|
||||||
const GhostFetch = 'https://blog.ghost.sudovanilla.org/ghost/api/content/posts/?key=bef2ed15d9e38f7703be9412b3'
|
const GhostFetch = 'https://blog.ghost.sudovanilla.org/ghost/api/content/posts/?key=bef2ed15d9e38f7703be9412b3'
|
||||||
|
@ -20,18 +16,7 @@ import { BookmarkBook, ReportColumns } from "@iconoir/vue";
|
||||||
|
|
||||||
<Default MobileTitle="SudoVanilla" NoSubHeader>
|
<Default MobileTitle="SudoVanilla" NoSubHeader>
|
||||||
<Fragment slot="body">
|
<Fragment slot="body">
|
||||||
<div class="posts">
|
<Posts/>
|
||||||
{Ghost.posts.map((post) =>
|
|
||||||
<a href={'/blog/' + post.slug + '?postid=' + post.id} class="card-post">
|
|
||||||
<img id="bg" src={post.custom_excerpt.image} />
|
|
||||||
<img src={post.custom_excerpt} />
|
|
||||||
<div class="card-post-content">
|
|
||||||
<p><strong>{post.title}</strong></p>
|
|
||||||
<p id="date">{new Date(post.published_at).toLocaleDateString()}</p>
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</Fragment>
|
</Fragment>
|
||||||
</Default>
|
</Default>
|
||||||
|
|
||||||
|
|
|
@ -7,12 +7,6 @@ import Hero from "@components/Hero.astro";
|
||||||
import Heading from "@components/Heading.astro";
|
import Heading from "@components/Heading.astro";
|
||||||
import Posts from "@components/blog/posts.astro";
|
import Posts from "@components/blog/posts.astro";
|
||||||
import LargeCard from "@components/Feature.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'
|
|
||||||
const GhostResponse = await fetch(GhostFetch);
|
|
||||||
const Ghost = await GhostResponse.json();
|
|
||||||
|
|
||||||
// Icons
|
// Icons
|
||||||
import { BookmarkBook, ReportColumns } from "@iconoir/vue";
|
import { BookmarkBook, ReportColumns } from "@iconoir/vue";
|
||||||
|
@ -32,18 +26,7 @@ import { BookmarkBook, ReportColumns } from "@iconoir/vue";
|
||||||
<BookmarkBook width={32} height={32} />
|
<BookmarkBook width={32} height={32} />
|
||||||
</slot>
|
</slot>
|
||||||
</Heading>
|
</Heading>
|
||||||
<div class="posts">
|
<Posts/>
|
||||||
{Ghost.posts.map((post) =>
|
|
||||||
<a href={'/blog/' + post.slug + '?postid=' + post.id} class="card-post">
|
|
||||||
<img id="bg" src={post.custom_excerpt.image} />
|
|
||||||
<img src={post.custom_excerpt} />
|
|
||||||
<div class="card-post-content">
|
|
||||||
<p><strong>{post.title}</strong></p>
|
|
||||||
<p id="date">{new Date(post.published_at).toLocaleDateString()}</p>
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<Heading Title="Projects" Description="What I've Made">
|
<Heading Title="Projects" Description="What I've Made">
|
||||||
<slot slot="icon">
|
<slot slot="icon">
|
||||||
<ReportColumns width={32} height={32} />
|
<ReportColumns width={32} height={32} />
|
||||||
|
|
|
@ -5,6 +5,9 @@
|
||||||
"@components/*": [
|
"@components/*": [
|
||||||
"src/components/*"
|
"src/components/*"
|
||||||
],
|
],
|
||||||
|
"@library/*": [
|
||||||
|
"src/library/*"
|
||||||
|
],
|
||||||
"@layouts/*": [
|
"@layouts/*": [
|
||||||
"src/layouts/*"
|
"src/layouts/*"
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in a new issue