~fkfd/utab

e3ccf1129fef6011124cc93eb7981513e28d9f98 — Frederick Yin 2 years ago 27f8fc4
Delete site
M utab/__main__.py => utab/__main__.py +18 -5
@@ 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

A utab/data/icons/arrow-thick-left.svg => utab/data/icons/arrow-thick-left.svg +3 -0
@@ 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>

A utab/data/icons/trash.svg => utab/data/icons/trash.svg +3 -0
@@ 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>

M utab/data/site.html => utab/data/site.html +14 -4
@@ 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>