on master help sign in
Use a class to identify injected configs
commit152a7169b4c4b9f837d9d365c680eb9b329255bd authorKen Micklas <ken.micklas@obsidian.systems> dateMon 29 Apr 2019, 11:55 (7 years ago) parentbf19268
3 files changed+7−9
lib/executable-config/inject/src/Obelisk/ExecutableConfig/Inject.hs+1−1 lib/executable-config/lookup/src-ghcjs/Obelisk/ExecutableConfig/Internal.hs+2−2 lib/frontend/src/Obelisk/Frontend.hs+4−6
lib/executable-config/inject/src/Obelisk/ExecutableConfig/Inject.hs+1−1
@@ -22,7 +22,7 @@ inject key = do
2222-- whose value is the provided configuration
2323injectPure :: DomBuilder t m => Text -> Text -> m ()
2424injectPure key value =
25− let attrs = ("type" =: "text/plain" <> "id" =: ("config-" <> key) <> "data-executable-config-inject" =: "1")
25+ let attrs = ("type" =: "text/plain" <> "id" =: ("config-" <> key) <> "class" =: "obelisk-executable-config-inject")
2626 in elAttr "script" attrs $ text value
2727
2828-- | Scans the "common" and "frontend" configuration folders and produces
lib/executable-config/lookup/src-ghcjs/Obelisk/ExecutableConfig/Internal.hs+2−2
@@ -10,7 +10,7 @@ import qualified Data.Text as T
1010import Data.Traversable (for)
1111import GHCJS.DOM
1212import GHCJS.DOM.Document (getHead)
13−import GHCJS.DOM.Element (Element, getElementsByTagName, getId, getInnerHTML)
13+import GHCJS.DOM.Element (getElementsByClassName, getId, getInnerHTML)
1414import GHCJS.DOM.HTMLCollection (HTMLCollection, item, getLength)
1515import GHCJS.DOM.NonElementParentNode
1616
@@ -18,7 +18,7 @@ getFrontendConfigs :: IO [(Text, Text)]
1818getFrontendConfigs = fmap concat $ runMaybeT $ do
1919 doc <- MaybeT currentDocument
2020 hd <- MaybeT $ getHead doc
21− es <- collToList =<< getElementsByTagName hd ("script" :: Text)
21+ es <- collToList =<< getElementsByClassName hd ("obelisk-executable-config-inject" :: Text)
2222 cfg <- for es $ \e -> runMaybeT $ do
2323 ident <- getId e
2424 k <- MaybeT $ pure $ T.stripPrefix "config-" ident
lib/frontend/src/Obelisk/Frontend.hs+4−6
@@ -32,12 +32,12 @@ import Data.ByteString (ByteString)
3232import Data.Foldable (for_)
3333import Data.Functor.Sum
3434import qualified Data.Map as Map
35−import Data.Maybe (catMaybes, isJust)
35+import Data.Maybe (catMaybes)
3636import Data.Monoid ((<>))
3737import Data.Text (Text)
3838import GHCJS.DOM (currentDocument)
3939import GHCJS.DOM.Document (getHead)
40−import GHCJS.DOM.Element (getAttribute, getElementsByTagName)
40+import GHCJS.DOM.Element (getElementsByClassName)
4141import GHCJS.DOM.HTMLCollection (item, getLength)
4242import GHCJS.DOM.Node (removeChild_)
4343import Language.Javascript.JSaddle (JSM)
@@ -96,10 +96,8 @@ removeHTMLConfigs :: JSM ()
9696removeHTMLConfigs = void $ runMaybeT $ do
9797 doc <- MaybeT currentDocument
9898 hd <- MaybeT $ getHead doc
99− es <- collToList =<< getElementsByTagName hd ("script" :: Text)
100− for_ es $ \e -> do
101− isConfig <- (isJust :: Maybe Text -> Bool) <$> getAttribute e ("data-executable-config-inject" :: Text)
102− when isConfig $ removeChild_ hd e
99+ es <- collToList =<< getElementsByClassName hd ("obelisk-executable-config-inject" :: Text)
100+ for_ es $ removeChild_ hd
103101 where
104102 collToList es = do
105103 len <- getLength es