Created
October 4, 2014 07:27
-
-
Save trekawek/72b3515a6641ca5f4b29 to your computer and use it in GitHub Desktop.
Following groovy script finds broken internal links under the given site
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.jcr.* | |
import org.apache.sling.api.resource.* | |
def ROOT_PATH = '/content/geometrixx' | |
def extractPaths(p) { | |
if (p instanceof Property && p.multiple) { | |
p.values.collect { extractPaths(it) }.flatten() | |
} else { | |
p.string.findAll(/\/content\/[^"]+/) | |
} | |
} | |
getNode(ROOT_PATH).recurse { node -> | |
node.properties.findAll {it.type == PropertyType.STRING}.each { | |
paths = extractPaths(it).findAll { resourceResolver.resolve(it) instanceof NonExistingResource } | |
if (!paths.empty) { | |
println "Path: ${node.path}" | |
println "Broken: ${paths}\n" | |
} | |
} | |
} | |
true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, i need to check broken links for a site. How can i put the URL in this code?