about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorAlan Pearce2014-10-10 15:53:30 +0100
committerAlan Pearce2014-10-10 16:10:09 +0100
commit062fcf6126c71601fa677bfab13bacdab78ec857 (patch)
treef6e03079d392a3c00650a7453705104aa1d38d28 /src
parentbd5a901a5081d01df16ab3a750fdfa403391b3d2 (diff)
downloadmicroformats-062fcf6126c71601fa677bfab13bacdab78ec857.tar.lz
microformats-062fcf6126c71601fa677bfab13bacdab78ec857.tar.zst
microformats-062fcf6126c71601fa677bfab13bacdab78ec857.zip
Add function to normalise a URL
Diffstat (limited to 'src')
-rw-r--r--src/microformats/parser.clj19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/microformats/parser.clj b/src/microformats/parser.clj
index e3a244e..61c1941 100644
--- a/src/microformats/parser.clj
+++ b/src/microformats/parser.clj
@@ -2,7 +2,8 @@
   (:require [net.cgrand.enlive-html :as html]
             [clojure.zip :as z]
             [clojure.core.reducers :as r]
-            [clojure.string :as str]))
+            [clojure.string :as str]
+            [clojurewerkz.urly.core :as url]))
 
 (defmacro anacond
   [& clauses]
@@ -68,11 +69,17 @@
 (defn get-base-url
   "Find the base-url of a document."
   [document]
-  (-> document
-      (html/select [:head :> [:base (html/attr? :href)]])
-      first
-      :attrs
-      :href))
+  (or (-> document
+          (html/select [:head :> [:base (html/attr? :href)]])
+          first
+          :attrs
+          :href)
+      ""))
+
+(defn normalise-url
+  "Normalise a URL"
+  [root url]
+  (url/resolve (get-base-url root) url))
 
 (defn get-value-class
   "Get the value class of elements"