Skip to content

Commit 8a935cc

Browse files
committed
highlight code from ports
1 parent c56d78b commit 8a935cc

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

app/Route/Blog/Slug_.elm

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
module Route.Blog.Slug_ exposing (ActionData, Data, Model, Msg, route)
1+
port module Route.Blog.Slug_ exposing (ActionData, Data, Model, Msg, route)
22

33
import Article exposing (ArticleMetadata)
44
import BackendTask exposing (BackendTask)
55
import Css exposing (..)
6+
import Effect exposing (Effect)
67
import FatalError exposing (FatalError)
78
import Head
89
import Head.Seo as Seo
@@ -38,7 +39,12 @@ route =
3839
, pages = pages
3940
, data = data
4041
}
41-
|> RouteBuilder.buildNoState { view = view }
42+
|> RouteBuilder.buildWithLocalState
43+
{ view = view
44+
, init = \_ _ -> ( Model, Effect.fromCmd (highlightJS ()) )
45+
, update = \_ _ _ _ -> ( Model, Effect.none )
46+
, subscriptions = \_ _ _ _ -> Sub.none
47+
}
4248

4349

4450
pages : BackendTask FatalError (List RouteParams)
@@ -93,6 +99,7 @@ head app =
9399
view :
94100
App Data ActionData RouteParams
95101
-> Shared.Model
102+
-> Model
96103
-> View (PagesMsg Msg)
97104
view app sharedModel =
98105
{ title = app.data.metadata.title
@@ -128,3 +135,6 @@ content app =
128135
[ fontSize (px 18) ]
129136
]
130137
]
138+
139+
140+
port highlightJS : () -> Cmd msg

index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ const config: ElmPagesInit = {
3939
console.log('Added event listener for mousemove homepage')
4040
}
4141

42-
console.log('Highlighting code blocks')
43-
hljs.highlightAll();
42+
app.ports.highlightJS.subscribe(function (message) {
43+
console.log('Highlighting code blocks')
44+
hljs.highlightAll();
45+
});
4446
},
4547
flags: function () {
4648
return "You can decode this in Shared.elm using Json.Decode.string!";

0 commit comments

Comments
 (0)