@@ -8,6 +8,7 @@ module Hakyll.Core.DirectedGraph
8 , neighbours
8 , neighbours
10 , reachableNodes
10 , reachableNodes
13import Prelude hiding (reverse)
14import Prelude hiding (reverse)
@@ -59,9 +60,17 @@ reachableNodes set graph = reachable (setNeighbours set) set
60 reachable next visited
61 reachable next visited
61 | S.null next = visited
62 | S.null next = visited
62− | otherwise = reachable (sanitize neighbours') (next `S.union` visited)
63+ | otherwise = reachable (sanitize' neighbours') (next `S.union` visited)
64− sanitize = S.filter (`S.notMember` visited)
65+ sanitize' = S.filter (`S.notMember` visited)
65− neighbours' = setNeighbours (sanitize next)
66+ neighbours' = setNeighbours (sanitize' next)
67 setNeighbours = S.unions . map (flip neighbours graph) . S.toList
68 setNeighbours = S.unions . map (flip neighbours graph) . S.toList
70+-- | Remove all dangling pointers, i.e. references to notes that do
71+-- not actually exist in the graph.
73+sanitize :: Ord a => DirectedGraph a -> DirectedGraph a
74+sanitize (DirectedGraph graph) = DirectedGraph $ M.map sanitize' $ graph
76+ sanitize' (Node t n) = Node t $ S.filter (`M.member` graph) n