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.
The .env File Template
Section titled “The .env File Template”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).
# Cloudflare ConfigurationDOMAIN=your-domain.comCLOUDFLARE_API_TOKEN=your-cloudflare-api-tokenCLOUDFLARE_ACCOUNT_ID=your-cloudflare-account-idCLOUDFLARE_ZONE_ID=your-cloudflare-zone-idCLOUDFLARE_PROJECT_NAME=your-project-name
# Giscus Comments Configuration# Obtain these values from https://giscus.app/PUBLIC_GISCUS_REPO=your-username/your-repoPUBLIC_GISCUS_REPO_ID=R_...PUBLIC_GISCUS_CATEGORY=AnnouncementsPUBLIC_GISCUS_CATEGORY_ID=DIC_...Cloudflare Variable Breakdown
Section titled “Cloudflare Variable Breakdown”- DOMAIN: The base domain where your blog is hosted.
- CLOUDFLARE_API_TOKEN: The token used by
wranglerto 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.
Cloudflare API Token Permissions
Section titled “Cloudflare API Token Permissions”For the bin/deploy script to work correctly, the CLOUDFLARE_API_TOKEN must have the appropriate permissions to upload files to Cloudflare Pages.
Required Permissions
Section titled “Required Permissions”When creating a custom token in the Cloudflare Dashboard, use the following settings:
| Scope | Resource | Permission |
|---|---|---|
| Account | Cloudflare Pages | Edit |
| Account | Access | Edit |
| Zone | Zone | Read |
| User | User Details | Read |
Steps to Create the Token
Section titled “Steps to Create the Token”- Log in to your Cloudflare Dashboard.
- Go to My Profile > API Tokens.
- Click Create Token.
- Use the “Edit Cloudflare Pages” template if available, or create a Custom Token.
- Add the permissions listed above.
- Set the Account Resources to “All accounts” (or select your specific account).
- Set the Zone Resources to “All zones” (or select your specific domain).
- Click Continue to summary and then Create Token.
Giscus Configuration
Section titled “Giscus Configuration”Giscus is the comment system used for this blog. To set it up:
- Go to giscus.app.
- Follow the instructions to Choose a repository (must be public and have the Giscus app installed).
- Copy the generated
REPO_IDandCATEGORY_IDinto your.envfile.
Loading variables
Section titled “Loading variables”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.