Skip to content

Commit

Permalink
Merge pull request #11 from ProgSoc/ghost-page-action
Browse files Browse the repository at this point in the history
ghost page action
  • Loading branch information
sebasptsch committed Feb 17, 2024
2 parents 9ef179c + 541cbf0 commit 7ed3e41
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .github/actions/publish.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { readFile } from "node:fs/promises";
import { Octokit } from "@octokit/action";
import GhostAdminAPI from '@tryghost/admin-api'

const octokit = new Octokit();
const ghost = new GhostAdminAPI({
url: "https://progsoc.org",
key: process.env.GHOST_ADMIN_API_KEY,
version: "v5.0",
});

const { data } = await octokit.request("POST /markdown", {
headers: { accept: "text/html" },
text: await readFile("CONSTITUTION.md", { encoding: "utf-8" }),
});

const html = data
.replace(/<h1.*?<\/h1>/g, "")
.replace(/>(\d(?:\.\d)*)\.?/g, "><b>$1.</b>");

const { updated_at } = await ghost.pages.read({ id: "65d0046b07a6e4000144c4d2" });

await ghost.pages.edit(
{ id: "65d0046b07a6e4000144c4d2", updated_at, html, },
{ source: "html" },
);
19 changes: 19 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Update Ghost Page
on:
push:
branches:
- main
jobs:
put-html:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm install @octokit/[email protected]
- run: npm install @tryghost/[email protected]
- run: node .github/actions/publish.mjs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GHOST_ADMIN_API_KEY: ${{ secrets.GHOST_ADMIN_API_KEY }}

0 comments on commit 7ed3e41

Please sign in to comment.