Improve the way the pagelist is generated

Now it automatically strips off the .md extension since it's unneeded, and it sorts it so that the 'index' of the site is always the first item in the array, since that dictates the order they appear in the browser
This commit is contained in:
Belle Aerni 2023-01-17 19:45:59 -08:00
parent f388c99647
commit 02e4492ecd

View file

@ -21,14 +21,26 @@ class AntPages
$page = AntTools::repairFilePath($page); $page = AntTools::repairFilePath($page);
$pageContent = file_get_contents($page); $pageContent = file_get_contents($page);
$pageHeader = AntCMS::getPageHeaders($pageContent); $pageHeader = AntCMS::getPageHeaders($pageContent);
$pageFunctionalPath = str_replace(antContentPath, "", $page);
// Because we are only getting a list of files with the 'md' extension, we can blindly strip off the extension from each path.
// Doing this creates more profesional URLs as AntCMS will automatically add the 'md' extenstion during the page rendering process.
$pageFunctionalPath = substr(str_replace(antContentPath, "", $page), 0, -3);
if ($pageFunctionalPath == '/index') {
$pageFunctionalPath = '/';
}
$currentPage = array( $currentPage = array(
'pageTitle' => $pageHeader['title'], 'pageTitle' => $pageHeader['title'],
'fullPagePath' => $page, 'fullPagePath' => $page,
'functionalPagePath' => $pageFunctionalPath, 'functionalPagePath' => $pageFunctionalPath,
'showInNav' => true, 'showInNav' => true,
); );
$pageList[] = $currentPage; if ($pageFunctionalPath === '/') {
array_unshift($pageList, $currentPage);
} else {
$pageList[] = $currentPage;
}
} }
AntYaml::saveFile(antPagesList, $pageList); AntYaml::saveFile(antPagesList, $pageList);