From b11b05385b5615aaf08bd245af53e8df03a193b3 Mon Sep 17 00:00:00 2001 From: defanor Date: Thu, 28 Dec 2017 05:03:26 +0300 Subject: Install and enable a few uncluttering XSLTs by default --- Pancake/Configuration.hs | 8 +++++++- Pancake/Unclutter.hs | 13 +++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'Pancake') diff --git a/Pancake/Configuration.hs b/Pancake/Configuration.hs index bfac392..c01ad96 100644 --- a/Pancake/Configuration.hs +++ b/Pancake/Configuration.hs @@ -109,7 +109,13 @@ instance Default Config where , historyDepth = 100 , referenceDigits = "0123456789" , indentDivs = False - , unclutter = M.empty + , unclutter = M.fromList + [ ("duckduckgo", "^https://duckduckgo\\.com/lite/\\?q=") + , ("lobsters", "^https://lobste\\.rs/((page|recent|newest).*)?$") + , ("hacker-news", + "^https://news\\.ycombinator\\.com/((news|show|ask).*)?$") + , ("mediawiki", "^https://en\\.(m.)?(wiktionary|wikipedia)\\.org/wiki/") + , ("github", "^https://github\\.com/")] } where curl = "curl --compressed -4 -L " ++ diff --git a/Pancake/Unclutter.hs b/Pancake/Unclutter.hs index cf5132e..2169e00 100644 --- a/Pancake/Unclutter.hs +++ b/Pancake/Unclutter.hs @@ -47,12 +47,13 @@ import Data.Text.Encoding (decodeUtf8', decodeLatin1, encodeUtf8) import qualified Data.Text as T import Control.Exception - import Pancake.Common import Pancake.Configuration +import Paths_pancake -- | Tries to unclutter a document by applying an XSLT if it's --- available. +-- available. Looks for a file in a user config directory first, and +-- in the system data directory then. tryUnclutter :: MonadIO m => [(Regex, String)] -- ^ Obtained with 'prepareUnclutter'. @@ -67,8 +68,12 @@ tryUnclutter rs u d = liftIO $ handle err $ do _ -> False case find matches rs of Just (_, fn) -> do - dir <- getXdgDirectory XdgConfig "pancake" - let src = dir "unclutter" fn <.> "xsl" + src <- do + configDir <- getXdgDirectory XdgConfig "pancake" + let src = configDir "unclutter" fn <.> "xsl" + exists <- doesFileExist src + dataDir <- getDataDir + pure $ if exists then src else dataDir "unclutter" fn <.> "xsl" exists <- doesFileExist src if exists then do -- cgit v1.2.3