about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorAlan Pearce2014-09-24 13:23:30 +0100
committerAlan Pearce2014-09-24 13:25:04 +0100
commitcdf600e89d0008ea42eaa60cc7b3abf0a18acff2 (patch)
treeea65a0da27fd440f876c1ec9d675d067bfabcc39 /src
parent388a6a07086c4217a907a8643b27693618c008f2 (diff)
downloadmicroformats-cdf600e89d0008ea42eaa60cc7b3abf0a18acff2.tar.lz
microformats-cdf600e89d0008ea42eaa60cc7b3abf0a18acff2.tar.zst
microformats-cdf600e89d0008ea42eaa60cc7b3abf0a18acff2.zip
Parse implied photo properties
Diffstat (limited to 'src')
-rw-r--r--src/microformats/parser.clj31
1 files changed, 22 insertions, 9 deletions
diff --git a/src/microformats/parser.clj b/src/microformats/parser.clj
index f348f3b..ab14cd6 100644
--- a/src/microformats/parser.clj
+++ b/src/microformats/parser.clj
@@ -171,8 +171,8 @@
        (r/filter (mf-names-from-class "h-"))
        (into [])))
 
-(defn- imply-name
-  "Imply the name of an entity from the element"
+(defn- parse-implied-name
+  "Get the implied name of an entity"
   [element]
   (case (:tag element)
     :abbr (-> element :attrs :title)
@@ -188,25 +188,38 @@
      (-> % :attrs :title)
      true (node-to-text (:content element)))))
 
-(defn- imply-url
+(defn- parse-implied-url
   [element]
   (case (:tag element)
     :a (-> element :attrs :href)
     nil))
 
-(defn- imply-photo
+(defn- parse-implied-photo
   [element]
   (case (:tag element)
     :img (-> element :attrs :src)
-    nil))
+    :object (-> element :attrs :data)
+    (cond-let
+     (first (html/select element [html/root :> [:img (html/but-node (html/attr-contains :class "h-")) html/only-of-type]]))
+     (-> % :attrs :src)
+     (first (html/select element [html/root :> [:object (html/but-node (html/attr-contains :class "h-")) html/only-of-type]]))
+     (-> % :attrs :data)
+     (first (html/select element [html/root :> html/only-child :> [:img (html/but-node (html/attr-contains :class "h-")) html/only-of-type]]))
+     (-> % :attrs :src)
+     (first (html/select element [html/root :> html/only-child :> [:object (html/but-node (html/attr-contains :class "h-")) html/only-of-type]]))
+     (-> % :attrs :data)
+     )))
+
+(def empty-ish
+  #(not (str/blank? (first (second %)))))
 
 (defn parse-implied
   "Parse implied properties of a HTML element"
   [element]
-  (into {} (filter #(first (second %))
-                   {:name (list (imply-name element))
-                    :url (list (imply-url element))
-                    :photo (list (imply-photo element))})))
+  (into {} (filter empty-ish
+                   {:name (list (parse-implied-name element))
+                    :url (list (parse-implied-url element))
+                    :photo (list (parse-implied-photo element))})))
 
 (defn get-mf-properties
   "Parse children of a microformat, returning a map of properties"