Cloudflare KV Sync
pendingby Alex Marshall
Automatically sync tagged Markdown files to Cloudflare KV storage.
Obsidian Cloudflare KV Sync
An Obsidian plugin that automatically syncs markdown files to Cloudflare KV storage based on Frontmatter configuration. Perfect for pulling content into a static site generator such as Eleventy, using Cloudflare KV as a bare bones CMS.
Features
- Automatic syncing: Files marked with a sync flag automatically upload when modified
- Auto-generated IDs: Unique document IDs are automatically assigned when missing
- Duplicate detection: Detects and auto-corrects duplicate KV keys during full sync
- Collection support: Organize KV keys with optional collection prefixes
- Smart key management: Handles collection changes and removes old keys automatically
- Error log: Errors are logged to a persistent file in your vault root
- Manual controls: Ribbon icon and commands for manual operations
- Configurable: Customize sync keys, ID fields, and sync behavior
- Debounced uploads: Prevents excessive API calls during rapid editing
Installation
From Obsidian Community Plugins (Recommended)
- Open Obsidian Settings
- Go to Community Plugins and disable Safe Mode
- Click Browse and search for "Cloudflare KV Sync"
- Install and enable the plugin
Manual Installation
- Download the latest release from GitHub
- Extract the files to your vault's
.obsidian/plugins/cloudflare-kv-sync/folder - Enable the plugin in Obsidian settings
Development Installation
- Clone this repository
- Run
npm installto install dependencies - Run
npm run buildto build the plugin - Copy
main.js,manifest.json, andversions.jsonto a new folder in your vault's plugin folder, eg..obsidian/plugins/cloudflare-kv-sync/
Setup
1. Cloudflare Configuration
- Create a Cloudflare KV namespace in your dashboard
- Note the namespace ID
- Create an API token with these permissions:
- Account:
Workers KV Storage:Edit
- Account:
- Note your Account ID
2. Plugin Configuration
- Go to Settings → Community Plugins → Cloudflare KV Sync
- Enter your:
- Account ID: Cloudflare Dashboard → three dots to right of account name → Copy account ID
- Namespace ID: Found in Storage & Databases → KV → Your namespace
- API Token: The token you created above
- Configure optional settings:
- Sync Key: Frontmatter key to check for sync flag (default:
kv_sync) - ID Key: Frontmatter key containing document ID (default:
id) - Auto-sync: Enable/disable automatic syncing on file changes
- Sync Key: Frontmatter key to check for sync flag (default:
Usage
Basic Syncing
Add the sync flag to your markdown frontmatter. A unique ID will be automatically generated if you don't provide one:
---
kv_sync: true
title: My Amazing Post
---
Your content here...
The plugin will auto-generate an id field (a UUID) and sync the file to KV.
You can also set your own ID manually — it will be preserved as-is:
---
id: my-unique-post-id
kv_sync: true
title: My Amazing Post
---
Your content here...
The file will sync to KV with key: my-unique-post-id
Collection Organization
Use collections to organize your KV keys:
---
id: my-blog-post
kv_sync: true
collection: writing
title: My Blog Post
---
This creates KV key: writing/my-blog-post
Manual Controls
- Ribbon icon: Click the cloud upload icon to sync all marked files.
- Command palette:
- "Sync all files marked for KV sync"
- "Sync current file to Cloudflare KV"
- "Remove current file from Cloudflare KV"
Sync Behavior
- Enable sync: Set
kv_sync: truein frontmatter. - Disable sync: Set
kv_syncto any value other thantrueor remove the key entirely. - Change collection: Update the
collectionvalue. Old keys are automatically removed. - Auto-cleanup: Removing sync flag automatically removes the file from KV.
Configuration Options
| Setting | Default | Description |
|---|---|---|
| Sync Key | kv_sync | Frontmatter key to check for sync flag |
| ID Key | id | Frontmatter key containing document ID (auto-generated if empty) |
| Auto-sync | true | Automatically sync files on modification |
| Debounce Delay | 2000ms | Wait time before syncing after file changes |
Examples
Simple Blog Post (auto-generated ID)
---
kv_sync: true
title: Hello World
date: 2024-01-15
---
# Hello World
This is my first post!
KV Key: auto-generated UUID (e.g. a1b2c3d4-e5f6-7890-abcd-ef1234567890)
Blog Post with Manual ID
---
id: hello-world
kv_sync: true
title: Hello World
date: 2024-01-15
---
# Hello World
This is my first post!
KV Key: hello-world
Organized Content
---
id: advanced-js-patterns
kv_sync: true
collection: tutorials
title: Advanced JavaScript Patterns
tags: [javascript, programming]
---
# Advanced JavaScript Patterns
Learn about advanced patterns...
KV Key: tutorials/advanced-js-patterns
Draft Content (Not Synced)
---
id: work-in-progress
kv_sync: false
title: Work in Progress
---
This won't be synced to KV.
Troubleshooting
Common Issues
- Files not syncing: Check that
kv_sync: trueexists in frontmatter (anidwill be auto-generated if missing) - API errors: Verify your Account ID, Namespace ID, and API token
- Permission errors: Ensure API token has Cloudflare Workers:Edit permission
- Old keys remaining: Plugin automatically cleans up when collections change
- Duplicate IDs: The plugin detects duplicate KV keys during full sync and auto-assigns new IDs to resolve conflicts
Debug Steps
- Check the
Cloudflare KV Sync error log.mdfile in your vault root for error details - Verify Cloudflare KV namespace exists and is accessible
- Test API token permissions in Cloudflare dashboard
- Ensure frontmatter is valid YAML syntax
Development
Building
npm install
npm run build
Development Mode
npm run dev
This will watch for changes and rebuild automatically.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
Support
- GitHub Issues: Report bugs or request features
- Discussions: Ask questions or share use cases
Changelog
0.1.0
- Initial release
- Automatic KV syncing based on frontmatter flags
- Collection support for organized keys
- Smart key management and cleanup
- Configurable sync behavior
For plugin developers
Search results and similarity scores are powered by semantic analysis of your plugin's README. If your plugin isn't appearing for searches you'd expect, try updating your README to clearly describe your plugin's purpose, features, and use cases.