Skip to content

Instantly share code, notes, and snippets.

@ahmed-musallam
Last active January 29, 2020 16:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmed-musallam/fb8f0eb0f5c577e6c5086090ba22a2a1 to your computer and use it in GitHub Desktop.
Save ahmed-musallam/fb8f0eb0f5c577e6c5086090ba22a2a1 to your computer and use it in GitHub Desktop.
A simple groovy console script to find AEM pages with a certain template then display them in a nice table

A simple groovy console script to find AEM pages with a certain template then display them in a nice table

copy script to AEM groovy console, change parameters and run!

/**
* An AEM groovy console script: https://github.com/OlsonDigital/aem-groovy-console
* This script finds all pages that were created using a certain template
*/
// Change those options to serach other paths
def TEMPLATE = 'apps/myproject/templates/mytemplate' // the template to check for
def START_PATH = '/content' // the subtree to search in
// builds an HTML link <a> from path and title
def buildLink(path, title){
return '<a target=\"_blank\" href=\"'+path+'\">'+ title + '</a>';
//return path;
}
// builds a crx/de link <a> of path
def buildCrxLink(path){
def newPath = "/crx/de/index.jsp#" + path;
return buildLink(newPath, 'Open in CRX/DE')
}
/**
* get list of pages that were created using templatePath
* @param templatePath the template path to find pages with
* @param startPath the path to start searching from
*/
def getPages(templatePath, startPath){
paths = [];
getNode(startPath).recurse{
def page = getPage(it.path);
if(page?.template?.path?.contains(templatePath)){
paths.add(page.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(TEMPLATE, 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