From e19324c22026aa10ee80e84bfe4c39e298afa7a4 Mon Sep 17 00:00:00 2001 From: my Date: Fri, 30 Jan 2026 15:18:10 +0100 Subject: [PATCH] clean url = clean database --- octomode.py | 15 ++++++++++++++- templates/start.html | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/octomode.py b/octomode.py index 28172dc..acc5603 100755 --- a/octomode.py +++ b/octomode.py @@ -4,6 +4,7 @@ from flask import Flask, request, render_template, redirect, url_for from urllib.request import urlopen from urllib.parse import urlencode import html +import re # To sanitize Flask input fields from markupsafe import Markup, escape @@ -173,6 +174,16 @@ def render_markdown_error(name, error): title="Markdown error" ), 400 + +def clean_string(input_string): + input_string = input_string.lower() + snake_case_string = re.sub(r'[\s!]+', '_', input_string) + return snake_case_string.strip('_') + +def prettify_string(input_string): + space_string = input_string.replace("_", " ") + return space_string.title() + # --- @APP.route('/', methods=['GET', 'POST']) @@ -184,12 +195,14 @@ def index(): # This is when the environment is "created" # The pads are filled with the default templates (pad, stylesheet, template) exts = ['.md', '.css'] + # clean up the name so we dont get x number of different publications when people mistype + name = clean_string(name) for ext in exts: create_pad_on_first_run(name, ext) return redirect(url_for("pad", name=name)) else: pubs = all_publications() - return render_template('start.html', pubs = pubs, home_pad_url=APP.config['HOME_PAD_URL']) + return render_template('start.html', pubs = pubs, home_pad_url=APP.config['HOME_PAD_URL'], prettify_string=prettify_string) @APP.route('//') def main(name): diff --git a/templates/start.html b/templates/start.html index c4d9903..f1368df 100644 --- a/templates/start.html +++ b/templates/start.html @@ -19,7 +19,7 @@

Below a list of the publications on the server.