Skip to content

Commit

Permalink
🔀 Pull Master into lost 1.0.9 commits (#227)
Browse files Browse the repository at this point in the history
* 🔖 1.0.8 Release

* 🎨 spelling

* 🔧 amended composer build scripts

* 📝 added some campaign details to links

* 🔖 1.9.0 release (#225)

* 🔖 1.9.0 release (#224)

* 🔧 setting version to 1.0.9-dev

* 🐛 Fix for issue #209 (#210)

* ✅ (TDD) amending test case for #209

* 🐛 fixed uri parsing

* Apply fixes from StyleCI

* 🐛 #! uri now supported

* 📝 adding changelog for #209

* Apply fixes from StyleCI

* ✨ double dot extension support added (#214)

* ✅ TDD for #208

* ✨ Files with multiple ext no longer have their dots converted to dashes

* 📝 adding changelog for #208

* 🚨 Apply fixes from StyleCI (#215)

* ✨ implement --auto-publish flag (#216)

* ✨ added --auto-publish flag

* ✨ finished --auto-publish functionality

* 📝 added changelog for #146

* 🚨 Apply fixes from StyleCI (#217)

* 🔀 Solves issue #209 with bugfix (#220)

* 📝 added changelog for #219

* 🐛 bugfix solves issue #129

* 🚨 Apply fixes from StyleCI (#221)

* 🔀 Add permalink duplication warning for #156 (#222)

* 📝 adding changelog for issue #156

* ✅ TDD for issue #156

* 🚚 unfinished adding of functionality

* ✨ functionality for #156 complete

* 🚨 Apply fixes from StyleCI (#223)

* 🔧 updating version for 1.0.9

* 🎨 Tidy up of todo's for #61 (#226)

* 🔧 setting version to 1.0.9-dev

* 🎨 tidy up old todo items for #61
  • Loading branch information
carbontwelve authored Jul 7, 2017
1 parent c3fe0b7 commit 343be8e
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 20 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
## Bugfixes
- #209 Fix Url helper parsing of Uri with parameters
- #208 File with multiple ext e.g. main.min.css are now compiled as expected rather than hyphenated e.g. main-min.css
- #219 Fixed permalinks not being valid urls when using the file path on Windows

## Enhancements
- #146 Added --auto-publish flag to build command, [click here](https://www.tapestry.cloud/documentation/commands/#build-command) for more information
- #156 Added permalink registry for the purpose of identifying when two files have the same permalink and warning the user or resolving the conflict

# 1.0.8
## Bugfixes
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ Tapestry is a static site generator that uses the [plates](http://platesphp.com/
* Built to be extendable with [plugins](https://www.tapestry.cloud/documentation/working-examples/#plugins)

## Learning Tapestry
The [Tapestry documentation](https://www.tapestry.cloud/documentation/) provides a thorough insight into the inner workings of Tapestry. Making it as easy as possible to get started generating your sites.
The [Tapestry documentation](https://www.tapestry.cloud/documentation/?utm_source=github&utm_medium=referral&utm_campaign=README) provides a thorough insight into the inner workings of Tapestry. Making it as easy as possible to get started generating your sites.

## Installing Tapestry
The recomended method for installing Tapestry is to grab the latest [zipped release here](https://github.com/carbontwelve/tapestry/releases) and unzip the contents into your `$PATH` to make it globally available from your command line.
The recommended method for installing Tapestry is to grab the latest [zipped release here](https://github.com/carbontwelve/tapestry/releases) and unzip the contents into your `$PATH` to make it globally available from your command line.

For Windows environments a `.bat` file is included so that you do not have to type `php tapestry.phar` to run Tapestry; for it to work ensure it is kept in the same folder as the `.phar`.

For alternative methods of installing Tapestry see the [install documentation here](https://www.tapestry.cloud/documentation/installation).
For alternative methods of installing Tapestry see the [install documentation here](https://www.tapestry.cloud/documentation/installation/?utm_source=github&utm_medium=referral&utm_campaign=README).

## License
Tapestry is open sourced software licensed under the [MIT License](LICENSE).
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
"scripts": {
"box": [
"composer install --no-dev --prefer-dist",
"curl -LSs https://box-project.github.io/box2/installer.php | php",
"php build/BuildVersion.php",
"php box.phar build -v"
"@php -r \"file_exists('box.phar') || exec('curl -LSs https://box-project.github.io/box2/installer.php | php');\"",
"@php build/BuildVersion.php",
"@php box.phar build -v"
]
}
}
1 change: 0 additions & 1 deletion src/ArrayContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,6 @@ public function sort(Closure $callback)
* A 2D array sort, useful for when you need to sort a two dimensional array.
*
* @param Closure $callback
* @todo is there a way of merging this in with the sort method?
* @return $this
*/
public function sortMultiDimension(Closure $callback)
Expand Down
14 changes: 13 additions & 1 deletion src/Entities/Permalink.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,16 @@ public function getCompiled(File $file, $pretty = true)
$output = $this->template;
$output = str_replace('{ext}', $file->getExt(), $output);
$output = str_replace('{filename}', $this->sluggify($file->getFilename()), $output);
$output = str_replace('{path}', $file->getPath(), $output);

$filePath = str_replace('\\', '/', $file->getPath());
if (substr($filePath, 0, 1) === '/') {
$filePath = substr($filePath, 1);
}
if (substr($filePath, -1, 1) === '/') {
$filePath = substr($filePath, 0, -1);
}
$filePath = preg_replace('!/+!', '/', $filePath);
$output = str_replace('{path}', $filePath, $output);

/** @var \DateTime $date */
if ($date = $file->getData('date')) {
Expand Down Expand Up @@ -93,6 +102,9 @@ public function getCompiled(File $file, $pretty = true)
$output = '/'.$output;
}

// Ensure valid slashes for url
$output = str_replace('\\', '/', $output);

if ($pretty === true && $file->getData('pretty_permalink', true)) {
return $this->prettify($output);
}
Expand Down
1 change: 0 additions & 1 deletion src/Modules/Config/DefaultConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

/*
* Tapestry Content Types
* @todo write Collections and Generators that use the below
*/
'content_types' => [
'blog' => [
Expand Down
27 changes: 26 additions & 1 deletion src/Modules/Content/Compile.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Tapestry\Entities\ViewFile;
use Tapestry\Entities\CachedFile;
use Tapestry\Entities\ContentType;
use Tapestry\Entities\ProjectFileInterface;
use Symfony\Component\Filesystem\Filesystem;
use Tapestry\Entities\Filesystem\FileCopier;
use Tapestry\Entities\Filesystem\FileWriter;
Expand All @@ -36,6 +37,11 @@ class Compile implements Step
*/
private $tapestry;

/**
* @var array
*/
private $permalinkTable = [];

/**
* Write constructor.
*
Expand Down Expand Up @@ -91,6 +97,10 @@ public function __invoke(Project $project, OutputInterface $output)
return false;
}

if (! $this->checkForPermalinkClashes($project, $output)) {
return false;
}

if ($stopwatch) {
Tapestry::addProfile('Compile.executeContentRenderers_START');
}
Expand Down Expand Up @@ -183,6 +193,21 @@ private function collectProjectFilesUseData(Project $project)
}
}

private function checkForPermalinkClashes(Project $project, OutputInterface $output)
{
/** @var File $file */
foreach ($project['compiled'] as $file) {
if (isset($this->permalinkTable[sha1($file->getCompiledPermalink())])) {
$output->writeln('<error>[!]</error> The permalink ['.$file->getCompiledPermalink().'] is already in use!');

return false;
}
$this->permalinkTable[sha1($file->getCompiledPermalink())] = $file->getUid();
}

return true;
}

private function checkForFileGeneratorError(OutputInterface $output)
{
if (! $this->allFilesGenerated()) {
Expand Down Expand Up @@ -250,7 +275,7 @@ private function mutateFilesToFilesystemInterfaces(Project $project, Cache $cach
}

/**
* @param File|File[] $files
* @param ProjectFileInterface|ProjectFileInterface[]|File|File[] $files
*/
private function add($files)
{
Expand Down
3 changes: 0 additions & 3 deletions src/Plates/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@

/**
* Class Template.
*
* @todo maybe overload the Template class so that we can filter out frontmatter from phtml files before they are rendered and inject into the files data any front matter
* The above may get complex if we are talking about data generators... but it may work in a nice, simple, compact way.
*/
class Template extends PlatesTemplate
{
Expand Down
2 changes: 1 addition & 1 deletion src/Tapestry.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Tapestry implements ContainerAwareInterface, ArrayAccess
*
* @var string
*/
const VERSION = '1.0.9-dev';
const VERSION = '1.0.9';

/**
* Storage of data used by --stopwatch flag.
Expand Down
13 changes: 13 additions & 0 deletions tests/BuildCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,17 @@ public function testDoubleDotFileExt()
$this->assertFileNotExists(__DIR__.'/_tmp/build_local/abc-123-xyz.html');
$this->assertFileExists(__DIR__.'/_tmp/build_local/abc.123.xyz.html');
}

/**
* Written for issue #156
* @link https://github.com/carbontwelve/tapestry/issues/156
*/
public function testPermalinkClashes()
{
$this->copyDirectory('assets/build_test_36/src', '_tmp');

$output = $this->runCommand('build', '');
$this->assertTrue(strpos(trim($output->getDisplay()), 'The permalink [/file-clash.html] is already in use!') !== false);
$this->assertEquals(1, $output->getStatusCode());
}
}
40 changes: 35 additions & 5 deletions tests/PermalinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,25 @@
class PermalinkTest extends CommandTestBase
{
/**
* @param $filePath
* @param File $file
* @return Permalink
*/
private function setupPermalinks($filePath)
private function setupPermalinks(File $file)
{
return $file->getCompiledPermalink();
}

/**
* @param string $filePath
* @return File
*/
private function setupFile($filePath)
{
$file = new File(new SplFileInfo($filePath, '', ''));
$frontMatter = new FrontMatter($file->getFileContent());
$file->setData($frontMatter->getData());
$file->setContent($frontMatter->getContent());
return $file->getCompiledPermalink();
return $file;
}

/**
Expand All @@ -34,7 +43,7 @@ private function setupPermalinks($filePath)
public function testCategoryPermalinkTag()
{
// Synthetic Test
$this->assertEquals('/category1/category2/category3/test-md-post/index.html', $this->setupPermalinks(__DIR__ . '/mocks/TestCategoryPermalinkTag.md'));
$this->assertEquals('/category1/category2/category3/test-md-post/index.html', $this->setupPermalinks($this->setupFile(__DIR__ . '/mocks/TestCategoryPermalinkTag.md')));

// Full Test
$this->copyDirectory('assets/build_test_33/src', '_tmp');
Expand All @@ -45,6 +54,27 @@ public function testCategoryPermalinkTag()

public function testPrettyPermalink()
{
$this->assertEquals('/testfile/index.md', $this->setupPermalinks(__DIR__ . '/mocks/TestFile.md'));
$this->assertEquals('/testfile/index.md', $this->setupPermalinks($this->setupFile(__DIR__ . '/mocks/TestFile.md')));
}

public function testPermalinkPathSlashes()
{
$file = $this->setupFile(__DIR__ . '/mocks/TestFile.md');

$backSlashTest = $file;
$backSlashTest->setPath('hello\\world/123');
$this->assertEquals('/hello/world/123/testfile/index.md', $this->setupPermalinks($backSlashTest));

$beginningSlashTest = $file;
$beginningSlashTest->setPath('/hello/world/123');
$this->assertEquals('/hello/world/123/testfile/index.md', $this->setupPermalinks($beginningSlashTest));

$endingSlashTest = $file;
$endingSlashTest->setPath('/hello/world/123/');
$this->assertEquals('/hello/world/123/testfile/index.md', $this->setupPermalinks($endingSlashTest));

$doubleSlashTest = $file;
$doubleSlashTest->setPath('hello//world\\123/');
$this->assertEquals('/hello/world/123/testfile/index.md', $this->setupPermalinks($doubleSlashTest));
}
}
2 changes: 1 addition & 1 deletion tests/assets/build_test_28/src/kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ public function register()
*/
public function boot()
{
// TODO: Implement boot() method.
// ...
}
}
4 changes: 4 additions & 0 deletions tests/assets/build_test_36/src/source/file-a.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
permalink: file-clash.html
---
Hello world from File A
4 changes: 4 additions & 0 deletions tests/assets/build_test_36/src/source/file-b.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
permalink: file-clash.html
---
Hello world from File B

0 comments on commit 343be8e

Please sign in to comment.