A utility service works alongside the OrangeJuice blog system to provide a variety of features.
This worker serves two API POST /api/post
1 and POST /api/post/{slug}/increment
2 for
-
Get metadata (viewCounts) of posts with the request body
{slugs: string[]}
-
Increment the view count of the post
slug
by 1.
This worker is invoked every time a new discussion
or discussion_comment
is created on GitHub. It performs the following actions:
-
Updates the body of the new discussion to include links to the original web page in multiple languages, like this:
English: {WEBSITE_URL}/{SLUG} 中文: {WEBSITE_URL}/zh/{SLUG}
-
Updates the title of the new discussion to
zh/{slug}
to ensure the discussion thread can be matched by both{slug}
(English) andzh/{slug}
(Chinese).
-
Integrate Giscus as the commenting system and use
mapping: pathname
. -
Clone this repository and install the necessary packages, e.g.,
bun i
. -
Obtain a
Github Private Key
, create a GitHub App, and configure the required settings/permissions:Webhook: Active Webhook URL: The URL of the Cloudflare worker Discussions: Read and Write Subscribe to events: Discussion
-
Install the GitHub App on your website's repository.
-
Set up Cloudflare worker secrets with the information obtained in the previous steps by running
wrangler secret put [Secret Name]
:GITHUB_PRIVATE_KEY: string (the Private Key) GITHUB_REPO: string (the repository name) WEBSITE_URL: string (the base URL of the website, e.g., https://example.com)
And of course, we can also store
GITHUB_REPO
andWEBSITE_URL
as plaintext Environment Variables instead. -
Deploy the Cloudflare worker
wrangler deploy
manually or setup Github Actions Continuous deploymeny by adding the Cloudflare API Token generated withEdit Cloudflare Worker
templateCLOUDFLARE_API_TOKEN: string (Github environment secrect)