MyModel and the route
Route shown in the previous section, we can create an instance as follows:
class Ema MyModel Route where -- Where to generate this route? encodeRoute _model = \case Index -> "index.html" About -> "about.html" -- Which route does this filepath correspond to? decodeRoute _model = \case "index.html" -> Just Index "about.html" -> Just About _ -> Nothing -- The third method is optional, and used by the `gen` command (not live-server) -- By default, Enum & Bounded will be used to determine this list. allRoutes model = [Index, About]
Ema typeclass has three methods, one of them being optional:
encodeRoutethat converts our route type to a filepath
decodeRoutethat does the reverse converstion (the conversion must be isomorphic)
allRoutesindicating the routes to statically generate
Ema constraint is used by the
runEma function that acts as the main entry point to your static site generator. It takes two arguments:
renderfunction that renders your route (usually to HTML); we’ll go over this in the next section.
an IO action that takes
LVar modelas an argument.
This IO action is expected to be a long-running one, wherein you have full control over setting the value of the model over time.
Next, with our model and routes in place constrained by
Ema type class, we will define the HTML for our site using Ema.