From 541cbf09239620d4b9e8b9b30e3b7a838fac365e Mon Sep 17 00:00:00 2001 From: Oli Lenehan Date: Sat, 17 Feb 2024 12:23:51 +1100 Subject: [PATCH] ghost page action --- .github/actions/publish.mjs | 26 ++++++++++++++++++++++++++ .github/workflows/main.yml | 19 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 .github/actions/publish.mjs create mode 100644 .github/workflows/main.yml diff --git a/.github/actions/publish.mjs b/.github/actions/publish.mjs new file mode 100644 index 0000000..c1b1459 --- /dev/null +++ b/.github/actions/publish.mjs @@ -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(//g, "") + .replace(/>(\d(?:\.\d)*)\.?/g, ">$1."); + +const { updated_at } = await ghost.pages.read({ id: "65d0046b07a6e4000144c4d2" }); + +await ghost.pages.edit( + { id: "65d0046b07a6e4000144c4d2", updated_at, html, }, + { source: "html" }, +); diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..4f1f5b3 --- /dev/null +++ b/.github/workflows/main.yml @@ -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/action@6.0.7 + - run: npm install @tryghost/admin-api@1.13.11 + - run: node .github/actions/publish.mjs + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GHOST_ADMIN_API_KEY: ${{ secrets.GHOST_ADMIN_API_KEY }}