A Cloudflare Workers project that lets you host Notion pages on your own custom domain with enhanced features like dark mode, custom fonts, SEO optimization, and the option to hardcode your settings for a single domain.
- Custom Domain: Host your Notion pages on your own domain
- SEO Optimization: Customize meta tags such as page title, description, and Open Graph tags
- Dark Mode: Automatically detects system preferences and allows manual toggling
- Custom Fonts: Easily integrate Google Fonts
- Clean UI: Removes Notion's default navigation elements
- Sitemap Generation: Automatically creates a sitemap.xml for search engines
- URL Slugs: Map custom, human-readable slugs to Notion page IDs
- Manual Configuration: Optionally hardcode your domain settings without using KV storage
The worker acts as a proxy between your custom domain and Notion. When a visitor accesses your domain, the worker:
- Retrieves the domain configuration
- Fetches the corresponding Notion page
- Applies custom modifications (like SEO meta tags, dark mode toggle, and custom fonts)
- Handles URL routing and slug redirection
- Returns the modified page to the visitor
By default, the worker uses Cloudflare KV storage to store configurations for multiple domains. Each domain configuration should follow this structure:
{
"SLUG_TO_PAGE": {
"": "homepage-notion-id",
"about": "about-page-notion-id",
"contact": "contact-page-notion-id"
},
"PAGE_TITLE": "Your Site Title",
"PAGE_DESCRIPTION": "Your site description for SEO",
"GOOGLE_FONT": "Font Name",
"CUSTOM_SCRIPT": "<script>console.log('Custom JavaScript');</script>"
}If you only need to host a single domain and prefer not to use KV storage, simply uncomment and configure the manualConfig object in the script. When manualConfig is defined, the script auto-detects its presence and uses those settings instead of fetching from KV.
- Create a Cloudflare Workers account
- If using KV storage, create a KV namespace called
DOMAINS_CONFIG - Deploy this worker script to Cloudflare
- Add your domain configuration to the KV namespace (if not using
manualConfig)
- Add your custom domain to Cloudflare
- Point your domain to the Cloudflare Worker
Instead of using Notion's long page IDs in URLs, you can map them to readable slugs:
https://yourdomain.com/about instead of https://yourdomain.com/83f7dd5879884c5f89326a1541629b20
The worker injects a dark mode toggle that:
- Detects user system preferences
- Allows manual toggling
- Persists the chosen mode during navigation
Improve search engine visibility by customizing meta tags such as:
- Page title
- Page description
- Open Graph and Twitter tags
For those with only a single domain or who wish to avoid using KV storage, simply uncomment and configure the manualConfig object in the script. The script auto-detects manual configuration if it exists and uses it instead of fetching from KV.
The variable MY_NOTION_USERNAME (formerly MY_NOTION_DOMAIN) should be set to your Notion username. This value is used to construct the target Notion URL for proxying.
When no manual configuration is provided, the worker uses KV storage to manage configurations for multiple domains, automatically selecting the correct configuration based on the incoming domain.
Domain not found: Ensure your domain configuration exists in KV storage or is defined via manualConfig.
Styling issues: Custom fonts or CSS might conflict with Notion's default styles. Experiment with different settings.
Incorrect redirects: Double-check your SLUG_TO_PAGE mappings and Notion page IDs.
Contributions are welcome! Feel free to submit pull requests for new features, improvements, or bug fixes.
This project is available under the MIT License.