aboutsummaryrefslogtreecommitdiff
path: root/src/Parser
diff options
context:
space:
mode:
Diffstat (limited to 'src/Parser')
-rw-r--r--src/Parser/Detail.hs22
-rw-r--r--src/Parser/Utils.hs14
2 files changed, 24 insertions, 12 deletions
diff --git a/src/Parser/Detail.hs b/src/Parser/Detail.hs
index 4144964..3a91ac2 100644
--- a/src/Parser/Detail.hs
+++ b/src/Parser/Detail.hs
@@ -14,12 +14,16 @@ import Parser.Utils
parseDetail :: Text -> Detail
parseDetail page =
let tags = parseTags page
- descriptionTags = getTagsBetween "<div itemprop=description>" "</div>" tags
- description =
- if null descriptionTags
- then
- Nothing
- else
- let replaceBr = map (\tag -> if tag ~== "<br>" then TagText (T.pack "\n") else tag)
- in Just . T.strip . renderTags . replaceBr $ descriptionTags
- in Detail { description = description }
+ description = parseDescription tags
+ images = getTagAttributes "<meta itemprop=image>" (T.pack "content") tags
+ in Detail { description = description, images = images }
+
+parseDescription :: [Tag Text] -> Maybe Text
+parseDescription tags =
+ let descriptionTags = getTagsBetween "<div itemprop=description>" "</div>" tags
+ in if null descriptionTags
+ then
+ Nothing
+ else
+ let replaceBr = map (\tag -> if tag ~== "<br>" then TagText (T.pack "\n") else tag)
+ in Just . T.strip . renderTags . replaceBr $ descriptionTags
diff --git a/src/Parser/Utils.hs b/src/Parser/Utils.hs
index 16fe3d2..c03ab03 100644
--- a/src/Parser/Utils.hs
+++ b/src/Parser/Utils.hs
@@ -1,11 +1,12 @@
module Parser.Utils
( getTagsBetween
+ , getTagAttributes
, getTagAttribute
, getTagTextAfter
) where
import Data.List (find, findIndex)
-import Data.Maybe (listToMaybe)
+import Data.Maybe (listToMaybe, catMaybes)
import Data.Text (Text)
import qualified Data.Text as T
@@ -17,9 +18,16 @@ getTagsBetween beginSelector endSelector =
. drop 1
. dropWhile (~/= beginSelector)
+getTagAttributes :: String -> Text -> [Tag Text] -> [Text]
+getTagAttributes selector attribute =
+ catMaybes
+ . fmap (maybeTagAttribute attribute)
+ . filter (~== selector)
+
getTagAttribute :: String -> Text -> [Tag Text] -> Maybe Text
-getTagAttribute selector attribute tags =
- find (~== selector) tags >>= maybeTagAttribute attribute
+getTagAttribute selector attribute =
+ listToMaybe
+ . getTagAttributes selector attribute
getTagTextAfter :: String -> [Tag Text] -> Maybe Text
getTagTextAfter selector tags =