From e30b1d9e22fcf49d523166aa63860522ed56bc2c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20Walker?=
Date: Tue, 26 May 2015 19:19:57 -0300
Subject: [PATCH] Refactor assets path handling
---
{css => assets/css}/default.css | 0
{css => assets/css}/fonts.css | 0
{css => assets/css}/syntax.css | 0
{css => assets/css}/webicons.css | 0
{fonts => assets/fonts}/BreeSerif.woff | Bin
{fonts => assets/fonts}/BubblegumSans.woff | Bin
{fonts => assets/fonts}/Lora.woff | Bin
{js => assets/js}/modernizr.js | 0
.../webicons}/webicon-github-m.png | Bin
.../webicons}/webicon-github-s.png | Bin
.../webicons}/webicon-github.png | Bin
.../webicons}/webicon-github.svg | 0
.../webicons}/webicon-linkedin-m.png | Bin
.../webicons}/webicon-linkedin-s.png | Bin
.../webicons}/webicon-linkedin.svg | 0
.../webicons}/webicon-mail-m.png | Bin
.../webicons}/webicon-mail-s.png | Bin
.../webicons}/webicon-mail.png | Bin
.../webicons}/webicon-mail.svg | 0
.../webicons}/webicon-rss-m.png | Bin
.../webicons}/webicon-rss-s.png | Bin
{webicons => assets/webicons}/webicon-rss.png | Bin
{webicons => assets/webicons}/webicon-rss.svg | 0
.../webicons}/webicon-twitter-m.png | Bin
.../webicons}/webicon-twitter-s.png | Bin
.../webicons}/webicon-twitter.png | Bin
.../webicons}/webicon-twitter.svg | 0
hakyll-awn.cabal | 1 +
images/moustache.svg | 60 ------------
src/Main.hs | 86 ++++++++++--------
templates/default.html | 4 +-
31 files changed, 52 insertions(+), 99 deletions(-)
rename {css => assets/css}/default.css (100%)
rename {css => assets/css}/fonts.css (100%)
rename {css => assets/css}/syntax.css (100%)
rename {css => assets/css}/webicons.css (100%)
rename {fonts => assets/fonts}/BreeSerif.woff (100%)
rename {fonts => assets/fonts}/BubblegumSans.woff (100%)
rename {fonts => assets/fonts}/Lora.woff (100%)
rename {js => assets/js}/modernizr.js (100%)
rename {webicons => assets/webicons}/webicon-github-m.png (100%)
rename {webicons => assets/webicons}/webicon-github-s.png (100%)
rename {webicons => assets/webicons}/webicon-github.png (100%)
rename {webicons => assets/webicons}/webicon-github.svg (100%)
rename {webicons => assets/webicons}/webicon-linkedin-m.png (100%)
rename {webicons => assets/webicons}/webicon-linkedin-s.png (100%)
rename {webicons => assets/webicons}/webicon-linkedin.svg (100%)
rename {webicons => assets/webicons}/webicon-mail-m.png (100%)
rename {webicons => assets/webicons}/webicon-mail-s.png (100%)
rename {webicons => assets/webicons}/webicon-mail.png (100%)
rename {webicons => assets/webicons}/webicon-mail.svg (100%)
rename {webicons => assets/webicons}/webicon-rss-m.png (100%)
rename {webicons => assets/webicons}/webicon-rss-s.png (100%)
rename {webicons => assets/webicons}/webicon-rss.png (100%)
rename {webicons => assets/webicons}/webicon-rss.svg (100%)
rename {webicons => assets/webicons}/webicon-twitter-m.png (100%)
rename {webicons => assets/webicons}/webicon-twitter-s.png (100%)
rename {webicons => assets/webicons}/webicon-twitter.png (100%)
rename {webicons => assets/webicons}/webicon-twitter.svg (100%)
delete mode 100644 images/moustache.svg
diff --git a/css/default.css b/assets/css/default.css
similarity index 100%
rename from css/default.css
rename to assets/css/default.css
diff --git a/css/fonts.css b/assets/css/fonts.css
similarity index 100%
rename from css/fonts.css
rename to assets/css/fonts.css
diff --git a/css/syntax.css b/assets/css/syntax.css
similarity index 100%
rename from css/syntax.css
rename to assets/css/syntax.css
diff --git a/css/webicons.css b/assets/css/webicons.css
similarity index 100%
rename from css/webicons.css
rename to assets/css/webicons.css
diff --git a/fonts/BreeSerif.woff b/assets/fonts/BreeSerif.woff
similarity index 100%
rename from fonts/BreeSerif.woff
rename to assets/fonts/BreeSerif.woff
diff --git a/fonts/BubblegumSans.woff b/assets/fonts/BubblegumSans.woff
similarity index 100%
rename from fonts/BubblegumSans.woff
rename to assets/fonts/BubblegumSans.woff
diff --git a/fonts/Lora.woff b/assets/fonts/Lora.woff
similarity index 100%
rename from fonts/Lora.woff
rename to assets/fonts/Lora.woff
diff --git a/js/modernizr.js b/assets/js/modernizr.js
similarity index 100%
rename from js/modernizr.js
rename to assets/js/modernizr.js
diff --git a/webicons/webicon-github-m.png b/assets/webicons/webicon-github-m.png
similarity index 100%
rename from webicons/webicon-github-m.png
rename to assets/webicons/webicon-github-m.png
diff --git a/webicons/webicon-github-s.png b/assets/webicons/webicon-github-s.png
similarity index 100%
rename from webicons/webicon-github-s.png
rename to assets/webicons/webicon-github-s.png
diff --git a/webicons/webicon-github.png b/assets/webicons/webicon-github.png
similarity index 100%
rename from webicons/webicon-github.png
rename to assets/webicons/webicon-github.png
diff --git a/webicons/webicon-github.svg b/assets/webicons/webicon-github.svg
similarity index 100%
rename from webicons/webicon-github.svg
rename to assets/webicons/webicon-github.svg
diff --git a/webicons/webicon-linkedin-m.png b/assets/webicons/webicon-linkedin-m.png
similarity index 100%
rename from webicons/webicon-linkedin-m.png
rename to assets/webicons/webicon-linkedin-m.png
diff --git a/webicons/webicon-linkedin-s.png b/assets/webicons/webicon-linkedin-s.png
similarity index 100%
rename from webicons/webicon-linkedin-s.png
rename to assets/webicons/webicon-linkedin-s.png
diff --git a/webicons/webicon-linkedin.svg b/assets/webicons/webicon-linkedin.svg
similarity index 100%
rename from webicons/webicon-linkedin.svg
rename to assets/webicons/webicon-linkedin.svg
diff --git a/webicons/webicon-mail-m.png b/assets/webicons/webicon-mail-m.png
similarity index 100%
rename from webicons/webicon-mail-m.png
rename to assets/webicons/webicon-mail-m.png
diff --git a/webicons/webicon-mail-s.png b/assets/webicons/webicon-mail-s.png
similarity index 100%
rename from webicons/webicon-mail-s.png
rename to assets/webicons/webicon-mail-s.png
diff --git a/webicons/webicon-mail.png b/assets/webicons/webicon-mail.png
similarity index 100%
rename from webicons/webicon-mail.png
rename to assets/webicons/webicon-mail.png
diff --git a/webicons/webicon-mail.svg b/assets/webicons/webicon-mail.svg
similarity index 100%
rename from webicons/webicon-mail.svg
rename to assets/webicons/webicon-mail.svg
diff --git a/webicons/webicon-rss-m.png b/assets/webicons/webicon-rss-m.png
similarity index 100%
rename from webicons/webicon-rss-m.png
rename to assets/webicons/webicon-rss-m.png
diff --git a/webicons/webicon-rss-s.png b/assets/webicons/webicon-rss-s.png
similarity index 100%
rename from webicons/webicon-rss-s.png
rename to assets/webicons/webicon-rss-s.png
diff --git a/webicons/webicon-rss.png b/assets/webicons/webicon-rss.png
similarity index 100%
rename from webicons/webicon-rss.png
rename to assets/webicons/webicon-rss.png
diff --git a/webicons/webicon-rss.svg b/assets/webicons/webicon-rss.svg
similarity index 100%
rename from webicons/webicon-rss.svg
rename to assets/webicons/webicon-rss.svg
diff --git a/webicons/webicon-twitter-m.png b/assets/webicons/webicon-twitter-m.png
similarity index 100%
rename from webicons/webicon-twitter-m.png
rename to assets/webicons/webicon-twitter-m.png
diff --git a/webicons/webicon-twitter-s.png b/assets/webicons/webicon-twitter-s.png
similarity index 100%
rename from webicons/webicon-twitter-s.png
rename to assets/webicons/webicon-twitter-s.png
diff --git a/webicons/webicon-twitter.png b/assets/webicons/webicon-twitter.png
similarity index 100%
rename from webicons/webicon-twitter.png
rename to assets/webicons/webicon-twitter.png
diff --git a/webicons/webicon-twitter.svg b/assets/webicons/webicon-twitter.svg
similarity index 100%
rename from webicons/webicon-twitter.svg
rename to assets/webicons/webicon-twitter.svg
diff --git a/hakyll-awn.cabal b/hakyll-awn.cabal
index 67f6700..ee8e76d 100644
--- a/hakyll-awn.cabal
+++ b/hakyll-awn.cabal
@@ -8,6 +8,7 @@ executable site
build-depends: base == 4.8.*
, hakyll == 4.6.*
, pandoc
+ , filepath
, bytestring
, time == 1.5.*
ghc-options: -threaded -Wall
diff --git a/images/moustache.svg b/images/moustache.svg
deleted file mode 100644
index c989a48..0000000
--- a/images/moustache.svg
+++ /dev/null
@@ -1,60 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/src/Main.hs b/src/Main.hs
index f5d9f14..5f4a0b3 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -8,6 +8,7 @@ import Data.Monoid ((<>))
import qualified Data.ByteString.Lazy as LB
import Text.Pandoc
import Text.Pandoc.PDF (makePDF)
+import System.FilePath
import Portuguese
import Hakyll
@@ -21,8 +22,11 @@ config = defaultConfiguration {
rules :: Rules ()
rules = do
- deploymentId <- preprocess getDeploymentId
+ staticId <- preprocess getStaticId
+ rulesWithStaticId staticId
+rulesWithStaticId :: Integer -> Rules ()
+rulesWithStaticId staticId = do
match "keybase.txt" $ do
route idRoute
compile copyFileCompiler
@@ -31,28 +35,28 @@ rules = do
route idRoute
compile copyFileCompiler
- match "webicons/*" $ do
- route idRoute
+ match "assets/webicons/*" $ do
+ route $ assetsRoute' "webicons/"
compile copyFileCompiler
- match "fonts/*" $ do
- route idRoute
+ match "assets/fonts/*" $ do
+ route $ assetsRoute' "fonts/"
compile copyFileCompiler
- match "js/*" $ do
- route idRoute
+ match "assets/js/*" $ do
+ route $ assetsRoute' "js/"
compile copyFileCompiler
- -- FIXME: how to avoid this? I only want style.css, so the other css files
- -- shouldn't be copied.
- match "css/*" $ do
- route idRoute
+ match "assets/css/*" $ do
+ -- Uncomment the following line for debugging:
+ -- route idRoute
+ -- And access at http://localhost:8000/assets/css
compile $ getResourceBody >>= saveSnapshot "raw"
create ["style.css"] $ do
- route $ assetsRoute deploymentId
+ route $ assetsRoute' ""
compile $ do
- items <- loadAllSnapshots "css/*" "raw"
+ items <- loadAllSnapshots "assets/css/*" "raw"
makeItem $ compressCss $ concat $ map itemBody (items :: [Item String])
match "cv.md" $ do
@@ -62,11 +66,9 @@ rules = do
match "pages/*" $ do
route pagesRoute
compile $ do
- let ctx = defaultContext <> constField "deploymentId" (show deploymentId)
-
pandocCompiler
- >>= loadAndApplyTemplate "templates/page.html" ctx
- >>= loadAndApplyTemplate "templates/default.html" ctx
+ >>= loadAndApplyTemplate "templates/page.html" siteCtx'
+ >>= loadAndApplyTemplate "templates/default.html" siteCtx'
>>= relativizeUrls
tags <- buildTags "posts/*" (fromCapture "tags/*.html")
@@ -78,9 +80,8 @@ rules = do
posts <- recentFirst =<< loadAll pattern
let ctx = mconcat
[ constField "title" title
- , constField "deploymentId" (show deploymentId)
- , listField "posts" postCtx (return posts)
- , defaultContext
+ , listField "posts" postCtx' (return posts)
+ , siteCtx'
]
makeItem ""
@@ -91,10 +92,7 @@ rules = do
match "posts/*" $ do
route $ setExtension "html"
compile $ do
- let postCtxWithTags =
- tagsField "tags" tags <>
- constField "deploymentId" (show deploymentId) <>
- postCtx
+ let postCtxWithTags = tagsField "tags" tags <> postCtx'
pandocCompiler
>>= saveSnapshot "content"
@@ -106,12 +104,12 @@ rules = do
route idRoute
compile $ do
posts <- recentFirst =<< loadAll "posts/*"
+
let archiveCtx = mconcat
- [ listField "posts" postCtx (return posts)
+ [ listField "posts" postCtx' (return posts)
, constField "title" "Arquivo"
- , constField "deploymentId" (show deploymentId)
, field "tagcloud" (\_ -> renderTagCloud 100 250 (sortTagsBy caseInsensitiveTags tags))
- , defaultContext
+ , siteCtx'
]
makeItem ""
@@ -122,9 +120,10 @@ rules = do
create ["atom.xml"] $ do
route idRoute
compile $ do
- let feedCtx = bodyField "description" <> postCtx
+ let feedCtx = bodyField "description" <> postCtx'
posts <- fmap (take 10) . recentFirst =<< loadAllSnapshots "posts/*" "content"
+
renderAtom feedConfiguration feedCtx posts
blog <- buildPaginateWith
@@ -142,10 +141,9 @@ rules = do
let paginateCtx = paginateContext blog pageNum
let ctx = mconcat
[ constField "title" "Home"
- , constField "deploymentId" (show deploymentId)
- , listField "posts" (postCtx <> paginateCtx) (return posts)
+ , listField "posts" (postCtx' <> paginateCtx) (return posts)
, paginateCtx
- , defaultContext
+ , siteCtx'
]
makeItem ""
@@ -155,6 +153,11 @@ rules = do
match "templates/*" $ compile templateCompiler
+ where
+ postCtx' = postCtx staticId
+ siteCtx' = siteCtx staticId
+ assetsRoute' = assetsRoute staticId
+
getPdfTemplate :: IO String
getPdfTemplate = do
templ <- getDefaultTemplate Nothing "latex"
@@ -182,8 +185,8 @@ pdfCompiler = do
dateFieldLoc :: String -> String -> Context a
dateFieldLoc = dateFieldWith timeLocalePtBr
-postCtx :: Context String
-postCtx = mconcat
+postCtx :: Integer -> Context String
+postCtx staticId = mconcat
[ teaserField "teaser" "content"
, dateFieldLoc "date" "%e de %B, %Y"
, dateFieldLoc "date_full" "%F"
@@ -191,6 +194,12 @@ postCtx = mconcat
, dateFieldLoc "date_day" "%d"
, dateFieldLoc "date_month" "%b"
, dateFieldLoc "date_year" "%Y"
+ , siteCtx staticId
+ ]
+
+siteCtx :: Integer -> Context String
+siteCtx staticId = mconcat
+ [ constField "staticId" (show staticId)
, defaultContext
]
@@ -203,11 +212,14 @@ feedConfiguration = FeedConfiguration
, feedRoot = "https://andrewalker.net"
}
-getDeploymentId :: IO Integer
-getDeploymentId = round `fmap` getPOSIXTime
+getStaticId :: IO Integer
+getStaticId = round `fmap` getPOSIXTime
-assetsRoute :: Integer -> Routes
-assetsRoute id' = customRoute $ ((show id') ++) . toFilePath
+assetsRoute :: Integer -> String -> Routes
+assetsRoute staticId folder = customRoute $ prefixPlus . takeFileName . toFilePath
+ where
+ prefix = (show staticId) ++ "/" ++ folder
+ prefixPlus = (prefix ++)
pagesRoute :: Routes
pagesRoute =
diff --git a/templates/default.html b/templates/default.html
index e7de410..ce6c3d0 100644
--- a/templates/default.html
+++ b/templates/default.html
@@ -5,7 +5,7 @@
$title$ - andrewalker.net
-
+
-
+