code: private Page findIndexPage(final SecurityContext securityContext, List<Page> pages, final EditMode edit) throws FrameworkException {
  
  		final PropertyKey<Integer> positionKey = StructrApp.key(Page.class, "position");
  
  		if (pages == null) {
  
  			pages = StructrApp.getInstance(securityContext).nodeQuery(Page.class).getAsList();
  			Collections.sort(pages, new GraphObjectComparator(positionKey, GraphObjectComparator.ASCENDING));
  		}
  
  		for (Page page : pages) {
  
  			if (securityContext.isVisible(page) && page.getProperty(positionKey) != null && ((EditMode.CONTENT.equals(edit) || isVisibleForSite(securityContext.getRequest(), page)) || (page.getEnableBasicAuth() && page.isVisibleToAuthenticatedUsers()))) {
  
  				return page;
  			}
  		}
  
  		return null;
  	}
docs: Find the page with the lowest non-empty position value which is visible in the
  current security context and for the given site.
  
  @param securityContext
  @param pages
  @param edit
  @return page
  @throws FrameworkException