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 +++++--- README | 74 +++++---------------------------------------- Setup.hs | 28 ++++++++++------- pancake.cabal | 1 + unclutter/duckduckgo.xsl | 24 +++++++++++++++ unclutter/github.xsl | 77 +++++++++++++++++++++++++++++++++++++++++++++++ unclutter/hacker-news.xsl | 33 ++++++++++++++++++++ unclutter/lobsters.xsl | 20 ++++++++++++ unclutter/mediawiki.xsl | 26 ++++++++++++++++ 10 files changed, 221 insertions(+), 83 deletions(-) create mode 100644 unclutter/duckduckgo.xsl create mode 100644 unclutter/github.xsl create mode 100644 unclutter/hacker-news.xsl create mode 100644 unclutter/lobsters.xsl create mode 100644 unclutter/mediawiki.xsl 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 diff --git a/README b/README index 76e58d6..662e9e9 100644 --- a/README +++ b/README @@ -85,78 +85,18 @@ emacs documentation (``C-h m``) for those. Configuration ------------- -Default configuration will be written into XDG configuration -directory, and would look approximately like this (slightly -simplified):: - - externalViewers: - png: xdg-open "${FILE}" - hs: emacsclient -n "${FILE}" - indentDivs: false - commands: - gopher: torify curl "${URI}" - ssh: scp "${URI_REGNAME}:${URI_PATH}" /dev/stdout - unclutter: - duckduckgo: ^https://duckduckgo\.com/lite/\?q= - defaultCommand: ! 'curl --compressed -4 -L -w " - - -pancake- - - uri: %{url_effective} - - type: %{content_type} - - " "${URI}"' - referenceDigits: 'rstwfpxcvaqzdgb' - shortcuts: - g: https://m.gutenberg.org/ebooks/search.mobile/?query= - ddg: https://duckduckgo.com/lite/?q= - wt: https://en.m.wiktionary.org/w/index.php?search= - wa: web-archive:///?url= - wp: https://en.m.wikipedia.org/wiki/Special:Search?search= - gp: gopher://gopherpedia.com:70/7/lookup? - vs: gopher://gopher.floodgap.com/7/v2/vs? - xiph: http://dir.xiph.org/search?search= - historyDepth: 100 - paginate: true +Default configuration will be written into XDG configuration directory +on ``pancake`` invocation if it's missing. Uncluttering ~~~~~~~~~~~~ -XSLT can be used to extract useful data from HTML documents. In the -above sample configuration, ``duckduckgo`` is defined along with an -URI regex to determine when it should be applied, and the -corresponding XSLT file should be in -``~/.config/pancake/unclutter/duckduckgo.xsl``:: - - - - - - - - DuckDuckGo - - -
-
- - - -
- -
- -
-
- - -
-
- -Uncluttering configurations for a few more websites can be found at -. +XSLT can be used to extract useful data from HTML documents, and XSLTs +for a few websites are provided by default. They can be read from +``unclutter`` subdirectory in either pancake's XDG config directory +(for custom XSLTs), or a data directory (for predefined XSLTs). + Screenshots ----------- diff --git a/Setup.hs b/Setup.hs index 1a01025..0015f6c 100644 --- a/Setup.hs +++ b/Setup.hs @@ -23,18 +23,24 @@ import Distribution.Simple.Setup import System.FilePath import System.Directory -main = defaultMainWithHooks simpleUserHooks { postCopy = installManPage } +main = defaultMainWithHooks simpleUserHooks { postCopy = installExtras } -- | Installs pancake.1. -installManPage :: Args - -> CopyFlags - -> PackageDescription - -> LocalBuildInfo - -> IO () -installManPage _ cf pd lbi = do +installExtras :: Args + -> CopyFlags + -> PackageDescription + -> LocalBuildInfo + -> IO () +installExtras _ cf pd lbi = do let dirs = absoluteInstallDirs pd lbi (fromFlag $ copyDest cf) - man1 = mandir dirs "man1" - fname = "pancake.1" - target = man1 fname + verbosity = fromFlag $ copyVerbosity cf + -- todo: use absoluteComponentInstallDirs once will switch to + -- cabal 2, e.g.: + -- absoluteComponentInstallDirs pd lbi (localUnitId lbi) + -- (fromFlag $ copyDest cf) + -- install man page + let man1 = mandir dirs "man1" + manFileName = "pancake.1" + manTarget = man1 manFileName createDirectoryIfMissing True man1 - installOrdinaryFile (fromFlag $ copyVerbosity cf) fname target + installOrdinaryFile verbosity manFileName manTarget diff --git a/pancake.cabal b/pancake.cabal index e5bb95f..06aa7fc 100644 --- a/pancake.cabal +++ b/pancake.cabal @@ -21,6 +21,7 @@ extra-source-files: ChangeLog.md , pancake.1 , Makefile , deb/DEBIAN/control +data-files: unclutter/*.xsl cabal-version: >=1.10 source-repository head type: git diff --git a/unclutter/duckduckgo.xsl b/unclutter/duckduckgo.xsl new file mode 100644 index 0000000..2bf6e2b --- /dev/null +++ b/unclutter/duckduckgo.xsl @@ -0,0 +1,24 @@ + + + + + + + DuckDuckGo + + +
+
+ + + +
+ +
+ +
+
+ + +
+
diff --git a/unclutter/github.xsl b/unclutter/github.xsl new file mode 100644 index 0000000..c4e42d4 --- /dev/null +++ b/unclutter/github.xsl @@ -0,0 +1,77 @@ + + + + + + + + + + + + + +

+ + + | + + + + + +

+
+ + + +
+ + + () +
+
+
+
+ + + +
+      
+        
+        

+      
+    
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/unclutter/hacker-news.xsl b/unclutter/hacker-news.xsl new file mode 100644 index 0000000..0f8c352 --- /dev/null +++ b/unclutter/hacker-news.xsl @@ -0,0 +1,33 @@ + + + + + + + Hacker News + + + + + +
+
+ + + +
+
+ +
+ + | + + + +
+
+
+ + +
+
diff --git a/unclutter/lobsters.xsl b/unclutter/lobsters.xsl new file mode 100644 index 0000000..92b58a7 --- /dev/null +++ b/unclutter/lobsters.xsl @@ -0,0 +1,20 @@ + + + + + + + Lobsters + +

+ +
+ + | + +

+
+ + +
+
diff --git a/unclutter/mediawiki.xsl b/unclutter/mediawiki.xsl new file mode 100644 index 0000000..1b88b4a --- /dev/null +++ b/unclutter/mediawiki.xsl @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3