Providing static HTML with a tree

How can I use a structure hamletto create static HTML pages from inside Haskell?

Note. This question intentionally does not show research efforts. For my research, see Q & A-style answer below.

+4
source share
1 answer

hamletgives QuasiQuoters that are evaluated in expressions blaze. Using Text.Blaze.Html.Renderer.String.renderHtml, you can display them in a row.

Let's start with a simple example other than HTML:

{-# LANGUAGE QuasiQuotes #-}
import Text.Blaze.Html.Renderer.String (renderHtml)
import Text.Hamlet

greet name = [shamlet|Hello world #{name}|]
-- This prints "Hello world John Foo"
main = putStrLn $ renderHtml $ greet "John Foo"

You can also use TextinsteadString Text.Blaze.Html.Renderer.Text.renderHtml

Haskell. , , writeFile putStrLn.

main = do writeFile "greet.txt" $ renderHtml $ greet "John Foo"

HTML . . .

{-# LANGUAGE QuasiQuotes #-}
import Text.Blaze.Html.Renderer.String (renderHtml)
import Text.Hamlet

greet name = [shamlet|
                $doctype 5
                <html>
                    <head>
                        <title>Greeting for #{name}
                    <body>
                        <h2>
                            Hello world #{name}|]

main = writeFile "greet.html" $ renderHtml $ greet "John Foo"

greet.html HTML-.

+7

Source: https://habr.com/ru/post/1523382/


All Articles