Skip to content

Setting up Environment Variables

To run and deploy this blog, you need to configure several environment variables. These are stored in a .env file at the root of your project.

Create a file named .env in the root of your blog-content directory (it is already in the .gitignore to prevent sensitive keys from being committed).

Terminal window
# Cloudflare Configuration
DOMAIN=your-domain.com
CLOUDFLARE_API_TOKEN=your-cloudflare-api-token
CLOUDFLARE_ACCOUNT_ID=your-cloudflare-account-id
CLOUDFLARE_ZONE_ID=your-cloudflare-zone-id
CLOUDFLARE_PROJECT_NAME=your-project-name
> [!NOTE]
> For the `blog-doc` repository, `DOMAIN` is used to set the `site` URL in `astro.config.mjs`.
# Giscus Comments Configuration
# Obtain these values from https://giscus.app/
PUBLIC_GISCUS_REPO=your-username/your-repo
PUBLIC_GISCUS_REPO_ID=R_...
PUBLIC_GISCUS_CATEGORY=Announcements
PUBLIC_GISCUS_CATEGORY_ID=DIC_...
  • DOMAIN: The base domain where your blog is hosted.
  • CLOUDFLARE_API_TOKEN: The token used by wrangler to authenticate with Cloudflare during deployment.
  • CLOUDFLARE_ACCOUNT_ID: Found in your Cloudflare dashboard URL (the string after dash.cloudflare.com/).
  • CLOUDFLARE_ZONE_ID: Found on the Overview page of your domain in the Cloudflare dashboard.
  • CLOUDFLARE_PROJECT_NAME: The name you gave to your Cloudflare Pages project.

For the bin/deploy script to work correctly, the CLOUDFLARE_API_TOKEN must have the appropriate permissions to upload files to Cloudflare Pages.

When creating a custom token in the Cloudflare Dashboard, use the following settings:

ScopeResourcePermission
AccountCloudflare PagesEdit
AccountAccessEdit
ZoneZoneRead
UserUser DetailsRead
  1. Log in to your Cloudflare Dashboard.
  2. Go to My Profile > API Tokens.
  3. Click Create Token.
  4. Use the “Edit Cloudflare Pages” template if available, or create a Custom Token.
  5. Add the permissions listed above.
  6. Set the Account Resources to “All accounts” (or select your specific account).
  7. Set the Zone Resources to “All zones” (or select your specific domain).
  8. Click Continue to summary and then Create Token.

Giscus is the comment system used for this blog. To set it up:

  1. Go to giscus.app.
  2. Follow the instructions to Choose a repository (must be public and have the Giscus app installed).
  3. Copy the generated REPO_ID and CATEGORY_ID into your .env file.

The bin/ scripts are designed to work with these variables. If you use direnv, you can also create a .envrc file with the content export $(cat .env | xargs) to have them automatically loaded into your shell when you enter the directory.