Skip to content

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
irv committed Feb 23, 2014
1 parent f016d96 commit 182e29e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
23 changes: 7 additions & 16 deletions src/site.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,13 @@ getListPrev i l = l !! checkBounds (fromMaybe 0 (i `elemIndex` l) +1 )
where checkBounds x | x > length l -1 = length l-1 | otherwise = x

constructDiff :: String -> [[Diff [String]]] -> Compiler (Item String)

constructDiff i d = makeItem i
>>= loadAndApplyTemplate "templates/diff.html" (field "diff" (\_ -> diff' d) <> commonContext)
>>= loadAndApplyTemplate "templates/default.html" commonContext
>>= relativizeUrls
where diff' [] = return []
diff' x = renderDiff $ head x

makeRevisionCompiler :: Compiler (Item String)
makeRevisionCompiler = do
path <- toFilePath <$> getUnderlying
revisionList <- getRevisionList
diff' <- unsafeCompiler (getDiff path revisionList)
unsafeCompiler (putStrLn (takeFileName path))
constructDiff (takeFileName path) diff'
--createDiffItem [(fromFilePath (takeFileName path))] diff'
--let gd = constructDiff path diff'
-- makeItem (diff_ident revisionList, gd)
-- where diff_ident i = fromFilePath $ ("diffs/" ++ revId ( fst $ head $ snd i)) ++ ("_" ++ revId ( snd $ head $ snd i)) ++ ".markdown"
-- diff_ident (_, (b,c):_) = fromFilePath $ "diffs/" ++ (show $ revId b) ++ "_" ++ (show $ revId c)
-- diff_ident (a, []) = fromFilePath $ a

routePage :: Routes
routePage = customRoute fileToDirectory

Expand All @@ -91,6 +76,7 @@ addRevisionList = do
lst <- unsafeCompiler $ getRevisions $ takeFileName path
return (concatMap renderRevision lst)

-- used to create a link to the diff between two revisions
renderRevision :: (Revision, Revision) -> String
renderRevision rl = renderHtml $ H.tr $ do
H.td $ H.toHtml $ createLink rl
Expand Down Expand Up @@ -158,8 +144,13 @@ main = hakyll $ do
>>= relativizeUrls
--diffs <- buildDiffsWith "articles/*" (fromCapture "diffs/*.html")

-- it's a right pain in the arse that you can't use the match function here. would be nice to do something like
-- match "articles" $ preprocess $ do ids <- getMatches
-- or something like that.
-- diffs ends up being Rules [Map Identifier [(Revision,Revision)]]
diffs <- preprocess $ do
-- let ids = concat $ getMatches "articles/*"
-- this is a bit brittle. use Hakyll internal function to get the list of all files in here
-- which we know is where our git repo is
ids <- getRecursiveContents (const $ return False) "articles"
let ids' = map (fromFilePath) ids
mapM buildDiffs ids'
Expand Down
6 changes: 3 additions & 3 deletions whistlepig.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ cabal-version: >=1.8

executable whistlepig
-- .hs or .lhs file containing the Main module.
-- main-is:
main-is: site.hs

-- Modules included in this executable, other than Main.
-- other-modules:

-- Other library packages from which modules are imported.
build-depends: base ==4.6.*, hakyll >=4.4.*
build-depends: base == 4.6.*, hakyll >= 4.4, Diff >= 0.3.0, containers >= 0.5, pandoc >= 1.12, filepath >= 1.3, blaze-html >= 0.6, filestore >=0.6, binary >= 0.5

-- Directories containing source files.
hs-source-dirs: src

GHC-Options: -Wall

0 comments on commit 182e29e

Please sign in to comment.