@@ -1,17 +1,18 @@
11-- | This is the main module of the client-side Halogen app.
22module Docs.Search.App where
33
4+import Prelude
5+
6+import Control.Coroutine as Coroutine
7+import Data.Maybe (Maybe(..))
8+import Data.Newtype (wrap)
49import Docs.Search.App.SearchField as SearchField
510import Docs.Search.App.SearchResults as SearchResults
611import Docs.Search.App.Sidebar as Sidebar
12+import Docs.Search.Config (config)
713import Docs.Search.Extra (whenJust)
814import Docs.Search.ModuleIndex as ModuleIndex
915import Docs.Search.PackageIndex as PackageIndex
10−
11−import Prelude
12−import Control.Coroutine as Coroutine
13−import Data.Maybe (Maybe(..))
14−import Data.Newtype (wrap)
1516import Effect (Effect)
1617import Effect.Aff (launchAff_)
1718import Halogen as H
@@ -26,11 +27,11 @@ import Web.DOM.ParentNode as ParentNode
2627import Web.DOM.Text as Text
2728import Web.Event.EventTarget (addEventListener, eventListener)
2829import Web.HTML as HTML
30+import Web.HTML.Event.EventTypes (focus)
2931import Web.HTML.Event.HashChangeEvent.EventTypes (hashchange)
3032import Web.HTML.HTMLDocument as HTMLDocument
3133import Web.HTML.HTMLElement (fromElement)
3234import Web.HTML.Window as Window
33−import Web.HTML.Event.EventTypes (focus)
3435
3536
3637main :: Effect Unit
@@ -39,6 +40,7 @@ main = do
3940 doc <- HTMLDocument.toDocument <$> Window.document win
4041
4142 insertStyle doc
43+ insertVersionInfo doc
4244 mbContainers <- getContainers doc
4345
4446 -- Initialize a `markdown-it` instance (we need it to render the docs as markdown)
@@ -163,6 +165,26 @@ insertStyle doc = do
163165 void $ Node.appendChild (Element.toNode style) (Element.toNode head)
164166
165167
168+insertVersionInfo :: Document.Document -> Effect Unit
169+insertVersionInfo doc = do
170+ let docPN = Document.toParentNode doc
171+ mbVersionInfo <-
172+ ParentNode.querySelector (wrap ".footer > p") docPN
173+ whenJust (mbVersionInfo <#> Element.toNode)
174+ \versionInfo -> do
175+ prefix <- Document.createTextNode " - patched by " doc <#> Text.toNode
176+ linkElement <- Document.createElement "a" doc
177+ let linkNode = Element.toNode linkElement
178+ Element.setAttribute "href" "https://github.com/spacchetti/purescript-docs-search" linkElement
179+ Element.setAttribute "target" "_blank" linkElement
180+ linkText <- Document.createTextNode ("docs-search") doc <#> Text.toNode
181+ suffix <- Document.createTextNode (" " <> config.version) doc <#> Text.toNode
182+ void $ Node.appendChild prefix versionInfo
183+ void $ Node.appendChild linkNode versionInfo
184+ void $ Node.appendChild linkText linkNode
185+ void $ Node.appendChild suffix versionInfo
186+
187+
166188-- | Query the DOM for specific elements that should always be present.
167189getContainers
168190 :: Document.Document