A simple groovy console script to find AEM pages with a certain component then display them in a nice table
Copy script to AEM groovy console, change parameters and run!
Copy script to AEM groovy console, change parameters and run!
| /** | |
| * This script finds all pages that contain a certain component | |
| */ | |
| // Change those options to serach other paths | |
| def COMPONENT_PATH = '/path/to/component' // the component to check for (via sling:resourceType) | |
| def START_PATH = '/content/mySite' // the subtree to search in | |
| /** | |
| * get list of pages that contain a certain component (componentPath) | |
| * @param componentPath the component path to find (via sling:resourceType) | |
| * @param startPath the path to start searching from | |
| */ | |
| def getPages(componentPath, startPath){ | |
| paths = []; | |
| getNode(startPath).recurse{ | |
| if(it?.hasProperty('sling:resourceType')){ | |
| def type = it?.getProperty('sling:resourceType')?.getString(); | |
| if(type && type.contains(componentPath)){ | |
| paths.add(pageManager.getContainingPage(it.path)?.path); | |
| } | |
| } | |
| } | |
| return paths; | |
| } | |
| // builds an HTML link <a> from path and title | |
| def link(path, title){ | |
| return "<a target=\"_blank\" href=\"${path}\">${title}</a>"; | |
| //return path; | |
| } | |
| // builds a crx/de link <a> of path | |
| def crxLink(path){ | |
| def newPath = "/crx/de/index.jsp#${path}"; | |
| return link(newPath, 'Open in CRX/DE') | |
| } | |
| // builds a touch ui editor link | |
| def touchLink(path){ | |
| def newPath = "/editor.html${path}" | |
| return link(newPath, 'Open in Touch Editor') | |
| } | |
| def paths = getPages(COMPONENT_PATH, START_PATH); // get pages with template | |
| def tableRows = paths.collect { // transform paths to html <a> elements to be used as rows for table | |
| def cxLink = crxLink(it) | |
| def link = link(it+'.html', it) | |
| def touchLink = touchLink(it) | |
| return [link, cxLink, touchLink] | |
| } | |
| // print table | |
| table { | |
| columns("Page Link",'open in CRX/DE', 'Touch Editor') | |
| rows(tableRows) | |
| } | |
@ncautotest yeah, I found that out after I wrote this script :) thanks for noting it here, though!
@ahmed-musallam: Just in case you didn't know — there is the OOTB Components table which has a live usage list: from the main rail (AEM logo in the top left corner) click Tools > General > Components
Direct link: http://localhost:4502/libs/wcm/core/content/sites/components.html