Commit 98566d5a authored by Ricardo J. Mendez's avatar Ricardo J. Mendez

Ignoring protocol when hashing the URL for a key
parent b79c0ee3
(ns booklet.background
(:require [clojure.set :refer [difference]]
[cljs.core.async :refer [>! <!]]
[booklet.utils :refer [on-channel from-transit to-transit]]
[booklet.utils :refer [on-channel from-transit to-transit key-from-url]]
[khroma.log :as console]
[khroma.alarms :as alarms]
[khroma.runtime :as runtime]
......@@ -251,7 +251,7 @@
(fn [app-state [_ tab time]]
(let [url-times (or (get-in app-state url-time-path) {})
url (or (:url tab) "")
url-key (hash-string url)
url-key (key-from-url url)
url-time (or (get url-times url-key)
{:url (:url tab)
:time 0
......@@ -11,9 +11,7 @@
[channel (chan-fn)]
(dispatch-fn [msg (<! channel)])
(recur channel)
(recur channel)))
(defn to-transit
......@@ -22,3 +20,12 @@
(defn from-transit
(transit/read (transit/reader :json) transit-data))
(defn key-from-url
"Shortens a URL to remove anchor and protocol, and returns an integer based on
the result."
(let [element (.createElement js/document "a")
_ (aset element "href" url)
shortened (str (.-host element) (.-pathname element) (.-search element))]
(hash-string shortened)))
(ns booklet.startpage
(:require [booklet.utils :refer [from-transit]]
(:require [booklet.utils :refer [from-transit key-from-url]]
[dommy.core :refer-macros [sel sel1]]
[khroma.runtime :as runtime]
[khroma.log :as console]
......@@ -12,7 +12,7 @@
[database node]
(let [parent (.-parentNode node)
href (.-href parent)
id (hash-string href)
id (key-from-url href)
data (get database id)
time (:time data)
root-item (-> parent .-parentNode .-parentNode .-parentNode) ; Yeah, hacky as fuck
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment