소스 검색

Add main API functions for future library

jherve 1 년 전
부모
커밋
3a93aed9df
3개의 변경된 파일18개의 추가작업 그리고 23개의 파일을 삭제
  1. 1 0
      package.json
  2. 3 21
      src/Content.purs
  3. 14 2
      src/LinkedIn.purs

+ 1 - 0
package.json

@@ -18,6 +18,7 @@
   "license": "ISC",
   "devDependencies": {
     "concurrently": "^5.2.0",
+    "esbuild": "^0.20.0",
     "jsdom": "^23.2.0",
     "parcel": "^2.11.0",
     "spago": "^0.21.0",

+ 3 - 21
src/Content.purs

@@ -3,33 +3,15 @@ module ExampleWebExt.Content where
 import Prelude
 
 import Browser.DOM (getBrowserDom)
-import Data.Either (Either(..))
 import Effect (Effect)
 import Effect.Class.Console (logShow)
 import Effect.Console (log)
-import LinkedIn (getContext, run)
-import LinkedIn.Output (toOutput)
-import LinkedIn.Page.JobOffer (JobOfferPage)
-import LinkedIn.Page.Projects (ProjectsPage)
-import LinkedIn.Page.Skills (SkillsPage)
-import LinkedIn.Page.WorkExperiences (WorkExperiencesPage)
-import Type.Proxy (Proxy(..))
+import LinkedIn (extractFromDocument, getContext)
 
 main :: Effect Unit
 main = do
   log "[content] starting up"
 
   dom <- getBrowserDom
-
-  run (Proxy :: Proxy WorkExperiencesPage) dom >>= logShow
-  run (Proxy :: Proxy SkillsPage) dom >>= logShow
-  run (Proxy :: Proxy ProjectsPage) dom >>= logShow
-  run (Proxy :: Proxy JobOfferPage) dom >>= logShow
-
-  ctx <- getContext dom
-
-  logShow ctx
-
-  case ctx of
-    Left l -> logShow l
-    Right r -> toOutput r dom >>= logShow
+  getContext dom >>= logShow
+  extractFromDocument dom >>= logShow

+ 14 - 2
src/LinkedIn.purs

@@ -1,11 +1,12 @@
-module LinkedIn (module LinkedIn.Output, getContext) where
+module LinkedIn (getContext, extractFromDocument, extractFromDocumentInContext) where
 
 import Prelude
 
 import Data.Either (Either(..))
 import Data.Maybe (Maybe(..))
 import Effect (Effect)
-import LinkedIn.Output (run, runToDetached, toOutput)
+import LinkedIn.Output (toOutput)
+import LinkedIn.Output.Types (Output)
 import LinkedIn.PageUrl (PageUrl, pageUrlP)
 import Parsing (runParser)
 import Web.DOM (Document)
@@ -20,3 +21,14 @@ getContext dom = do
     Just u' -> case runParser (U.pathname u') pageUrlP of
       Left _ -> Left "Unexpected URL"
       Right page -> Right page
+
+extractFromDocument :: Document -> Effect (Either String Output)
+extractFromDocument dom = do
+  ctx <- getContext dom
+
+  case ctx of
+    Left l -> pure $ Left l
+    Right ctx' -> toOutput ctx' dom
+
+extractFromDocumentInContext :: PageUrl -> Document -> Effect (Either String Output)
+extractFromDocumentInContext = toOutput