From f0e10a9ea21f351f2617b23f2e615f8d82f089bd Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Fri, 6 Nov 2015 02:12:44 +0000 Subject: hashing for math filenames --- blog.cabal | 3 +++ blog.nix | 4 ++-- src/Site.hs | 6 +++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/blog.cabal b/blog.cabal index f1e3c0b..7ad97a7 100644 --- a/blog.cabal +++ b/blog.cabal @@ -27,3 +27,6 @@ executable site , pandoc-types >=1.12 && <2 , data-default >=0.5 && <0.6 , filepath >=1.3 && <2 + , bytestring >=0.10 && <1 + , cryptohash >=0.11 && <1 + , hex >=0.1 && <1 diff --git a/blog.nix b/blog.nix index a4c5d8c..ecb0022 100644 --- a/blog.nix +++ b/blog.nix @@ -1,7 +1,7 @@ # This file was auto-generated by cabal2nix. Please do NOT edit manually! { mkDerivation, stdenv -, hakyll, containers, pandoc, data-default, filepath +, hakyll, containers, pandoc, data-default, filepath, hex, cryptohash }: mkDerivation { @@ -11,7 +11,7 @@ mkDerivation { isExecutable = true; isLibrary = false; buildDepends = [ - hakyll containers pandoc data-default filepath + hakyll containers pandoc data-default filepath hex cryptohash ]; license = stdenv.lib.licenses.publicDomain; } diff --git a/src/Site.hs b/src/Site.hs index 279532f..1bda7ec 100644 --- a/src/Site.hs +++ b/src/Site.hs @@ -17,6 +17,10 @@ import Text.Pandoc.Walk (query) import Text.Pandoc.Error import Control.Applicative (Alternative(..), Applicative(..)) +import qualified Crypto.Hash.SHA256 as SHA256 (hash) +import qualified Data.ByteString.Char8 as CBS +import Data.Hex + import System.FilePath (takeBaseName, (), (<.>)) main :: IO () @@ -135,7 +139,7 @@ tagTranslation = mapMaybe charTrans | otherwise = Nothing mathTranslation' :: String -> Identifier -mathTranslation' = fromCapture "math/*.svg" . id -- TODO hash math +mathTranslation' = fromCapture "math/*.svg" . CBS.unpack . hex . SHA256.hash . CBS.pack addTag :: MonadMetadata m => String -> Pattern -> Tags -> m Tags addTag name pattern tags = do -- cgit v1.2.3