Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/hjerpbakk/cloudflare-cache-purger
- Owner: hjerpbakk
- License: mit
- Created: 2018-06-19T11:20:28.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-04-29T11:39:56.000Z (over 4 years ago)
- Last Synced: 2023-11-30T15:20:27.167Z (about 1 year ago)
- Topics: cloudflare, cloudflare-api, cloudflare-cache-purger, dotnet, dotnet-script, google, jekyll, webmaster-tools
- Language: C#
- Homepage: https://hjerpbakk.com/blog/2018/06/20/clear-cloudflare-cache
- Size: 163 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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.
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.