code: public static void deletePageOrResource(Resource resource) {
      Page configPage = resource.adaptTo(Page.class);
      if (configPage != null) {
        try {
          log.trace("! Delete page {}", configPage.getPath());
          PageManager pageManager = configPage.getPageManager();
          pageManager.delete(configPage, false);
        }
        catch (WCMException ex) {
          throw convertWCMException("Unable to delete configuration page at " + resource.getPath(), ex);
        }
      }
      else {
        try {
          log.trace("! Delete resource {}", resource.getPath());
          resource.getResourceResolver().delete(resource);
        }
        catch (PersistenceException ex) {
          throw convertPersistenceException("Unable to delete configuration resource at " + resource.getPath(), ex);
        }
      }
    }
docs: If the given resource points to an AEM page, delete the page using PageManager.
  Otherwise delete the resource using ResourceResolver.
  @param resource Resource to delete