mirror of
https://github.com/typemill/typemill.git
synced 2025-01-16 21:08:20 +01:00
Fix error with folders transform posts and page
This commit is contained in:
parent
f2a474a3cc
commit
dfb356d902
4
content/02-de/00-berlin/00-wedding.md
Normal file
4
content/02-de/00-berlin/00-wedding.md
Normal file
@ -0,0 +1,4 @@
|
||||
# Wedding
|
||||
|
||||
Content
|
||||
|
9
content/02-de/00-berlin/00-wedding.yaml
Normal file
9
content/02-de/00-berlin/00-wedding.yaml
Normal file
@ -0,0 +1,9 @@
|
||||
meta:
|
||||
title: Wedding
|
||||
description: Content
|
||||
owner: trendschau
|
||||
author: 'Sebastian Schürmanns'
|
||||
created: '2022-04-08'
|
||||
time: 13-41-43
|
||||
navtitle: Wedding
|
||||
modified: '2022-04-08'
|
4
content/02-de/00-berlin/01-neukoelln.md
Normal file
4
content/02-de/00-berlin/01-neukoelln.md
Normal file
@ -0,0 +1,4 @@
|
||||
# Neukölln
|
||||
|
||||
Content
|
||||
|
9
content/02-de/00-berlin/01-neukoelln.yaml
Normal file
9
content/02-de/00-berlin/01-neukoelln.yaml
Normal file
@ -0,0 +1,9 @@
|
||||
meta:
|
||||
title: Neukölln
|
||||
description: Content
|
||||
owner: trendschau
|
||||
author: 'Sebastian Schürmanns'
|
||||
created: '2022-04-08'
|
||||
time: 13-41-39
|
||||
navtitle: Neukölln
|
||||
modified: '2022-04-08'
|
4
content/02-de/00-berlin/index.md
Normal file
4
content/02-de/00-berlin/index.md
Normal file
@ -0,0 +1,4 @@
|
||||
# Berlin
|
||||
|
||||
Content
|
||||
|
17
content/02-de/00-berlin/index.yaml
Normal file
17
content/02-de/00-berlin/index.yaml
Normal file
@ -0,0 +1,17 @@
|
||||
meta:
|
||||
navtitle: Berlina
|
||||
title: Berlin
|
||||
description: Content
|
||||
heroimage: null
|
||||
heroimagealt: null
|
||||
hide: false
|
||||
noindex: false
|
||||
owner: trendschau
|
||||
author: 'Sebastian Schürmanns'
|
||||
allowedrole: null
|
||||
alloweduser: null
|
||||
manualdate: null
|
||||
modified: '2022-04-08'
|
||||
created: '2022-04-08'
|
||||
time: 13-41-04
|
||||
contains: pages
|
4
content/02-de/index.md
Normal file
4
content/02-de/index.md
Normal file
@ -0,0 +1,4 @@
|
||||
# de
|
||||
|
||||
Content
|
||||
|
11
content/02-de/index.yaml
Normal file
11
content/02-de/index.yaml
Normal file
@ -0,0 +1,11 @@
|
||||
meta:
|
||||
title: de
|
||||
description: Content
|
||||
owner: trendschau
|
||||
author: 'Sebastian Schürmanns'
|
||||
created: '2022-04-08'
|
||||
time: 13-40-55
|
||||
navtitle: Deutschland
|
||||
modified: '2022-04-08'
|
||||
hide: false
|
||||
noindex: false
|
4
content/03-uk/00-berlin/202204081422-wedding.md
Normal file
4
content/03-uk/00-berlin/202204081422-wedding.md
Normal file
@ -0,0 +1,4 @@
|
||||
# Wedding
|
||||
|
||||
Content
|
||||
|
9
content/03-uk/00-berlin/202204081422-wedding.yaml
Normal file
9
content/03-uk/00-berlin/202204081422-wedding.yaml
Normal file
@ -0,0 +1,9 @@
|
||||
meta:
|
||||
title: Wedding
|
||||
description: Content
|
||||
owner: trendschau
|
||||
author: 'Sebastian Schürmanns'
|
||||
created: '2022-04-08'
|
||||
time: 14-22-35
|
||||
navtitle: Wedding
|
||||
modified: '2022-04-08'
|
4
content/03-uk/00-berlin/index.md
Normal file
4
content/03-uk/00-berlin/index.md
Normal file
@ -0,0 +1,4 @@
|
||||
# Berlin
|
||||
|
||||
Content
|
||||
|
17
content/03-uk/00-berlin/index.yaml
Normal file
17
content/03-uk/00-berlin/index.yaml
Normal file
@ -0,0 +1,17 @@
|
||||
meta:
|
||||
navtitle: Berlin
|
||||
title: Berlin
|
||||
description: Content
|
||||
heroimage: null
|
||||
heroimagealt: null
|
||||
hide: false
|
||||
noindex: false
|
||||
owner: trendschau
|
||||
author: 'Sebastian Schürmanns'
|
||||
allowedrole: null
|
||||
alloweduser: null
|
||||
manualdate: null
|
||||
modified: '2022-04-08'
|
||||
created: '2022-04-08'
|
||||
time: 14-22-11
|
||||
contains: posts
|
4
content/03-uk/index.md
Normal file
4
content/03-uk/index.md
Normal file
@ -0,0 +1,4 @@
|
||||
# uk
|
||||
|
||||
Content
|
||||
|
17
content/03-uk/index.yaml
Normal file
17
content/03-uk/index.yaml
Normal file
@ -0,0 +1,17 @@
|
||||
meta:
|
||||
navtitle: change
|
||||
title: uk
|
||||
description: Content
|
||||
heroimage: null
|
||||
heroimagealt: null
|
||||
hide: false
|
||||
noindex: false
|
||||
owner: trendschau
|
||||
author: 'Sebastian Schürmanns'
|
||||
allowedrole: null
|
||||
alloweduser: null
|
||||
manualdate: null
|
||||
modified: '2022-04-08'
|
||||
created: '2022-04-08'
|
||||
time: 14-03-22
|
||||
contains: pages
|
@ -296,17 +296,28 @@ class ControllerAuthorMetaApi extends ControllerAuthor
|
||||
}
|
||||
|
||||
# if folder has changed and contains pages instead of posts or posts instead of pages
|
||||
if($this->item->elementType == "folder" && isset($metaInput['contains']) && $this->hasChanged($metaInput, $metaPage['meta'], 'contains'))
|
||||
if($this->item->elementType == "folder" && isset($metaInput['contains']) && isset($metaPage['meta']['contains']) && $this->hasChanged($metaInput, $metaPage['meta'], 'contains'))
|
||||
{
|
||||
$structure = true;
|
||||
|
||||
if($writeMeta->folderContainsFolders($this->item))
|
||||
{
|
||||
return $response->withJson(array('errors' => ['message' => 'The folder contains another folder so we cannot transform it. Please make sure there are only files in this folder.']),422);
|
||||
}
|
||||
|
||||
if($metaInput['contains'] == "posts")
|
||||
{
|
||||
$writeMeta->transformPagesToPosts($this->item);
|
||||
if(!$writeMeta->transformPagesToPosts($this->item))
|
||||
{
|
||||
return $response->withJson(array('errors' => ['message' => 'One or more files could not be transformed.']),422);
|
||||
}
|
||||
}
|
||||
if($metaInput['contains'] == "pages")
|
||||
{
|
||||
$writeMeta->transformPostsToPages($this->item);
|
||||
if(!$writeMeta->transformPostsToPages($this->item))
|
||||
{
|
||||
return $response->withJson(array('errors' => ['message' => 'One or more files could not be transformed.']),422);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -258,9 +258,10 @@ class WriteMeta extends WriteYaml
|
||||
return $description;
|
||||
}
|
||||
|
||||
public function transformPagesToPosts($folder){
|
||||
|
||||
public function transformPagesToPosts($folder)
|
||||
{
|
||||
$filetypes = array('md', 'txt', 'yaml');
|
||||
$result = true;
|
||||
|
||||
foreach($folder->folderContent as $page)
|
||||
{
|
||||
@ -294,13 +295,11 @@ class WriteMeta extends WriteYaml
|
||||
# create new file-name without filetype
|
||||
$newFile = $this->basePath . 'content' . $folder->path . DIRECTORY_SEPARATOR . $datetime . '-' . $page->slug;
|
||||
|
||||
$result = true;
|
||||
|
||||
foreach($filetypes as $filetype)
|
||||
{
|
||||
$oldFilePath = $oldFile . '.' . $filetype;
|
||||
$newFilePath = $newFile . '.' . $filetype;
|
||||
|
||||
|
||||
#check if file with filetype exists and rename
|
||||
if($oldFilePath != $newFilePath && file_exists($oldFilePath))
|
||||
{
|
||||
@ -315,12 +314,15 @@ class WriteMeta extends WriteYaml
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function transformPostsToPages($folder){
|
||||
|
||||
public function transformPostsToPages($folder)
|
||||
{
|
||||
$filetypes = array('md', 'txt', 'yaml');
|
||||
$index = 0;
|
||||
$result = true;
|
||||
|
||||
foreach($folder->folderContent as $page)
|
||||
{
|
||||
@ -337,8 +339,6 @@ class WriteMeta extends WriteYaml
|
||||
# create new file-name without filetype
|
||||
$newFile = $this->basePath . 'content' . $folder->path . DIRECTORY_SEPARATOR . $order . '-' . $page->slug;
|
||||
|
||||
$result = true;
|
||||
|
||||
foreach($filetypes as $filetype)
|
||||
{
|
||||
$oldFilePath = $oldFile . '.' . $filetype;
|
||||
@ -360,5 +360,20 @@ class WriteMeta extends WriteYaml
|
||||
|
||||
$index++;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function folderContainsFolders($folder)
|
||||
{
|
||||
foreach($folder->folderContent as $page)
|
||||
{
|
||||
if($page->elementType == 'folder')
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user