ArtDecoCard.purs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. module LinkedIn.ArtDecoCard where
  2. import Prelude
  3. import Data.Generic.Rep (class Generic)
  4. import Data.List (List)
  5. import Data.List.Types (NonEmptyList)
  6. import Data.Maybe (Maybe)
  7. import Data.Show.Generic (genericShow)
  8. import LinkedIn (DetachedNode)
  9. import LinkedIn.ArtDeco (ArtDecoPvsEntity, parseArtDecoPvsEntity)
  10. import LinkedIn.ArtDeco as AD
  11. import LinkedIn.Types (Parser)
  12. import LinkedIn.Utils (queryOneAndParse)
  13. data ArtDecoCardElement a = ArtDecoCardElement {
  14. pvs_entity :: ArtDecoPvsEntity a
  15. }
  16. derive instance Generic (ArtDecoCardElement a) _
  17. derive instance Eq a => Eq (ArtDecoCardElement a)
  18. instance Show a => Show (ArtDecoCardElement a) where
  19. show = genericShow
  20. instance Functor ArtDecoCardElement where
  21. map f (ArtDecoCardElement {pvs_entity}) =
  22. ArtDecoCardElement ({pvs_entity: map f pvs_entity})
  23. parseArtDecoCard :: Parser (ArtDecoCardElement DetachedNode)
  24. parseArtDecoCard n = do
  25. pvs <- queryOneAndParse ":scope div.pvs-entity--padded" parseArtDecoPvsEntity n
  26. pure $ ado
  27. p <- pvs
  28. in ArtDecoCardElement {pvs_entity: p}
  29. toCenterContent ∷ forall a. ArtDecoCardElement a → List a
  30. toCenterContent = toPvsEntity >>> AD.toCenterContent
  31. toHeaderBold ∷ forall a. ArtDecoCardElement a → a
  32. toHeaderBold = toPvsEntity >>> AD.toHeaderBold
  33. toHeaderLight ∷ forall a. ArtDecoCardElement a → Maybe (NonEmptyList a)
  34. toHeaderLight = toPvsEntity >>> AD.toHeaderLight
  35. toHeaderNormal ∷ forall a. ArtDecoCardElement a → Maybe a
  36. toHeaderNormal = toPvsEntity >>> AD.toHeaderNormal
  37. toPvsEntity ∷ forall a. ArtDecoCardElement a → ArtDecoPvsEntity a
  38. toPvsEntity (ArtDecoCardElement { pvs_entity }) = pvs_entity