36
SMART STATIC SITES WITH HAKYLL -Eric Rasmussen

Smart Static Sites (PDF) - Chromatic Leaves

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Smart Static Sites (PDF) - Chromatic Leaves

SMART STATIC SITESWITH HAKYLL

-Eric Rasmussen

Page 2: Smart Static Sites (PDF) - Chromatic Leaves

BACK TO THE 90'S

Page 3: Smart Static Sites (PDF) - Chromatic Leaves

ERIC'S HOME PAGE!!!

Page 4: Smart Static Sites (PDF) - Chromatic Leaves

Maybe not those 90's

Page 5: Smart Static Sites (PDF) - Chromatic Leaves

But static sites are coming back in style

Page 6: Smart Static Sites (PDF) - Chromatic Leaves

WHAT ARE STATIC SITE GENERATORS?think of them as build toolsturn any input into htmlrebuild when content changes

Page 7: Smart Static Sites (PDF) - Chromatic Leaves

BUT REALLY... WHY?minimalismreduce security concernsversion controlit's fun

Page 8: Smart Static Sites (PDF) - Chromatic Leaves

TEXT FORMAT OF YOUR CHOICEmarkdownReSTructured textLaTeXMediaWiki

Page 9: Smart Static Sites (PDF) - Chromatic Leaves

SYNTAX HIGHLIGHTINGmatch ("about.markdown" .||. "commands.markdown") $ do route $ setExtension "html" compile $ pandocCompiler >>= applyBase >>= relativizeUrls

Page 10: Smart Static Sites (PDF) - Chromatic Leaves

"What's hard to ignore about all these platforms is that, your dadwill never blog like this."

-Mike Bayer (author of SQLAlchemy)

Page 11: Smart Static Sites (PDF) - Chromatic Leaves

WHY NOT?takes time to configurethe wild wild westgeek factor

Page 12: Smart Static Sites (PDF) - Chromatic Leaves

HAKYLL

Page 13: Smart Static Sites (PDF) - Chromatic Leaves

RULES-BASED EDSLconfiguration via code

match ("images/*" .||. "js/**") $ do route idRoute compile copyFileCompiler

match ("css/*" .||. "css/icons/*" .||. "foundation/*") $ do route $ setExtension "css" compile sassCompiler

Page 14: Smart Static Sites (PDF) - Chromatic Leaves

FEATURESdependency resolutionsimple file metadatasnapshots (during build)

Page 15: Smart Static Sites (PDF) - Chromatic Leaves

HAKYLL BUILT-INStags and tag cloud renderingrss/atom feed generationcode syntax highlightingtemplating

Page 16: Smart Static Sites (PDF) - Chromatic Leaves

EXAMPLE: RENDER POSTSmatch "posts/*" $ do route $ setExtension "html" compile $ pandocCompiler >>= saveSnapshot "content" >>= loadAndApplyTemplate "templates/post.html" postCtx >>= loadAndApplyTemplate "templates/base.html" baseCtx >>= relativizeUrls

Page 17: Smart Static Sites (PDF) - Chromatic Leaves

EXAMPLE: CREATE AN ATOM FEEDcreate ["atom.xml"] $ do route idRoute compile $ do loadAllSnapshots "posts/*" "content" >>= fmap (take 10) . recentFirst >>= renderAtom (feedConfiguration "All posts") feedCtx

Page 18: Smart Static Sites (PDF) - Chromatic Leaves

EXAMPLE: CREATE A CONTEXTdefaultPostCtx :: Tags -> Context StringdefaultPostCtx tags = mconcat [ dateField "date" "%B %e, %Y" , tagsField "tags" tags , defaultContext ]

Page 19: Smart Static Sites (PDF) - Chromatic Leaves

EXAMPLE: SASS/SCSS COMPILERsassCompiler :: Compiler (Item String)sassCompiler = getResourceString >>= withItemBody (unixFilter "sass" ["-s", "--scss"]) >>= return . fmap compressCss

Page 20: Smart Static Sites (PDF) - Chromatic Leaves

PANDOCSwiss-army knife of markupCan parse several markdown/markup formatsCan output to html, tex, pdf, and other formats

Page 21: Smart Static Sites (PDF) - Chromatic Leaves

GO DYNAMIC WITH JAVASCRIPTvisual effectsindexed search (sphinx)comments (Disqus, Branch)live feeds (twitter, app.net)

Page 22: Smart Static Sites (PDF) - Chromatic Leaves

THE HASKELL CONNECTIONYou don't need to know Haskell for HakyllBut know that Haskell is awesomeModern type systems are expressive and productiveBeginner friendly community

Page 23: Smart Static Sites (PDF) - Chromatic Leaves

DRAWBACKS

Page 24: Smart Static Sites (PDF) - Chromatic Leaves

HASKELL IS... TOO AWESOME?"a monad is a monoid in the category of endofunctors, what's the

problem?"

Page 25: Smart Static Sites (PDF) - Chromatic Leaves

FOR COMPLEX SITESHaskell knowledge likely requiredDSLs can be hard to hack onbut there are open source examples

Page 26: Smart Static Sites (PDF) - Chromatic Leaves

WHERE TO BEGINThe Hakyll tutorials are a great starting point

But if you already have a favorite language, try:

pelican (python)jekyll (ruby)nanoc (ruby)middleman (ruby)high_voltage (ruby)

(ruby devs like DSLs)

(but you can find examples in most languages)

Page 27: Smart Static Sites (PDF) - Chromatic Leaves

A WORD OF CAUTIONThe good news: typically no proprietary format or DB, but...

Static site generators come and goPrepare for breaking changes/tinkeringNo security patches! (good thing)

Page 28: Smart Static Sites (PDF) - Chromatic Leaves

DEPLOYMENTit's plain html and assetsso you can deploy just about anywherersync -zrv mysite/ user@host:~/mysite/GitHub Pages (http://pages.github.com/)

Page 29: Smart Static Sites (PDF) - Chromatic Leaves

CSS FOR NON-DESIGNERSDon't do itJust... don't

Page 30: Smart Static Sites (PDF) - Chromatic Leaves
Page 31: Smart Static Sites (PDF) - Chromatic Leaves

THE EASY WAYUse twitter bootstrapOr zurb foundationLearn grid systems and responsive classes

Page 32: Smart Static Sites (PDF) - Chromatic Leaves

DESKTOP

Use grid layouts to design big

Page 33: Smart Static Sites (PDF) - Chromatic Leaves

MOBILE

Design small at the same time

Page 34: Smart Static Sites (PDF) - Chromatic Leaves

SASSvariables -- $blue: #3bbfce;functions -- darken($blue, 9%);like coding, but notreduces CSS madness boilerplatecompile with your build process

Page 35: Smart Static Sites (PDF) - Chromatic Leaves

CHOOSE YOUR OWN ADVENTUREQ&A

haskellhakylljavascript + servicesresponsive design