Skip to content

Commit

Permalink
Merged online changes to changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasNoergaard committed Jan 14, 2021
2 parents 51e0037 + a2cd4e4 commit 8e21335
Show file tree
Hide file tree
Showing 16 changed files with 859 additions and 83 deletions.
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

All notable changes to `flatblog` will be documented in this file
All notable changes to `flatblog-engine` will be documented in this file

## 0.0.1 - 2019.05.23

Expand All @@ -9,7 +9,8 @@ Added .webmanifest file type, to file types that will not be deleted when buildi

## 0.0.2 - 2020.03.27

Implemented new variables for posts
Implemented new variables for posts:

* alt
* feature_post
* seo_title
Expand Down Expand Up @@ -42,4 +43,5 @@ Implemented ability to give an array of related posts in a posts settings file a

## 0.1.0 - 2021.01.14

Added .webp image filetype
Added .webp image filetype

3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"symfony/yaml": "3.2.*",
"erusev/parsedown-extra": "0.7.*",
"duncan3dc/blade": "3.3.*",
"cakephp/chronos": "^1.1"
"cakephp/chronos": "^1.1",
"cocur/slugify": "^4.0"
},
"require-dev": {
"phpunit/phpunit": "5.7.*",
Expand Down
Empty file modified flatblog
100644 → 100755
Empty file.
33 changes: 30 additions & 3 deletions src/Builders/PostsBuilder.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php
namespace WackyStudio\Flatblog\Builders;

use Ausi\SlugGenerator\SlugGenerator;
use Ausi\SlugGenerator\SlugOptions;
use Cocur\Slugify\Slugify;
use Illuminate\Support\Collection;
use WackyStudio\Flatblog\Contracts\BuilderContract;
use WackyStudio\Flatblog\Core\Config;
Expand Down Expand Up @@ -38,13 +41,17 @@ class PostsBuilder implements BuilderContract
*/
private $config;

private $slugify;

public function __construct(array $rawEntities, PostEntityFactory $postEntityFactory, TemplateRenderer $renderer, Config $config)
{
$this->rawrawEntities = $rawEntities;
$this->postEntityFactory = $postEntityFactory;
$this->renderer = $renderer;
$this->templates = $config->get('posts.templates');
$this->config = $config;

$this->slugify = new Slugify(['regexp' => '/([^a-z0-9\/]|-)+/']);
}

/**
Expand All @@ -63,7 +70,27 @@ public function build()

public function buildSinglePosts()
{
return $this->getPosts()->flatMap(function (PostEntity $postEntity) {
$posts = $this->getPosts();

$posts->transform(function (PostEntity $entity) use ($posts) {

$relations = collect($entity->relations)->map(function ($relation) use ($posts) {
$post = $posts->filter(function(PostEntity $postEntity) use($relation){
return $postEntity->slugTitle === $relation;
})->first();


if($post !== null){
return $post;
}
});

$entity->setRelations($relations->toArray());
return $entity;

});

return $posts->flatMap(function (PostEntity $postEntity) {
return [$postEntity->destination() => $this->renderer->render($this->templates['single'], ['post' => $postEntity])];
});
}
Expand Down Expand Up @@ -93,7 +120,7 @@ public function buildSingleCategories()
return $this->renderer->render($this->templates['single-category'], ['category' => $key, 'posts'=>$item, 'categories' => $this->buildCategoryList()]);
})->flatMap(function($posts, $categoryName){
$prefix = $this->getPostPrefix();
return [$prefix.'/'.strtolower($categoryName) => $posts];
return [$prefix.'/'.$this->slugify->slugify($categoryName) => $posts];
});

return $categories;
Expand Down Expand Up @@ -179,7 +206,7 @@ protected function buildCategoryList()
$category->title = $key;
$category->postsCount = $posts->count();

return [strtolower($key) => $category];
return [$this->slugify->slugify($key) => $category];
})->toArray();
return $categories;
}
Expand Down
41 changes: 39 additions & 2 deletions src/Entities/PostEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,39 @@ class PostEntity implements BuildDestinationContract
/**
* @var string
*/
private $destination;
public $destination;
public $alt;
public $seo_title;
public $seo_description;
public $seo_keywords;
public $fb_url;
public $header_image;
public $featured_post;
public $thumbnail;
public $relations;
public $slugTitle;


public function __construct($title, Chronos $date, $category = null, $categoryLink, $summary, $content, $image, $destination)
public function __construct($title, Chronos $date, $category = null, $categoryLink, $summary, $content, $image, $destination, $alt, $featured_post, $seo_title, $seo_description, $seo_keywords, $fb_url, $header_image, $thumbnail, $relations, $slugTitle)
{
$this->title = $title;
$this->date = $date;
$this->content = $content;
$this->image = $image;
$this->thumbnail = $thumbnail;
$this->category = $category;
$this->summary = $summary;
$this->destination = $destination;
$this->categoryLink = $categoryLink;
$this->alt = $alt;
$this->seo_title = $seo_title;
$this->seo_description = $seo_description;
$this->seo_keywords = $seo_keywords;
$this->fb_url = $fb_url;
$this->header_image = $header_image;
$this->featured_post = $featured_post;
$this->relations = $relations;
$this->slugTitle = $slugTitle;
}

/**
Expand All @@ -70,5 +90,22 @@ public function destination()
return $this->destination;
}

/**
* Get Post relations
* @return array
*/
public function getRelations()
{
return $this->relations;
}

/**
* Set Post relations
* @param array $relations
*/
public function setRelations(array $relations){
$this->relations = $relations;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php


namespace WackyStudio\Flatblog\Exceptions;


class InvalidRelationArrayGivenInSettingsFileException extends \RuntimeException
{

}
61 changes: 60 additions & 1 deletion src/Factories/PostEntityFactory.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<?php
namespace WackyStudio\Flatblog\Factories;

use Ausi\SlugGenerator\SlugGenerator;
use Ausi\SlugGenerator\SlugOptions;
use Cake\Chronos\Chronos;
use Cocur\Slugify\Slugify;
use WackyStudio\Flatblog\Core\Config;
use WackyStudio\Flatblog\Entities\PostEntity;
use WackyStudio\Flatblog\Entities\RawEntity;
use WackyStudio\Flatblog\Exceptions\InvalidDateGivenInSettingsFileException;
use WackyStudio\Flatblog\Exceptions\InvalidRelationArrayGivenInSettingsFileException;
use WackyStudio\Flatblog\Exceptions\PostIsMissingContentException;
use WackyStudio\Flatblog\Exceptions\PostIsMissingImageException;
use WackyStudio\Flatblog\Exceptions\PostIsMissingSummaryException;
Expand All @@ -19,14 +23,19 @@ class PostEntityFactory
*/
private $config;

private $slugify;

public function __construct(Config $config)
{
$this->config = $config;

$this->slugify = new Slugify(['regexp' => '/([^a-z0-9\/]|-)+/']);
}

public function make(RawEntity $rawEntity)
{
$settings = $rawEntity->getSettings();

if ( ! isset($settings['title'])) {
throw new PostIsMissingTitleException('Post is missing title');
}
Expand All @@ -36,9 +45,34 @@ public function make(RawEntity $rawEntity)
if ( ! isset($settings['image'])) {
throw new PostIsMissingImageException('Post is missing image');
}
if ( ! isset($settings['thumbnail'])) {
throw new PostIsMissingImageException('Post is missing thumbnail');
}
if ( ! isset($settings['content'])) {
throw new PostIsMissingContentException('Post is missing content');
}
if ( ! isset($settings['alt'])) {
throw new PostIsMissingContentException('Post is missing alt');
}
if ( ! isset($settings['featured_post'])) {
throw new PostIsMissingContentException('Post is missing featured post');
}
if ( ! isset($settings['seo_title'])) {
throw new PostIsMissingContentException('Post is missing seo title');
}
if ( ! isset($settings['seo_description'])) {
throw new PostIsMissingContentException('Post is missing seo description');
}
if ( ! isset($settings['seo_keywords'])) {
throw new PostIsMissingContentException('Post is missing seo keywords');
}
if ( ! isset($settings['fb_url'])) {
throw new PostIsMissingContentException('Post is missing facebook url');
}
if ( ! isset($settings['header_image'])) {
throw new PostIsMissingContentException('Post is missing header image');
}


return new PostEntity(
$settings['title'],
Expand All @@ -48,7 +82,17 @@ public function make(RawEntity $rawEntity)
$settings['summary'],
$settings['content'],
$settings['image'],
$this->handlePostDestination($rawEntity->getPath())
$this->handlePostDestination($this->slugify->slugify($rawEntity->getPath())),
$settings['alt'],
$settings['featured_post'],
$settings['seo_title'],
$settings['seo_description'],
$settings['seo_keywords'],
$settings['fb_url'],
$settings['header_image'],
$settings['thumbnail'],
$this->handlePostRelations($rawEntity, $settings),
array_last($rawEntity->getSubDirectories())
);
}

Expand Down Expand Up @@ -82,4 +126,19 @@ private function handlePostDestination($path){

return $basePath;
}

private function handlePostRelations(RawEntity $rawEntity, array $settings)
{
if ( ! isset($settings['related'])) {
return [];
}else{
if(!is_array($settings['related'])){
throw new InvalidRelationArrayGivenInSettingsFileException("Invalid relations array given in settings file for {$rawEntity->getPath()}");
}

return $settings['related'];
}


}
}
Loading

0 comments on commit 8e21335

Please sign in to comment.