Skip to content

Instantly share code, notes, and snippets.

@ahmed-musallam
Last active March 3, 2022 01:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ahmed-musallam/780d92ee1ea30c7101054506364d6a25 to your computer and use it in GitHub Desktop.
Save ahmed-musallam/780d92ee1ea30c7101054506364d6a25 to your computer and use it in GitHub Desktop.
A simple groovy console script to find AEM pages with a certain component then display them in a nice table

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!

/**
* 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
Copy link

@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

@ahmed-musallam
Copy link
Author

@ncautotest yeah, I found that out after I wrote this script :) thanks for noting it here, though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment