Skip to content

Commit 192b154

Browse files
Set example language field for correct highlighting
1 parent a92fb77 commit 192b154

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

message-index/site.hs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ main = hakyll $ do
7676
( mconcat
7777
[ urlField "url",
7878
field "name" (pure . view _1 . itemBody),
79+
-- Set the language that highlight.js should use for syntax highlighting
80+
field "language" $ \(itemBody -> (filename, _, _)) ->
81+
pure $ case dropWhile (== '.') $ takeExtension filename of
82+
"hs" -> "haskell"
83+
other -> other,
7984
field "before" (maybe (pure "<not present>") (fmap itemBody . load . itemIdentifier) . view _2 . itemBody),
8085
field "after" (maybe (pure "<not present>") (fmap itemBody . load . itemIdentifier) . view _3 . itemBody)
8186
]
@@ -193,10 +198,14 @@ getExampleFiles = do
193198
["messages", id, exampleName, _mdFile] -> pure (id, exampleName)
194199
_ -> fail "Not processing an example"
195200

196-
let beforePattern = foldl1 (.||.) $ exampleExtensions <&> \ext ->
197-
fromGlob ("messages/" <> id <> "/" <> exampleName <> "/before/*." <> ext)
198-
afterPattern = foldl1 (.||.) $ exampleExtensions <&> \ext ->
199-
fromGlob ("messages/" <> id <> "/" <> exampleName <> "/after/*." <> ext)
201+
let beforePattern =
202+
foldl1 (.||.) $
203+
exampleExtensions <&> \ext ->
204+
fromGlob ("messages/" <> id <> "/" <> exampleName <> "/before/*." <> ext)
205+
afterPattern =
206+
foldl1 (.||.) $
207+
exampleExtensions <&> \ext ->
208+
fromGlob ("messages/" <> id <> "/" <> exampleName <> "/after/*." <> ext)
200209

201210
before <- loadAll (beforePattern .&&. hasVersion "raw")
202211
after <- loadAll (afterPattern .&&. hasVersion "raw")

message-index/templates/example.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
<div class="example-inner">
77
<div class="example-title">Before</div>
88
<!-- keep next line as is, i.e., on one line, or the code will not format properly -->
9-
<pre class="example-pre"><code class="language-haskell">$before$</code></pre>
9+
<pre class="example-pre"><code class="language-$language$">$before$</code></pre>
1010
</div>
1111
</div>
1212
<div class="example">
1313
<div class="example-inner">
1414
<div class="example-title">After</div>
1515
<!-- keep next line as is, i.e., on one line, or the code will not format propertly -->
16-
<pre class="example-pre"><code class="language-haskell">$after$</code></pre>
16+
<pre class="example-pre"><code class="language-$language$">$after$</code></pre>
1717
</div>
1818
</div>
1919
</div>

0 commit comments

Comments
 (0)