aboutsummaryrefslogtreecommitdiff
path: root/src/Parser/Detail.hs
blob: 4144964ebed0ce4e68a5985e6022c4da22e8cb54 (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
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
      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 }