From 7b3b7b386a4fdd3acbc85962dfb48a937d6e8c71 Mon Sep 17 00:00:00 2001
From: Korbs
Date: Mon, 23 Dec 2024 16:46:42 -0500
Subject: [PATCH] Add support to add a blog using Ghost, creating a separated
blog page
---
Dockerfile | 2 +-
astro.config.mjs | 4 +--
config.json | 9 ++++++
package.json | 3 +-
src/components/Sidebar.astro | 56 ++++++++++++++++++++++------------
src/layouts/Document.astro | 15 ++++++---
src/library/ghost.ts | 8 +++++
src/pages/blog/[...slug].astro | 51 +++++++++++++++++++++++++++++++
src/pages/blog/index.astro | 6 ++++
tsconfig.json | 1 +
10 files changed, 127 insertions(+), 28 deletions(-)
create mode 100644 src/library/ghost.ts
create mode 100644 src/pages/blog/[...slug].astro
create mode 100644 src/pages/blog/index.astro
diff --git a/Dockerfile b/Dockerfile
index 740d2cb..401b108 100755
--- a/Dockerfile
+++ b/Dockerfile
@@ -8,7 +8,7 @@ LABEL org.opencontainers.image.description="Documentations built on Astro"
LABEL org.opencontainers.image.licenses="MIT NON-AI License"
LABEL org.opencontainers.image.url="https://butterflyvu.docs.sudovanilla.org/"
LABEL org.opencontainers.image.source="https://ark.sudovanilla.org/Korbs/ButterflyVu/"
-LABEL org.opencontainers.image.version="0.1.8"
+LABEL org.opencontainers.image.version="0.1.9"
# Copy Files
WORKDIR /app
diff --git a/astro.config.mjs b/astro.config.mjs
index a162e99..bd0d9e6 100755
--- a/astro.config.mjs
+++ b/astro.config.mjs
@@ -2,14 +2,12 @@ import { defineConfig } from 'astro/config'
import vue from "@astrojs/vue"
// Settings
-import { SiteSettings } from './config.json'
+import { SiteSettings, Ghost } from './config.json'
// Integrations
import mdx from '@astrojs/mdx'
import pagefind from "astro-pagefind"
-
import compressor from 'astro-compressor';
-
import pageInsight from 'astro-page-insight';
// Astro Configuration
diff --git a/config.json b/config.json
index e02b30b..e9d833f 100755
--- a/config.json
+++ b/config.json
@@ -9,6 +9,11 @@
"WhiteLabel": "true",
"FooterVersion": "true"
},
+ "Ghost": {
+ "Enabled": true,
+ "Instance": "https://minpluto.ghost.sudovanilla.org",
+ "Key": "22f4a31cd6f8cc0b2a2718a0cd"
+ },
"FeelbackConfig": {
"Enabled": false,
"ContentSetId": "566e8b96-c65e-4bf7-87df-d22a9f4994a2",
@@ -17,6 +22,10 @@
"Answer": "Thank you for your feedback."
},
"HeaderItems": [
+ {
+ "text": "Blog",
+ "link": "/blog/"
+ },
{
"text": "Syntax",
"link": "/syntax/"
diff --git a/package.json b/package.json
index 32aabdc..47afa0a 100755
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "butterflyvu",
"type": "module",
- "version": "0.1.8",
+ "version": "0.1.9",
"license": "MIT NON-AI License",
"author": {
"name": "SudoVanilla"
@@ -33,6 +33,7 @@
"@astrojs/vue": "^5.0.3",
"@iconoir/vue": "^7.10.1",
"@minpluto/zorn": "^0.4.83",
+ "@tryghost/content-api": "^1.11.21",
"astro": "5.1.1",
"astro-analytics": "^2.7.0",
"astro-bun-adapter": "^1.0.2",
diff --git a/src/components/Sidebar.astro b/src/components/Sidebar.astro
index 186de82..e14fc39 100755
--- a/src/components/Sidebar.astro
+++ b/src/components/Sidebar.astro
@@ -1,28 +1,46 @@
---
// Settings
import { SiteSettings, SidebarItems } from '@config'
+
+// Properties
+const { Blog } = Astro.props
+
+// Get Posts
+import { ghostClient } from "@library/ghost";
+const posts = await ghostClient.posts
+ .browse({
+ limit: "all",
+ })
+ .catch(() => {null})
---
+ :
+
+}
+
-
+
-
{frontmatter.Title}
+ {Blog ?
{Title}
:
{frontmatter.Title}
}
diff --git a/src/library/ghost.ts b/src/library/ghost.ts
new file mode 100644
index 0000000..6d3cc97
--- /dev/null
+++ b/src/library/ghost.ts
@@ -0,0 +1,8 @@
+import GhostContentAPI from '@tryghost/content-api'
+import {Ghost} from "@config"
+
+export const ghostClient = new GhostContentAPI({
+ url: Ghost.Instance,
+ key: Ghost.Key,
+ version: 'v5.0',
+})
\ No newline at end of file
diff --git a/src/pages/blog/[...slug].astro b/src/pages/blog/[...slug].astro
new file mode 100644
index 0000000..16c7c6c
--- /dev/null
+++ b/src/pages/blog/[...slug].astro
@@ -0,0 +1,51 @@
+---
+// Layout
+import Default from "@layouts/Document.astro";
+
+// Settings
+import { Ghost } from '@config'
+
+// 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;
+
+const Id = Astro.url.href.split("?postid=").pop();
+const GhostPostFetch = Ghost.Instance + "/ghost/api/content/posts/" + Id + "/?key=" + Ghost.Key;
+const GhostPostResponse = await fetch(GhostPostFetch);
+const GhostPost = await GhostPostResponse.json();
+---
+
+
+
+

+
{new Date(post.published_at).toLocaleDateString()}
+
+
+
\ No newline at end of file
diff --git a/src/pages/blog/index.astro b/src/pages/blog/index.astro
new file mode 100644
index 0000000..a7a130b
--- /dev/null
+++ b/src/pages/blog/index.astro
@@ -0,0 +1,6 @@
+---
+// Layout
+import Default from "@layouts/Document.astro";
+---
+
+
\ No newline at end of file
diff --git a/tsconfig.json b/tsconfig.json
index 6113fd6..5dba6b9 100755
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -7,6 +7,7 @@
"@assets/*": ["src/assets/*"],
"@components/*": ["src/components/*"],
"@layouts/*": ["src/layouts/*"],
+ "@library/*": ["src/library/*"],
"@styles/*": ["src/styles/*"],
"@config": ["./config.json"]
}