Skip to content

Instantly share code, notes, and snippets.

@dfparker2002
Forked from ahmed-musallam/README.md
Created March 3, 2022 01:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dfparker2002/5ab87fe5162eb9005e8875d9bff506b6 to your computer and use it in GitHub Desktop.
Save dfparker2002/5ab87fe5162eb9005e8875d9bff506b6 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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment