Skip to content
Snippets Groups Projects
Select Git revision
  • 2851a59dee1b862197f7c4c28f702ffd14818528
  • test default protected
  • thing
  • master protected
  • niki-stuff2
  • feat/niki-stuff
  • feat/custom-css
  • feat/redesign-improvements-10
  • feat/redesign-improvements-8
  • feat/redesign-fixes-3
  • feat/pirstan-changes
  • feat/separate-import-thread
  • feat/dary-improvements
  • features/add-pdf-page
  • features/add-typed-table
  • features/fix-broken-calendar-categories
  • features/add-embed-to-articles
  • features/create-mastodon-feed-block
  • features/add-custom-numbering-for-candidates
  • features/add-timeline
  • features/create-wordcloud-from-article-page
21 results

feed_item_description.html

  • Link.hs 2.27 KiB
    {-|
    Module      :  Hikaru.Link
    Copyright   :  Jan Hamal Dvořák
    License     :  AGPL-3
    
    Maintainer  :  mordae@anilinux.org
    Stability   :  unstable
    Portability :  non-portable (ghc)
    
    This module provides various ways to build local links.
    -}
    
    module Hikaru.Link
      ( makeLink
      , deriveLink
    
      -- ** Lucid Integration
      , lhref_
      , phref_
      , qhref_
      )
    where
      import BasePrelude
    
      import Data.Binary.Builder
      import Data.ByteString (ByteString)
      import Data.String.Conversions
      import Data.Text (Text)
      import Lucid
      import Network.HTTP.Types.URI
      import Hikaru.Action
    
    
      -- |
      -- Combine path segments and parameters to create an internal Link.
      --
      -- Examples:
      --
      -- >>> makeLink ["api", "echo"] []
      -- "/api/echo"
      -- >>> makeLink ["char", ""] [("name", "haruhi")]
      -- "/char/?name=haruhi"
      --
      makeLink :: [Text] -> [(Text, Text)] -> Text
      makeLink ps qs = cs $ toLazyByteString $ encodePath ps $ csQueryTuple qs
    
    
      -- |
      -- Create a link with just the query string by updating the
      -- parameters sent by the client.
      --
      -- All keys that appear in the new parameter list are first deleted
      -- from the current parameter list, then the new list is appended to
      -- the current one.
      --
      -- Useful to create dynamic pages with multiple independent widgets.
      --
      deriveLink :: (MonadAction m) => [(Text, Text)] -> m Text
      deriveLink ps = do
        ops <- getParams
        return $ makeLink [] $ update ops ps
    
    
      csQueryTuple :: [(Text, Text)] -> [(ByteString, Maybe ByteString)]
      csQueryTuple = map \(n, v) -> (cs n, Just (cs v))
    
    
      update :: [(Text, Text)] -> [(Text, Text)] -> [(Text, Text)]
      update old new = deleteNewKeys old <> new
        where
          deleteNewKeys = filter \(n, _) -> n `notElem` newKeys
          newKeys = map fst new
    
    
      -- Lucid Integration -------------------------------------------------------
    
    
      -- |
      -- Create a @href@ attribute using 'makeLink'.
      --
      lhref_ :: [Text] -> [(Text, Text)] -> Attribute
      lhref_ ps qs = href_ (makeLink ps qs)
    
    
      -- |
      -- Same as 'lhref_', but without any query parameters.
      --
      phref_ :: [Text] -> Attribute
      phref_ ps = href_ (makeLink ps [])
    
    
      -- |
      -- Same as 'lhref_', but without any path components.
      --
      qhref_ :: [(Text, Text)] -> Attribute
      qhref_ qs = href_ (makeLink [] qs)
    
    
    -- vim:set ft=haskell sw=2 ts=2 et: