Compare commits

..

No commits in common. "7c4fea02d164657ba16b956fc856285148b06505" and "ce75f2ae7d1041d3b4e21d5ffdfac354e44c9623" have entirely different histories.

2 changed files with 7 additions and 42 deletions

View File

@ -24,7 +24,6 @@ import Network.Wai (Application)
import Servant import Servant
( Accept (..) ( Accept (..)
, Handler , Handler
, Header
, MimeRender (..) , MimeRender (..)
, Server , Server
, ServerError (..) , ServerError (..)
@ -62,18 +61,14 @@ app :: Application
app = serve (Proxy :: Proxy API) server app = serve (Proxy :: Proxy API) server
type API = type API =
Header "Host" Text :> Get '[PlainText, HTML] RootModel "utf8" :> Capture "bytes" Text :> Get '[PlainText, HTML] Utf8Model
:<|> "utf8" :> Capture "bytes" Text :> Get '[PlainText, HTML] Utf8Model
:<|> "codepoints" :> Capture "codepoints" Text :> Get '[PlainText, HTML] CodepointsModel :<|> "codepoints" :> Capture "codepoints" Text :> Get '[PlainText, HTML] CodepointsModel
:<|> "text" :> Capture "text" Text :> Get '[PlainText, HTML] TextModel :<|> "text" :> Capture "text" Text :> Get '[PlainText, HTML] TextModel
server :: Server API server :: Server API
server = server =
rootR :<|> utf8R :<|> codepointsR :<|> textR utf8R :<|> codepointsR :<|> textR
where where
rootR host = do
pure $ RootModel $ fromMaybe "" host
utf8R bytesP = do utf8R bytesP = do
bytes <- Parsers.parseHexBytes bytesP `orThrow` const err400 bytes <- Parsers.parseHexBytes bytesP `orThrow` const err400
pure $ mkUtf8Model bytes pure $ mkUtf8Model bytes
@ -85,38 +80,6 @@ server =
textR textP = do textR textP = do
pure $ TextModel textP pure $ TextModel textP
-- /
newtype RootModel = RootModel
{ host :: Text
}
examples :: [Text]
examples =
[ "/text/✅🤔"
, "/codepoints/x2705+x1F914"
, "/utf8/e2.9c.85.f0.9f.a4.94"
]
instance MimeRender PlainText RootModel where
mimeRender _ model = renderText $ Text.unlines $
[ "⚞ utoy ⚟"
, ""
, "This is utoy, a URL-based Unicode playground. Examples:"
, ""
] ++ map (urlBase <>) examples
where
-- We assume HTTPS here. Doesn't work for development on localhost.
urlBase = "https://" <> model.host
instance MimeRender HTML RootModel where
mimeRender _ model = renderHtml $ documentWithBody $ do
H.h1 $ H.toHtml ("⚞ utoy ⚟" :: Text)
H.p $ H.toHtml ("This is utoy, a URL-based Unicode playground. Examples:" :: Text)
H.ul $ for_ examples $ \example -> do
let url = "https://" <> model.host <> example
H.li $ H.a ! A.href (H.toValue url) $ H.toHtml example
-- /bytes/<bytes> -- /bytes/<bytes>
newtype Utf8Model = Utf8Model newtype Utf8Model = Utf8Model
@ -234,7 +197,7 @@ instance MimeRender HTML TextModel where
instance MimeRender PlainText TextModel where instance MimeRender PlainText TextModel where
mimeRender _ model = renderText $ Table.render " " mimeRender _ model = renderText $ Table.render " "
[ map Table.cl [ map (Table.cl)
[ Text.pack [c] [ Text.pack [c]
, Text.pack $ printf "U+%04X" c , Text.pack $ printf "U+%04X" c
, Text.pack $ intercalate ", " $ allNames c , Text.pack $ intercalate ", " $ allNames c
@ -278,7 +241,7 @@ documentWithBody body =
H.meta ! A.charset "utf-8" H.meta ! A.charset "utf-8"
H.title "utoy" H.title "utoy"
H.style $ H.toHtml $ Encoding.decodeUtf8 $(embedFile "static/utoy.css") H.style $ H.toHtml $ Encoding.decodeUtf8 $(embedFile "static/utoy.css")
H.body $ H.main body H.body body
-- HTML routes -- HTML routes

View File

@ -21,7 +21,9 @@
# The build is simply a call to makeWrapper, so we don't have to # The build is simply a call to makeWrapper, so we don't have to
# do any of the typical build steps. # do any of the typical build steps.
phases = [ "installPhase" ]; dontUnpack = true;
dontConfigure = true;
dontBuild = true;
nativeBuildInputs = [ pkgs.makeWrapper ]; nativeBuildInputs = [ pkgs.makeWrapper ];
# makeBinaryWrapper creates a stack executable for us that uses # makeBinaryWrapper creates a stack executable for us that uses