aboutsummaryrefslogtreecommitdiff
path: root/src/Parser/Detail.hs
blob: b787772726e7c030e169854bd8adb6361968f5d7 (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
module Parser.Detail
  ( parseDetail
  ) where

import qualified Data.Text as T

import Text.HTML.TagSoup

import Model.Detail

import Parser.Utils

parseDetail :: T.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 }