google-apps-scriptgoogle-sites

Deleting Classic Google Sites pages via Apps Script


Is there a way to delete large sections of a classic Site via Apps Script?


Solution

  • /* CHANGE THE URL BELOW TO THE PAGE THAT YOU WANT TO DELETE. THEN SELECT "Run" > "deletePage" ABOVE. */
    
    const URL = 'https://sites.google.com/site/demositeappsscript/mylistpage';
    
    
    
    /* DON'T MODIFY ANYTHING BELOW HERE. */
    
    function deletePage() {
      const pageToDelete = SitesApp.getPageByUrl(URL);
      deletePageHelper_(pageToDelete);
    }
    
    function deletePageHelper_(page) {
      page.getChildren().forEach(childPage => deletePageHelper_(childPage));
      Logger.log(`DELETING PAGE: "${page.getName()}".`);
      page.deletePage();
    }