Compare commits
2 commits
b3808f4136
...
c447aab1b9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c447aab1b9 | ||
|
|
009806c2b0 |
3 changed files with 27 additions and 17 deletions
|
|
@ -11,8 +11,9 @@ import Config
|
|||
import Control.Monad (when)
|
||||
import Data.Aeson (ToJSON (toJSON))
|
||||
import qualified Data.HashMap.Strict as HM
|
||||
import Data.List (sortOn)
|
||||
import Data.List (isSuffixOf, sortOn)
|
||||
import qualified Data.Ord as Ord
|
||||
import Data.String (IsString (fromString))
|
||||
import qualified Data.Text as T
|
||||
import Data.Traversable (traverse)
|
||||
import Deriving.Aeson
|
||||
|
|
@ -28,7 +29,7 @@ import Types
|
|||
import Utilities.Action (getPublishedPosts, isDraft', markdownToHtml, markdownToPost, now, psbProgress)
|
||||
import Utilities.Bundling (BuildOracleVariant (CSS, Javascript), bundled)
|
||||
import qualified Utilities.CSS as CSS
|
||||
import Utilities.FilePath (indexHtmlOutputPath, indexHtmlSourcePaths, isMarkdownPost, urlConvert)
|
||||
import Utilities.FilePath (indexHtmlOutputPath, indexHtmlSourcePaths, isMarkdownPost, map_filter, res_path_handle, urlConvert)
|
||||
import qualified Utilities.Javascript as JS
|
||||
|
||||
-- target = thing we want
|
||||
|
|
@ -58,6 +59,8 @@ buildSite = do
|
|||
Shake.need $ map (outputDir </>) assetPaths
|
||||
|
||||
-- handle js, css and anything else we want to process before moving
|
||||
-- to be honest I'm not sure what this is doing anymore but somehow
|
||||
-- it's making the resource files get built
|
||||
resourcePaths <- Shake.getDirectoryFiles "resources/" resourceGlobs
|
||||
Shake.need $ map resourceHashPath resourcePaths
|
||||
|
||||
|
|
@ -140,8 +143,8 @@ markdownPost src = do
|
|||
pageContent = postHtml,
|
||||
pageNow = time,
|
||||
pageUrl = urlConvert target,
|
||||
pageBundleCss = map T.pack css_bundle,
|
||||
pageBundleJs = map T.pack js_bundle
|
||||
pageBundleCss = filter map_filter $ map res_path_handle css_bundle,
|
||||
pageBundleJs = filter map_filter $ map res_path_handle js_bundle
|
||||
}
|
||||
applyTemplateAndWrite "default.html" page target
|
||||
|
||||
|
|
@ -166,8 +169,8 @@ home =
|
|||
pageContent = html,
|
||||
pageNow = time,
|
||||
pageUrl = urlConvert target,
|
||||
pageBundleCss = map T.pack css_bundle,
|
||||
pageBundleJs = map T.pack js_bundle
|
||||
pageBundleCss = filter map_filter $ map res_path_handle css_bundle,
|
||||
pageBundleJs = filter map_filter $ map res_path_handle js_bundle
|
||||
}
|
||||
applyTemplateAndWrite "default.html" page target
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import Data.Maybe (fromJust)
|
|||
import Data.String (IsString (fromString))
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as T
|
||||
import Development.Shake (Action, RuleResult, Rules, addOracle, addOracleCache, cmd_, command_, getDirectoryFiles, need, newCache, readFile', (%>))
|
||||
import Development.Shake (Action, RuleResult, Rules, Stderr (Stderr), Stdout (Stdout), addOracle, addOracleCache, cmd, command_, getDirectoryFiles, need, readFile', (%>))
|
||||
import Development.Shake.Classes
|
||||
import Development.Shake.FilePath ((</>))
|
||||
import GHC.Generics (Generic)
|
||||
|
|
@ -39,16 +39,8 @@ type instance RuleResult BuildOracleVariant = BuildOutputs
|
|||
resource_dir :: FilePath
|
||||
resource_dir = outputDir </> "resources"
|
||||
|
||||
-- TODO: not sure if I want all bundling to be an all at once afair, per file format
|
||||
-- or multiple stages for various formats
|
||||
--
|
||||
-- Regardless the objective is to produce all of that while outputting a file to
|
||||
-- indicate completion/fulfill a need directive without rebuilding even when files
|
||||
-- are left unchanged, maybe have the need be a $(filename).hash which we compute
|
||||
-- ourselves based on the unminified input
|
||||
bundled :: Rules ()
|
||||
bundled = do
|
||||
-- TODO: Need to adjust this oracle to split out source maps from js and css files
|
||||
oracle <- addOracleCache $ \q -> case q of
|
||||
CSS -> bundle_css
|
||||
Javascript -> bundle_scripts
|
||||
|
|
@ -69,6 +61,8 @@ css_esbuild_options =
|
|||
"--metafile=" ++ css_meta_file
|
||||
]
|
||||
|
||||
-- I'm aware that this json handling is simultaneously overkill and a hack job
|
||||
-- however I don't care, I generated this mostly with an LLM anyways
|
||||
newtype Metafile = Metafile
|
||||
{ outputs :: Object -- keys are the file paths
|
||||
}
|
||||
|
|
@ -93,7 +87,7 @@ bundle_css :: Action BuildOutputs
|
|||
bundle_css = do
|
||||
need cssGlobs
|
||||
css_files <- getDirectoryFiles "" cssGlobs
|
||||
cmd_ ("esbuild" :: String) (generic_esbuild_options ++ css_esbuild_options ++ css_files)
|
||||
(Stderr (), Stdout ()) <- cmd ("esbuild" :: String) (generic_esbuild_options ++ css_esbuild_options ++ css_files)
|
||||
metafile_outputs css_meta_file
|
||||
|
||||
-- Javascript and typescript
|
||||
|
|
@ -113,5 +107,5 @@ bundle_scripts :: Action BuildOutputs
|
|||
bundle_scripts = do
|
||||
need jsGlobs
|
||||
js_files <- getDirectoryFiles "" jsGlobs
|
||||
cmd_ ("esbuild" :: String) (generic_esbuild_options ++ js_esbuild_options ++ js_files)
|
||||
(Stderr (), Stdout ()) <- cmd ("esbuild" :: String) (generic_esbuild_options ++ js_esbuild_options ++ js_files)
|
||||
metafile_outputs js_meta_file
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
module Utilities.FilePath where
|
||||
|
||||
import Config
|
||||
import Data.String (IsString (fromString))
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as T
|
||||
import Development.Shake.FilePath ((<.>), (</>))
|
||||
|
|
@ -25,3 +26,15 @@ isMarkdownPost path = FP.takeExtension path == ".md"
|
|||
|
||||
urlConvert :: FilePath -> Text
|
||||
urlConvert = T.pack . FP.dropFileName . flip FP.replaceDirectory1 "https://pagwin.xyz"
|
||||
|
||||
res_path_handle :: String -> T.Text
|
||||
res_path_handle = T.pack . yeetTop
|
||||
|
||||
yeetTop :: FilePath -> FilePath
|
||||
yeetTop path = new_dir </> filename
|
||||
where
|
||||
new_dir = concat $ drop 1 $ FP.splitPath $ FP.takeDirectory path
|
||||
filename = FP.takeFileName path
|
||||
|
||||
map_filter :: T.Text -> Bool
|
||||
map_filter = not . (T.isSuffixOf $ fromString ".map")
|
||||
|
|
|
|||
Loading…
Reference in a new issue