summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@macaw.me>2020-07-05 14:57:19 +0800
committerFrederick Yin <fkfd@macaw.me>2020-07-05 14:57:19 +0800
commite3ccf1129fef6011124cc93eb7981513e28d9f98 (patch)
treeb181c9aca2317b4edb202e82fa08f4aed81131fb
parent27f8fc4761b10a415391e5d9b8314931c692aa57 (diff)
Delete site
-rw-r--r--utab/__main__.py23
-rw-r--r--utab/data/icons/arrow-thick-left.svg3
-rw-r--r--utab/data/icons/trash.svg3
-rw-r--r--utab/data/site.html18
4 files changed, 38 insertions, 9 deletions
diff --git a/utab/__main__.py b/utab/__main__.py
index df92dbc..6dddd0b 100644
--- a/utab/__main__.py
+++ b/utab/__main__.py
@@ -72,13 +72,12 @@ def index():
@app.route("/go/<path:url>")
def visit_site(url):
# log this visit, then redirect to the unescaped url
- url_unesc = urllib.parse.unquote(url) # unescaped url
sites = read_sites()
for i, s in enumerate(sites):
- if s[URL] == url_unesc:
+ if s[URL] == url:
sites[i][VISITS] = str(int(sites[i][VISITS]) + 1)
write_sites(sites)
- return redirect(url_unesc, 302)
+ return redirect(url, 302)
return abort(404)
@@ -113,9 +112,11 @@ def add_site():
site_form,
site_heading="Add site",
url="https://",
+ url_esc="",
title="",
favicon_src="",
favicon_placeholder="Leave blank to auto-retrieve favicon. Base64 is allowed.",
+ delete_button_visibility="hidden",
action="new",
)
@@ -127,10 +128,9 @@ def edit_site(url):
# /edit/<escaped_url>?url=<escaped_new_url>&... => edit this site in database
if not url:
return redirect("/edit", 301)
- url_unesc = urllib.parse.unquote(url)
sites = read_sites()
for i, s in enumerate(sites):
- if s[URL] == url_unesc:
+ if s[URL] == url:
new_url, new_title, new_favicon = (
request.args.get("url"),
request.args.get("title"),
@@ -141,9 +141,11 @@ def edit_site(url):
site_form,
site_heading="Edit site",
url=s[URL],
+ url_esc=urllib.parse.quote(s[URL], safe=""),
title=s[TITLE],
favicon_src=s[FAVICON],
favicon_placeholder="Base64 is allowed.",
+ delete_button_visibility="visible",
action="edit/" + urllib.parse.quote(s[URL], safe=""),
)
sites[i][URL] = new_url
@@ -165,6 +167,17 @@ def select_site_to_edit():
)
+@app.route("/delete/<path:url>")
+def delete_site(url):
+ sites = read_sites()
+ for i, s in enumerate(sites):
+ if s[URL] == url:
+ sites = sites[:i] + sites[i + 1 :]
+ write_sites(sites)
+ return redirect("/", 302)
+ return "No site with such URL exists", 403
+
+
@app.route("/css/<string:filename>")
def serve_css(filename):
# serve static CSS because browsers forbid file:// scheme
diff --git a/utab/data/icons/arrow-thick-left.svg b/utab/data/icons/arrow-thick-left.svg
new file mode 100644
index 0000000..26d3bbe
--- /dev/null
+++ b/utab/data/icons/arrow-thick-left.svg
@@ -0,0 +1,3 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8" viewBox="0 0 8 8">
+ <path style="fill:#ffffff;fill-opacity:1" d="M3 0l-3 3.03 3 2.97v-2h5v-2h-5v-2z" transform="translate(0 1)" />
+</svg>
diff --git a/utab/data/icons/trash.svg b/utab/data/icons/trash.svg
new file mode 100644
index 0000000..a960240
--- /dev/null
+++ b/utab/data/icons/trash.svg
@@ -0,0 +1,3 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8" viewBox="0 0 8 8">
+ <path style="fill:#ffffff;fill-opacity:1" d="M3 0c-.55 0-1 .45-1 1h-1c-.55 0-1 .45-1 1h7c0-.55-.45-1-1-1h-1c0-.55-.45-1-1-1h-1zm-2 3v4.81c0 .11.08.19.19.19h4.63c.11 0 .19-.08.19-.19v-4.81h-1v3.5c0 .28-.22.5-.5.5s-.5-.22-.5-.5v-3.5h-1v3.5c0 .28-.22.5-.5.5s-.5-.22-.5-.5v-3.5h-1z" />
+</svg>
diff --git a/utab/data/site.html b/utab/data/site.html
index 1406af9..20b0900 100644
--- a/utab/data/site.html
+++ b/utab/data/site.html
@@ -4,13 +4,13 @@
/edit/<url>
-->
<head>
- <title>utab - add new</title>
+ <title>utab - edit site</title>
</head>
<body>
<h2>%site_heading%</h2>
<form action="/%action%" method="GET">
<label for="url">URL:</label>
- <input class="form-input" name="url" type="url" value="%url%" autofocus />
+ <input class="form-input" name="url" type="text" value="%url%" autofocus />
<br />
<label for="title">Title:</label>
<input class="form-input" name="title" type="text" value="%title%" />
@@ -19,13 +19,23 @@
<input
class="form-input"
name="favicon"
- type="url"
+ type="text"
value="%favicon_src%"
placeholder="%favicon_placeholder%"
/>
<br />
<input class="form-button" type="submit" />
- <a href="/"><button class="form-button">Cancel</button></a>
</form>
+ <footer class="ctrl">
+ <a href="/">
+ <img class="ctrl-icon" src="/icons/home.svg" />
+ </a>
+ <a href="/edit">
+ <img class="ctrl-icon" src="/icons/arrow-thick-left.svg" />
+ </a>
+ <a href="/delete/%url_esc%" style="visibility: %delete_button_visibility%;">
+ <img class="ctrl-icon" src="/icons/trash.svg" />
+ </a>
+ </footer>
<link rel="stylesheet" type="text/css" href="/css/index.css" />
</body>