mirror of
https://github.com/typemill/typemill.git
synced 2025-08-01 03:40:27 +02:00
v2.2.2 Create Live Navigation from DraftNavigation to preserve keyPathArray
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# Setup Your Website
|
||||
|
||||
Typemill provides detailed settings, and you have access to nearly all settings in the author panel. Learn the basics in this short video:
|
||||
Typemill provides detailed settings, and you have access to nearly all settings in the author panel. Learn the basics in this short video: mod
|
||||
|
||||
{#7yvlwXJL9dc .youtube}
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
@@ -3,7 +3,7 @@
|
||||
hide: false
|
||||
noindex: false
|
||||
path: /00-welcome
|
||||
keyPath: '0'
|
||||
keyPath: 0
|
||||
/welcome/setup-your-website:
|
||||
navtitle: 'setup your website'
|
||||
hide: false
|
||||
@@ -39,7 +39,7 @@
|
||||
hide: false
|
||||
noindex: false
|
||||
path: /01-cyanine-theme
|
||||
keyPath: '1'
|
||||
keyPath: 1
|
||||
/cyanine-theme/landingpage:
|
||||
navtitle: landingpage
|
||||
hide: false
|
||||
|
@@ -35,38 +35,26 @@ class Folder
|
||||
|
||||
|
||||
/*
|
||||
* scans content of a folder recursively and keeps the index order
|
||||
* scans content of a folder recursively
|
||||
* vars: folder path as string
|
||||
* returns: multi-dimensional array with names of folders and files
|
||||
*/
|
||||
public function scanFolder($folderPath, $draft = false)
|
||||
public function scanFolder($folderPath)
|
||||
{
|
||||
$folderItems = scandir($folderPath);
|
||||
$folderContent = array();
|
||||
|
||||
# if it is the live version and if it is a folder that is not published, then do not show the folder and its content.
|
||||
if(!$draft && !in_array('index.md', $folderItems)){ return false; }
|
||||
|
||||
# Remove '.' and '..' from the array
|
||||
$folderItems = array_diff($folderItems, array('.', '..'));
|
||||
|
||||
# Reindex the array
|
||||
$folderItems = array_values($folderItems);
|
||||
|
||||
foreach ($folderItems as $key => $item)
|
||||
{
|
||||
{
|
||||
if (!in_array($item, array(".","..")) && substr($item, 0, 1) != '.')
|
||||
{
|
||||
if (is_dir($folderPath . DIRECTORY_SEPARATOR . $item))
|
||||
{
|
||||
|
||||
$subFolder = $item;
|
||||
$folderPublished = file_exists($folderPath . DIRECTORY_SEPARATOR . $item . DIRECTORY_SEPARATOR . 'index.md');
|
||||
|
||||
# scan that folder only if it is a draft or if the folder is published (contains index.md)
|
||||
if($draft OR $folderPublished)
|
||||
{
|
||||
# we need s countable index here
|
||||
$folderContent[$key . ':' . $subFolder] = $this->scanFolder($folderPath . DIRECTORY_SEPARATOR . $subFolder, $draft);
|
||||
}
|
||||
$folderContent[$subFolder] = $this->scanFolder($folderPath . DIRECTORY_SEPARATOR . $subFolder);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -79,70 +67,6 @@ class Folder
|
||||
}
|
||||
|
||||
if($fileType == 'txt')
|
||||
{
|
||||
if(isset($last) && ($last == implode($nameParts)) )
|
||||
{
|
||||
array_pop($folderContent);
|
||||
$item = $item . 'md';
|
||||
}
|
||||
$folderContent[] = $item;
|
||||
|
||||
if(!$draft)
|
||||
{
|
||||
$index = count($folderContent)-1;
|
||||
unset($folderContent[$index]);
|
||||
}
|
||||
}
|
||||
|
||||
# store the name of the last file
|
||||
$last = implode($nameParts);
|
||||
|
||||
}
|
||||
}
|
||||
return $folderContent;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* scans content of a folder recursively
|
||||
* vars: folder path as string
|
||||
* returns: multi-dimensional array with names of folders and files
|
||||
*/
|
||||
public function scanFolderOLD($folderPath, $draft = false)
|
||||
{
|
||||
$folderItems = scandir($folderPath);
|
||||
$folderContent = array();
|
||||
|
||||
# if it is the live version and if it is a folder that is not published, then do not show the folder and its content.
|
||||
if(!$draft && !in_array('index.md', $folderItems)){ return false; }
|
||||
|
||||
foreach ($folderItems as $key => $item)
|
||||
{
|
||||
if (!in_array($item, array(".","..")) && substr($item, 0, 1) != '.')
|
||||
{
|
||||
if (is_dir($folderPath . DIRECTORY_SEPARATOR . $item))
|
||||
{
|
||||
|
||||
$subFolder = $item;
|
||||
$folderPublished = file_exists($folderPath . DIRECTORY_SEPARATOR . $item . DIRECTORY_SEPARATOR . 'index.md');
|
||||
|
||||
# scan that folder only if it is a draft or if the folder is published (contains index.md)
|
||||
if($draft OR $folderPublished)
|
||||
{
|
||||
$folderContent[$subFolder] = $this->scanFolder($folderPath . DIRECTORY_SEPARATOR . $subFolder, $draft);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$nameParts = $this->getStringParts($item);
|
||||
$fileType = array_pop($nameParts);
|
||||
|
||||
if($fileType == 'md')
|
||||
{
|
||||
$folderContent[] = $item;
|
||||
}
|
||||
|
||||
if($draft === true && $fileType == 'txt')
|
||||
{
|
||||
if(isset($last) && ($last == implode($nameParts)) )
|
||||
{
|
||||
@@ -160,7 +84,6 @@ class Folder
|
||||
return $folderContent;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Transforms array of folder item into an array of item-objects with additional information for each item
|
||||
* vars: multidimensional array with folder- and file-names
|
||||
@@ -173,133 +96,6 @@ class Folder
|
||||
$iteration = 0;
|
||||
$chapternr = 1;
|
||||
|
||||
foreach($folderContent as $key => $name)
|
||||
{
|
||||
$item = new \stdClass();
|
||||
|
||||
if(is_array($name))
|
||||
{
|
||||
# get the index of the folder. Limit to 2 parts to ensure only the first ":" is used
|
||||
$findIndex = explode(':', $key, 2);
|
||||
$key = $findIndex[0];
|
||||
$folderName = $findIndex[1];
|
||||
|
||||
$nameParts = $this->getStringParts($folderName);
|
||||
|
||||
$fileType = '';
|
||||
if(in_array('index.md', $name))
|
||||
{
|
||||
$fileType = 'md';
|
||||
$status = 'published';
|
||||
}
|
||||
if(in_array('index.txt', $name))
|
||||
{
|
||||
$fileType = 'txt';
|
||||
$status = 'unpublished';
|
||||
}
|
||||
if(in_array('index.txtmd', $name))
|
||||
{
|
||||
$fileType = 'txt';
|
||||
$status = 'modified';
|
||||
}
|
||||
|
||||
$item->originalName = $folderName;
|
||||
$item->elementType = 'folder';
|
||||
$item->contains = $this->getFolderContentType($name, $fullPath . DIRECTORY_SEPARATOR . $key . DIRECTORY_SEPARATOR . 'index.yaml');
|
||||
$item->status = $status;
|
||||
$item->fileType = $fileType;
|
||||
$item->order = count($nameParts) > 1 ? array_shift($nameParts) : NULL;
|
||||
$item->name = implode(" ",$nameParts);
|
||||
$item->name = iconv(mb_detect_encoding($item->name, mb_detect_order(), true), "UTF-8", $item->name);
|
||||
$item->slug = implode("-",$nameParts);
|
||||
$item->slug = $this->createSlug($item->slug, $language);
|
||||
$item->path = $fullPath . DIRECTORY_SEPARATOR . $folderName;
|
||||
$item->pathWithoutType = $fullPath . DIRECTORY_SEPARATOR . $folderName . DIRECTORY_SEPARATOR . 'index';
|
||||
$item->urlRelWoF = $fullSlugWithoutFolder . '/' . $item->slug;
|
||||
$item->urlRel = $fullSlugWithFolder . '/' . $item->slug;
|
||||
$item->urlAbs = $baseUrl . $fullSlugWithoutFolder . '/' . $item->slug;
|
||||
$item->key = $key;
|
||||
$item->keyPath = isset($keyPath) ? $keyPath . '.' . $key : $key;
|
||||
$item->keyPathArray = explode('.', $item->keyPath);
|
||||
$item->chapter = $chapter ? $chapter . '.' . $chapternr : $chapternr;
|
||||
$item->active = false;
|
||||
$item->activeParent = false;
|
||||
$item->hide = false;
|
||||
|
||||
# sort posts in descending order
|
||||
if($item->contains == "posts")
|
||||
{
|
||||
rsort($name);
|
||||
}
|
||||
|
||||
$item->folderContent = $this->getFolderContentDetails($name, $language, $baseUrl, $item->urlRel, $item->urlRelWoF, $item->path, $item->keyPath, $item->chapter);
|
||||
}
|
||||
elseif($name)
|
||||
{
|
||||
# do not use index files
|
||||
if($name == 'index.md' || $name == 'index.txt' || $name == 'index.txtmd' ) continue;
|
||||
|
||||
$nameParts = $this->getStringParts($name);
|
||||
$fileType = array_pop($nameParts);
|
||||
$nameWithoutType = $this->getNameWithoutType($name);
|
||||
|
||||
if($fileType == 'md')
|
||||
{
|
||||
$status = 'published';
|
||||
}
|
||||
elseif($fileType == 'txt')
|
||||
{
|
||||
$status = 'unpublished';
|
||||
}
|
||||
else
|
||||
{
|
||||
$fileType = 'txt';
|
||||
$status = 'modified';
|
||||
}
|
||||
|
||||
$item->originalName = $name;
|
||||
$item->elementType = 'file';
|
||||
$item->status = $status;
|
||||
$item->fileType = $fileType;
|
||||
$item->order = count($nameParts) > 1 ? array_shift($nameParts) : NULL;
|
||||
$item->name = implode(" ",$nameParts);
|
||||
$item->name = iconv(mb_detect_encoding($item->name, mb_detect_order(), true), "UTF-8", $item->name);
|
||||
$item->slug = implode("-",$nameParts);
|
||||
$item->slug = $this->createSlug($item->slug, $language);
|
||||
$item->path = $fullPath . DIRECTORY_SEPARATOR . $name;
|
||||
$item->pathWithoutType = $fullPath . DIRECTORY_SEPARATOR . $nameWithoutType;
|
||||
$item->key = $key;
|
||||
$item->keyPath = isset($keyPath) ? $keyPath . '.' . $key : $key;
|
||||
$item->keyPathArray = explode('.',$item->keyPath);
|
||||
$item->chapter = $chapter . '.' . $chapternr;
|
||||
$item->urlRelWoF = $fullSlugWithoutFolder . '/' . $item->slug;
|
||||
$item->urlRel = $fullSlugWithFolder . '/' . $item->slug;
|
||||
$item->urlAbs = $baseUrl . $fullSlugWithoutFolder . '/' . $item->slug;
|
||||
$item->active = false;
|
||||
$item->activeParent = false;
|
||||
$item->hide = false;
|
||||
}
|
||||
|
||||
$iteration++;
|
||||
$chapternr++;
|
||||
$contentDetails[$key] = $item;
|
||||
}
|
||||
return $contentDetails;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Transforms array of folder item into an array of item-objects with additional information for each item
|
||||
* vars: multidimensional array with folder- and file-names
|
||||
* returns: array of objects. Each object contains information about an item (file or folder).
|
||||
*/
|
||||
|
||||
public function getFolderContentDetailsOLD(array $folderContent, $language, $baseUrl, $fullSlugWithFolder = NULL, $fullSlugWithoutFolder = NULL, $fullPath = NULL, $keyPath = NULL, $chapter = NULL)
|
||||
{
|
||||
$contentDetails = [];
|
||||
$iteration = 0;
|
||||
$chapternr = 1;
|
||||
|
||||
foreach($folderContent as $key => $name)
|
||||
{
|
||||
$item = new \stdClass();
|
||||
|
@@ -206,8 +206,6 @@ class Navigation extends Folder
|
||||
{
|
||||
# todo: filter for userrole or username
|
||||
|
||||
$basicLiveNavigation = $this->getBasicLiveNavigation($urlinfo, $language);
|
||||
|
||||
$this->liveNavigation = $this->storage->getFile('dataFolder', $this->naviFolder, $this->liveNaviName, 'unserialize');
|
||||
|
||||
if($this->liveNavigation)
|
||||
@@ -215,8 +213,9 @@ class Navigation extends Folder
|
||||
return $this->liveNavigation;
|
||||
}
|
||||
|
||||
# if there is no cached navi, create a basic new draft navi
|
||||
$basicLiveNavigation = $this->getBasicLiveNavigation($urlinfo, $language);
|
||||
$draftNavigation = $this->getDraftNavigation($urlinfo, $language);
|
||||
|
||||
$basicLiveNavigation = $this->generateLiveNavigationFromDraft($draftNavigation);
|
||||
|
||||
# get the extended navigation with additional infos from the meta-files like title or hidden pages
|
||||
$extendedNavigation = $this->getExtendedNavigation($urlinfo, $language);
|
||||
@@ -230,6 +229,33 @@ class Navigation extends Folder
|
||||
return $liveNavigation;
|
||||
}
|
||||
|
||||
public function generateLiveNavigationFromDraft($draftNavigation)
|
||||
{
|
||||
foreach($draftNavigation as $key => $item)
|
||||
{
|
||||
if($item->status == 'unpublished')
|
||||
{
|
||||
unset($draftNavigation[$key]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if($item->status == 'modified')
|
||||
{
|
||||
$draftNavigation[$key]->fileType = 'md';
|
||||
$draftNavigation[$key]->path = $draftNavigation[$key]->pathWithoutType . '.md';
|
||||
}
|
||||
|
||||
if(isset($item->folderContent) && $item->folderContent)
|
||||
{
|
||||
$item->folderContent = $this->generateLiveNavigationFromDraft($item->folderContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $draftNavigation;
|
||||
}
|
||||
|
||||
/*
|
||||
public function getBasicLiveNavigation($urlinfo, $language)
|
||||
{
|
||||
if(!$this->basicLiveNavigation)
|
||||
@@ -254,7 +280,8 @@ class Navigation extends Folder
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
# get the extended navigation with additional infos from the meta-files like title or hidden pages
|
||||
public function getExtendedNavigation($urlinfo, $language)
|
||||
{
|
||||
|
Reference in New Issue
Block a user