Compare commits

..

No commits in common. "c447aab1b97a1c5e2160d369003424a455635bc5" and "b3808f4136774abe1478f9094919614e618619ce" have entirely different histories.

3 changed files with 17 additions and 27 deletions

View file

@ -11,9 +11,8 @@ import Config
import Control.Monad (when)
import Data.Aeson (ToJSON (toJSON))
import qualified Data.HashMap.Strict as HM
import Data.List (isSuffixOf, sortOn)
import Data.List (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
@ -29,7 +28,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, map_filter, res_path_handle, urlConvert)
import Utilities.FilePath (indexHtmlOutputPath, indexHtmlSourcePaths, isMarkdownPost, urlConvert)
import qualified Utilities.Javascript as JS
-- target = thing we want
@ -59,8 +58,6 @@ 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
@ -143,8 +140,8 @@ markdownPost src = do
pageContent = postHtml,
pageNow = time,
pageUrl = urlConvert target,
pageBundleCss = filter map_filter $ map res_path_handle css_bundle,
pageBundleJs = filter map_filter $ map res_path_handle js_bundle
pageBundleCss = map T.pack css_bundle,
pageBundleJs = map T.pack js_bundle
}
applyTemplateAndWrite "default.html" page target
@ -169,8 +166,8 @@ home =
pageContent = html,
pageNow = time,
pageUrl = urlConvert target,
pageBundleCss = filter map_filter $ map res_path_handle css_bundle,
pageBundleJs = filter map_filter $ map res_path_handle js_bundle
pageBundleCss = map T.pack css_bundle,
pageBundleJs = map T.pack js_bundle
}
applyTemplateAndWrite "default.html" page target

View file

@ -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, Stderr (Stderr), Stdout (Stdout), addOracle, addOracleCache, cmd, command_, getDirectoryFiles, need, readFile', (%>))
import Development.Shake (Action, RuleResult, Rules, addOracle, addOracleCache, cmd_, command_, getDirectoryFiles, need, newCache, readFile', (%>))
import Development.Shake.Classes
import Development.Shake.FilePath ((</>))
import GHC.Generics (Generic)
@ -39,8 +39,16 @@ 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
@ -61,8 +69,6 @@ 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
}
@ -87,7 +93,7 @@ bundle_css :: Action BuildOutputs
bundle_css = do
need cssGlobs
css_files <- getDirectoryFiles "" cssGlobs
(Stderr (), Stdout ()) <- cmd ("esbuild" :: String) (generic_esbuild_options ++ css_esbuild_options ++ css_files)
cmd_ ("esbuild" :: String) (generic_esbuild_options ++ css_esbuild_options ++ css_files)
metafile_outputs css_meta_file
-- Javascript and typescript
@ -107,5 +113,5 @@ bundle_scripts :: Action BuildOutputs
bundle_scripts = do
need jsGlobs
js_files <- getDirectoryFiles "" jsGlobs
(Stderr (), Stdout ()) <- cmd ("esbuild" :: String) (generic_esbuild_options ++ js_esbuild_options ++ js_files)
cmd_ ("esbuild" :: String) (generic_esbuild_options ++ js_esbuild_options ++ js_files)
metafile_outputs js_meta_file

View file

@ -1,7 +1,6 @@
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 ((<.>), (</>))
@ -26,15 +25,3 @@ 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")