aboutsummaryrefslogtreecommitdiff
path: root/src/Parser/Detail.hs
blob: 3a91ac29aa6bc03fe77434d09c1e1617b2ecc566 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
module Parser.Detail
  ( parseDetail
  ) where

import Data.Text (Text)
import qualified Data.Text as T

import Text.HTML.TagSoup

import Model.Detail

import Parser.Utils

parseDetail :: Text -> Detail
parseDetail page =
  let tags = parseTags page
      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