summaryrefslogtreecommitdiff
path: root/src/Hakyll
diff options
context:
space:
mode:
Diffstat (limited to 'src/Hakyll')
-rw-r--r--src/Hakyll/Core/DirectedGraph.hs15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/Hakyll/Core/DirectedGraph.hs b/src/Hakyll/Core/DirectedGraph.hs
index bf52277..66905f7 100644
--- a/src/Hakyll/Core/DirectedGraph.hs
+++ b/src/Hakyll/Core/DirectedGraph.hs
@@ -8,6 +8,7 @@ module Hakyll.Core.DirectedGraph
, neighbours
, reverse
, reachableNodes
+ , sanitize
) where
import Prelude hiding (reverse)
@@ -59,9 +60,17 @@ reachableNodes set graph = reachable (setNeighbours set) set
where
reachable next visited
| S.null next = visited
- | otherwise = reachable (sanitize neighbours') (next `S.union` visited)
+ | otherwise = reachable (sanitize' neighbours') (next `S.union` visited)
where
- sanitize = S.filter (`S.notMember` visited)
- neighbours' = setNeighbours (sanitize next)
+ sanitize' = S.filter (`S.notMember` visited)
+ neighbours' = setNeighbours (sanitize' next)
setNeighbours = S.unions . map (flip neighbours graph) . S.toList
+
+-- | Remove all dangling pointers, i.e. references to notes that do
+-- not actually exist in the graph.
+--
+sanitize :: Ord a => DirectedGraph a -> DirectedGraph a
+sanitize (DirectedGraph graph) = DirectedGraph $ M.map sanitize' $ graph
+ where
+ sanitize' (Node t n) = Node t $ S.filter (`M.member` graph) n