Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/hjerpbakk/cloudflare-cache-purger

This script clears the cache on Cloudflare and notifies Google when adding a new post to a Jekyll repository.
https://github.com/hjerpbakk/cloudflare-cache-purger

cloudflare cloudflare-api cloudflare-cache-purger dotnet dotnet-script google jekyll webmaster-tools

Last synced: about 1 month ago
JSON representation

This script clears the cache on Cloudflare and notifies Google when adding a new post to a Jekyll repository.

Awesome Lists containing this project

README

        

# Cloudflare Cache Purger

## What it does

This script purges relevant pages from the cache on Cloudflare when adding a new post to a Jekyll repository. In addition to the tag pages matching the tags of the latest post and the post itself, it purges the following hardcoded pages:

- .
- . /feed.xml
- . /sitemap.xml
- ./archive

`sitemap.xml` is also submitted to Google so that the new content is crawled quicker.

## Running locally

```bash
$ dotnet script main.csx -- path_to_jekyll_repo
```

## Running from GitHub

```bash
$ dotnet script https://raw.githubusercontent.com/Sankra/cloudflare-cache-purger/master/main.csx -- path_to_jekyll_repo
```

Caution, do not run scripts from the Internet that you do not fully understand.

## Configuration

The script takes one argument. This is the `path to the Jekyll repo`.

If a `config.json` file is added to the same directory, the script will try to actually purge the cache. If this file is missing, the script only prints what it would’ve done.

`config.json` should look like this:

```JSON
{
"baseAddress": "[baseAdress]",
"cloudflareApiKey": "[cloudflareApiKey]",
"cloudflareEmail": "[cloudflareEmail]",
"cloudflareZoneId": "[cloudflareZoneId]"
}
```

- `baseAdress` is the URL to your site.
- `cloudflareApiKey` is your Cloudflare API key. You can see this on your *profile*.
- `cloudflareEmail` is the email to your user on Cloudflare.
- `cloudflareZoneId` is the id of this site on Cloudflare. You can see this in the *overview* tab for your site.

## Dry run

If the script cannot find `config.json`, the generated paths will only be written to standard out. The default site is `https://hjerpbakk.com`, but this can easily be changed to your domain within the script.


Example from a local dry run

A dry run can also be forced by using a second argument:

```bash
$ dotnet script main.csx -- path_to_jekyll_repo dry_run
```

## Clear Cloudflare cache

To use this with Cloudflare, clone the repo, create `config.json` from `config.default.json` and input your configuration values.

Running the script now will call the Cloudflare API and do the needful.


Example clearing the Cloudflare cache