beginning work on CSS and JS minification
This commit is contained in:
parent
2bf95b0295
commit
dfeffdef2b
6 changed files with 53 additions and 3 deletions
4
TODO.md
4
TODO.md
|
|
@ -1,4 +1,8 @@
|
||||||
- [ ] minify js and css when copying over instead of just copying
|
- [ ] minify js and css when copying over instead of just copying
|
||||||
|
- CSS
|
||||||
|
- https://github.com/wereHamster/haskell-css-syntax
|
||||||
|
- JS
|
||||||
|
- https://hackage.haskell.org/package/language-ecmascript
|
||||||
- [ ] setup fingerprinting in file names for css and js
|
- [ ] setup fingerprinting in file names for css and js
|
||||||
- [ ] process source code blocks to syntax highlight them
|
- [ ] process source code blocks to syntax highlight them
|
||||||
- tree sitter https://hackage.haskell.org/package/tree-sitter
|
- tree sitter https://hackage.haskell.org/package/tree-sitter
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,8 @@ common warnings
|
||||||
|
|
||||||
library
|
library
|
||||||
hs-source-dirs: src
|
hs-source-dirs: src
|
||||||
exposed-modules: Markdown HTML Logger IR Logger.Shake Psb.Main Utilities Utilities.FilePath Utilities.Action Templates Types Config
|
exposed-modules: Markdown HTML Logger IR Logger.Shake Psb.Main Utilities Utilities.FilePath Utilities.Action Utilities.Javascript Utilities.CSS Templates Types Config
|
||||||
build-depends: base >=4.20 && < 4.21, mustache >=2.4.2, shake >= 0.19.8, deriving-aeson >= 0.2.9, aeson, text >= 2.1.2, time, unordered-containers, yaml, megaparsec >= 9.7.0, transformers >= 0.6.2
|
build-depends: base >=4.20 && < 4.21, mustache >=2.4.2, shake >= 0.19.8, deriving-aeson >= 0.2.9, aeson, text >= 2.1.2, time, unordered-containers, yaml, megaparsec >= 9.7.0, transformers >= 0.6.2, css-syntax >= 0.1.0.2, language-ecmascript >= 0.19.1.0
|
||||||
default-extensions: ApplicativeDo DataKinds NamedFieldPuns DerivingVia LambdaCase TypeApplications DeriveGeneric OverloadedRecordDot NamedFieldPuns DuplicateRecordFields DisambiguateRecordFields FlexibleInstances
|
default-extensions: ApplicativeDo DataKinds NamedFieldPuns DerivingVia LambdaCase TypeApplications DeriveGeneric OverloadedRecordDot NamedFieldPuns DuplicateRecordFields DisambiguateRecordFields FlexibleInstances
|
||||||
|
|
||||||
test-suite test-markdown-parse
|
test-suite test-markdown-parse
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,20 @@ outputDir :: String
|
||||||
outputDir = "publish"
|
outputDir = "publish"
|
||||||
|
|
||||||
assetGlobs :: [String]
|
assetGlobs :: [String]
|
||||||
assetGlobs = ["static//*", "robots.txt", "sw.js", "favicon.ico"]
|
assetGlobs = ["static//*", "robots.txt", "favicon.ico"]
|
||||||
|
|
||||||
|
-- this insanity is to avoid repetition
|
||||||
|
resourceGlobs :: [String]
|
||||||
|
resourceGlobs = jsGlobs ++ cssGlobs
|
||||||
|
|
||||||
|
prependResources :: (Functor m) => m String -> m String
|
||||||
|
prependResources = fmap ("resources/" ++)
|
||||||
|
|
||||||
|
jsGlobs :: [String]
|
||||||
|
jsGlobs = prependResources $ liftA2 (++) ["js//*."] ["js", "mjs"]
|
||||||
|
|
||||||
|
cssGlobs :: [String]
|
||||||
|
cssGlobs = prependResources $ liftA2 (++) ["css//*."] ["css"]
|
||||||
|
|
||||||
-- CAN ONLY BE TYPST DOCS UNLESS YOU CHANGE THINGS AT THE `pages` RULE in `Main.hs
|
-- CAN ONLY BE TYPST DOCS UNLESS YOU CHANGE THINGS AT THE `pages` RULE in `Main.hs
|
||||||
pagePaths :: [String]
|
pagePaths :: [String]
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,9 @@ import qualified Development.Shake.FilePath as FP
|
||||||
import Templates
|
import Templates
|
||||||
import Types
|
import Types
|
||||||
import Utilities.Action (getPublishedPosts, isDraft', markdownToHtml, markdownToPost, now, psbProgress)
|
import Utilities.Action (getPublishedPosts, isDraft', markdownToHtml, markdownToPost, now, psbProgress)
|
||||||
|
import qualified Utilities.CSS as CSS
|
||||||
import Utilities.FilePath (indexHtmlOutputPath, indexHtmlSourcePaths, isMarkdownPost, urlConvert)
|
import Utilities.FilePath (indexHtmlOutputPath, indexHtmlSourcePaths, isMarkdownPost, urlConvert)
|
||||||
|
import qualified Utilities.Javascript as JS
|
||||||
|
|
||||||
-- target = thing we want
|
-- target = thing we want
|
||||||
-- Rule = pattern of thing being made + actions to produce the thing
|
-- Rule = pattern of thing being made + actions to produce the thing
|
||||||
|
|
@ -51,6 +53,9 @@ buildSite = do
|
||||||
-- path concat each asset path so it's output into the outputDir
|
-- path concat each asset path so it's output into the outputDir
|
||||||
Shake.need $ map (outputDir </>) assetPaths
|
Shake.need $ map (outputDir </>) assetPaths
|
||||||
|
|
||||||
|
-- handle js, css and anything else we want to process before moving
|
||||||
|
Shake.need <$> Shake.getDirectoryFiles "" resourceGlobs
|
||||||
|
|
||||||
-- take the misc pages which aren't blog posts and make their html files
|
-- take the misc pages which aren't blog posts and make their html files
|
||||||
Shake.need $ map indexHtmlOutputPath pagePaths
|
Shake.need $ map indexHtmlOutputPath pagePaths
|
||||||
|
|
||||||
|
|
@ -67,6 +72,8 @@ buildRules = do
|
||||||
assets
|
assets
|
||||||
postsRule
|
postsRule
|
||||||
rss
|
rss
|
||||||
|
css_resources
|
||||||
|
js_resources
|
||||||
|
|
||||||
-- make a rule of the pattern outputDir/asset_name which copes from outputDir/../pages
|
-- make a rule of the pattern outputDir/asset_name which copes from outputDir/../pages
|
||||||
assets :: Rules ()
|
assets :: Rules ()
|
||||||
|
|
@ -75,6 +82,18 @@ assets =
|
||||||
let src = FP.dropDirectory1 target
|
let src = FP.dropDirectory1 target
|
||||||
Shake.copyFileChanged src target
|
Shake.copyFileChanged src target
|
||||||
|
|
||||||
|
css_resources :: Rules ()
|
||||||
|
css_resources =
|
||||||
|
map (outputDir </>) cssGlobs |%> \target -> do
|
||||||
|
src <- Shake.readFile' $ FP.dropDirectory1 target
|
||||||
|
Shake.writeFileChanged target $ CSS.minify src
|
||||||
|
|
||||||
|
js_resources :: Rules ()
|
||||||
|
js_resources =
|
||||||
|
map (outputDir </>) jsGlobs |%> \target -> do
|
||||||
|
src <- Shake.readFile' $ FP.dropDirectory1 target
|
||||||
|
Shake.writeFileChanged target $ JS.minify src
|
||||||
|
|
||||||
-- there's probably a better way of doing this that allows for the target's origin file extension to get passed in but for now we're doing brute force
|
-- there's probably a better way of doing this that allows for the target's origin file extension to get passed in but for now we're doing brute force
|
||||||
postsRule :: Rules ()
|
postsRule :: Rules ()
|
||||||
postsRule =
|
postsRule =
|
||||||
|
|
|
||||||
7
src/Utilities/CSS.hs
Normal file
7
src/Utilities/CSS.hs
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
module Utilities.CSS
|
||||||
|
( minify,
|
||||||
|
)
|
||||||
|
where
|
||||||
|
|
||||||
|
minify :: String -> String
|
||||||
|
minify = id
|
||||||
7
src/Utilities/Javascript.hs
Normal file
7
src/Utilities/Javascript.hs
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
module Utilities.Javascript
|
||||||
|
( minify,
|
||||||
|
)
|
||||||
|
where
|
||||||
|
|
||||||
|
minify :: String -> String
|
||||||
|
minify = id
|
||||||
Loading…
Reference in a new issue