Skip to content

Instantly share code, notes, and snippets.

@TitusRobyK
Created April 29, 2025 20:36
Show Gist options
  • Select an option

  • Save TitusRobyK/fae31ef1939efccee9d81b1c1baecb86 to your computer and use it in GitHub Desktop.

Select an option

Save TitusRobyK/fae31ef1939efccee9d81b1c1baecb86 to your computer and use it in GitHub Desktop.

Revisions

  1. TitusRobyK created this gist Apr 29, 2025.
    44 changes: 44 additions & 0 deletions SearchAndGetAllImagePath.groovy
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    import org.apache.sling.api.resource.Resource
    import org.apache.sling.api.resource.ResourceResolver
    import org.apache.sling.api.resource.ValueMap


    def rootPath = "/content/wknd/us/en"

    Resource root = resourceResolver.getResource(rootPath)
    if (root == null) {
    println "ERROR: Path not found: ${rootPath}"
    return
    }


    def images = [] as Set<String>


    def traverse
    traverse = { Resource res ->

    ValueMap props = res.adaptTo(ValueMap)
    if (props) {
    def fileRef = props.get("fileReference", String)
    if (fileRef) {
    images << fileRef
    }

    def src = props.get("src", String)
    if (src) {
    images << src
    }

    ["imagePath","poster","thumbnail"].each { key ->
    def v = props.get(key, String)
    if (v) { images << v }
    }
    }
    res.listChildren().each { traverse(it) }
    }


    traverse(root)
    println "\nFound ${images.size()} unique image references under ${rootPath}:\n"
    images.sort().each { println it }