Asset

An “asset” is simply a ByteString (written to disk) or FilePath (copied) that siteOutput of EmaSite typically produces. It is defined as:

-- | The type of assets that can be bundled in a static site.
data Asset a
  = -- | A file that is copied as-is from the source directory.
    --
    -- Relative paths are assumed relative to the source directory. Absolute
    -- paths allow copying static files outside of source directory.
    AssetStatic FilePath
  | -- | A file whose contents are generated at runtime by user code.
    AssetGenerated Format a
  deriving stock (Eq, Show, Ord, Functor, Generic)

-- | The format of a generated asset.
data Format
  = -- | Html assets are served by the live server with hot-reload
    Html
  | -- | Other assets are served by the live server as static files.
    Other
  deriving stock (Eq, Show, Ord, Generic)

HTML asset

Live Server specifically looks at the Asset Generated . Html asset and Hot Reloads the browser on its change.

Static file asset

The AssetStatic fp asset is copied as-is from the source directory to the destination directory. In Live Server the file is served directly from the given path. See Ema.Route.Lib.Extra.StaticRoute for example.

Other assets

Any generated route that is not HTML (eg: RSS) must use the AssetGenerated . Other type.

Links to this page
  • Hello World
    The EmaSite typeclass defines the “site pipeline” – the input Model type and the output Asset:
  • EmaSite

    The siteOutput method takes the Model type value snapshot at that point in time, as well as the route value to render and returns a Asset output (typically HTML bytestring) for it. siteOutput has IO capabilities; usually it is defined as a pure function (siteOutput ... = pure <expr>) inasmuch as all the data required to render the site is contained in the Model type, but sometimes you may need IO (example).