├── LICENSE ├── README.md └── worker.js /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 jonfraser 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # simpletext blog 2 | A simple to use text only blog using CloudFlare Workers and KV. I wanted to see if I could create a super basic blog engine with very little setup, writing effort, and writing distraction. Enter simpletext! Create a cloudflare worker and KV and start adding KV Pairs (blog entries) to get a free blog engine right on the cloudflare edge. 3 | 4 | # Setup 5 | 1. Create a CloudFlare account (free plan works fine until your blog gets super popular) 6 | 2. Create a worker and leave the default text for the moment 7 | 4. Create a KV 8 | 3. Add a Binding to your KV from your Worker (via the Settings in the Worker) named "PAGES" 9 | 5. Paste the worker.js content from this project into your Worker (overwrite it all) 10 | 6. Update the top variables baseUrl, blogTitle, blogDescription 11 | 7. Save and deploy your worker 12 | 13 | # Adding blog entries 14 | Simply add KV Pairs into your KV. A few notes: 15 | - At the moment the Key is convention-based and needs to be in the format yyyy-MM-dd\~blog-title (ie 2024-10-26\~My-First-Entry) 16 | - The date gets extracted and split from the title by the tilde. 17 | - The title is formatted by replacing the dashes with spaces 18 | - Not following this format will break everything (probably) 19 | - The Value can have whatever you want that is valid HTML. What you put is not being sanitised so take care 20 | 21 | # Example 22 | https://simpletext.bananaortaco.fun/ 23 | -------------------------------------------------------------------------------- /worker.js: -------------------------------------------------------------------------------- 1 | 2 | export default { 3 | async fetch (req, env, ctx) { 4 | const baseUrl = "https://simpletext.bananaortaco.fun"; 5 | const blogTitle = "SimpleText BananaOrTaco"; 6 | const blogDescription = "This is a simpletext RSS feed."; 7 | 8 | const url = new URL(req.url) 9 | const pre_head = `
"; 11 | const end_it = "
"; 12 | const pagekeys = await env.PAGES.list(); 13 | 14 | //we've hit the home 15 | if (req.method === 'GET' && url.pathname === '/') { 16 | var pageList = ""; 17 | if(pagekeys.keys !== undefined && pagekeys.keys.length > 0){ 18 | pagekeys.keys.forEach(element => { 19 | var prettyLink = element.name.substring(11).replaceAll('-',' '); 20 | pageList += ""+prettyLink+" (" + element.name.substring(0,10) + ")"; 21 | }); 22 | } 23 | return new Response(pre_head+blogTitle+pre_body+pageList+end_it, { 24 | headers: { 25 | "content-type": "text/html;charset=UTF-8", 26 | }, 27 | }); 28 | } 29 | 30 | //rss endpoint 31 | if (req.method === 'GET' && url.pathname === '/rss') { 32 | var pageList = ""; 33 | if(pagekeys.keys !== undefined && pagekeys.keys.length > 0){ 34 | pagekeys.keys.forEach(element => { 35 | var prettyLink = element.name.substring(11).replaceAll('-',' '); 36 | var postDate = element.name.substring(0,10); 37 | var postLink = "/"+element.name; 38 | 39 | var itemBlock = `