From 0b1c8b0fd0b8ae7bb615e6ad515f071d4cc07efc Mon Sep 17 00:00:00 2001 From: towards-a-new-leftypol Date: Wed, 6 Mar 2024 00:37:48 -0500 Subject: [PATCH] Move quotedPosts and collectBacklinks into Common.PostBodyUtils --- src/Common | 2 +- src/Parsing/BodyParser.hs | 25 +------------------------ 2 files changed, 2 insertions(+), 25 deletions(-) diff --git a/src/Common b/src/Common index 738f76c..7e0cfd5 160000 --- a/src/Common +++ b/src/Common @@ -1 +1 @@ -Subproject commit 738f76cb9a56cc397a7b9c1efc844fbf6622dea8 +Subproject commit 7e0cfd57269bb631417a9bcf9f9f071520000a88 diff --git a/src/Parsing/BodyParser.hs b/src/Parsing/BodyParser.hs index 40cea9b..9501680 100644 --- a/src/Parsing/BodyParser.hs +++ b/src/Parsing/BodyParser.hs @@ -12,7 +12,6 @@ module Parsing.BodyParser ) where import Data.Maybe (catMaybes) -import qualified Data.Map as Map import GHCJS.DOM (currentDocument) import GHCJS.DOM.Types ( Element (..) @@ -28,10 +27,10 @@ import GHCJS.DOM.JSFFI.Generated.DOMTokenList (contains) import Data.Text (Text) import Miso (consoleLog) import Miso.String (fromMisoString) -import Common.Component.Thread.Model (PostWithBody) import Common.Parsing.PostPartType import Common.Parsing.QuoteLinkParser +import Common.Parsing.PostBodyUtils nodeListToList :: NodeList -> IO [ Node ] @@ -143,25 +142,3 @@ parseS :: Element -> IO PostPart parseS element = parseChildNodes element >>= return . Strikethrough - -collectBacklinks :: [PostWithBody] -> Backlinks -collectBacklinks xs = foldr insertElement Map.empty xs - where - insertElement :: PostWithBody -> Backlinks -> Backlinks - insertElement (post, body) acc = foldr insertPost acc (quotedPosts body) - where - insertPost postId = Map.insertWith (++) postId [post] - - -quotedPosts :: [ PostPart ] -> [ Integer ] -quotedPosts [] = [] -quotedPosts (Quote (Right (ParsedURL { postId = Just p })) : xs) = [p] ++ quotedPosts xs -quotedPosts ((GreenText xs) : xxs) = quotedPosts xs ++ quotedPosts xxs -quotedPosts ((OrangeText xs) : xxs) = quotedPosts xs ++ quotedPosts xxs -quotedPosts ((RedText xs) : xxs) = quotedPosts xs ++ quotedPosts xxs -quotedPosts ((Spoiler xs) : xxs) = quotedPosts xs ++ quotedPosts xxs -quotedPosts ((Bold xs) : xxs) = quotedPosts xs ++ quotedPosts xxs -quotedPosts ((Underlined xs) : xxs) = quotedPosts xs ++ quotedPosts xxs -quotedPosts ((Italics xs) : xxs) = quotedPosts xs ++ quotedPosts xxs -quotedPosts ((Strikethrough xs) : xxs) = quotedPosts xs ++ quotedPosts xxs -quotedPosts _ = []