{{ $post->matter['title'] }}
- -- @isset($post->matter['description']) - {{ $post->matter['description'] }} - @endisset -
- Read more -diff --git a/README.md b/README.md index 367521d..ff0e127 100644 --- a/README.md +++ b/README.md @@ -20,3 +20,9 @@ While the main purpose of this repo is to generate the static HTML Documentation ## License The MIT License (MIT). Please see [License File](LICENSE.md) for more information. + +## Attributions +> Please see the respective authors' repositories for their license files + +- The Hyde core is built with [Laravel Zero](https://laravel-zero.com/) which is based on [Laravel](https://laravel.com/) +- The frontend is built with [TailwindCSS](https://tailwindcss.com/). diff --git a/_site/404.html b/_site/404.html new file mode 100644 index 0000000..9db2b08 --- /dev/null +++ b/_site/404.html @@ -0,0 +1,523 @@ + + +
++ + Syntax highlighting by Torchlight.dev + +
' + ], // The Torchlight client caches highlighted code blocks. Here // you can define which cache driver you'd like to use. If diff --git a/config/view.php b/config/view.php index d41f749..1e7310c 100644 --- a/config/view.php +++ b/config/view.php @@ -2,7 +2,7 @@ return [ 'paths' => [ - resource_path('views'), + Hyde\Framework\Hyde::viewPath(), ], 'compiled' => env( diff --git a/package.json b/package.json index 1f27530..e05c58d 100644 --- a/package.json +++ b/package.json @@ -12,10 +12,10 @@ "watch": "concurrently \"npm:watch-livereload\" \"npm:watch-build\" \"npm:watch-sass\" \"npm:watch-tailwind\"", "watch-livereload": "npx browser-sync _site -w", "watch-build": "chokidar ./_posts/*.md ./_docs/*.md ./resources/views/**/*.blade.php -c \"npm run build\"", - "watch-sass": "sass src/resources/sass/app.scss _site/media/app.css -w", - "watch-tailwind": "npx tailwindcss -i ./src/resources/sass/tailwind.scss -o ./_site/media/tailwind.css --watch", - "prod": "sass src/resources/sass/app.scss _site/media/app.css --style=compressed && npx tailwindcss -i ./src/resources/sass/tailwind.scss -o ./_site/media/tailwind.css --minify", - "dev": " sass src/resources/sass/app.scss _site/media/app.css && npx tailwindcss -i ./src/resources/sass/tailwind.scss -o ./_site/media/tailwind.css" + "watch-sass": "sass resources/sass/app.scss _site/media/app.css -w", + "watch-tailwind": "npx tailwindcss -i ./resources/sass/tailwind.scss -o ./_site/media/tailwind.css --watch", + "prod": "sass resources/sass/app.scss _site/media/app.css --style=compressed && npx tailwindcss -i ./resources/sass/tailwind.scss -o ./_site/media/tailwind.css --minify", + "dev": " sass resources/sass/app.scss _site/media/app.css && npx tailwindcss -i ./resources/sass/tailwind.scss -o ./_site/media/tailwind.css" }, "repository": { "type": "git", diff --git a/src/resources/sass/_torchlight.scss b/resources/sass/_torchlight.scss similarity index 100% rename from src/resources/sass/_torchlight.scss rename to resources/sass/_torchlight.scss diff --git a/src/resources/sass/app.scss b/resources/sass/app.scss similarity index 100% rename from src/resources/sass/app.scss rename to resources/sass/app.scss diff --git a/src/resources/sass/tailwind.scss b/resources/sass/tailwind.scss similarity index 100% rename from src/resources/sass/tailwind.scss rename to resources/sass/tailwind.scss diff --git a/resources/views/components/article-excerpt.blade.php b/resources/views/components/article-excerpt.blade.php deleted file mode 100644 index b0c3860..0000000 --- a/resources/views/components/article-excerpt.blade.php +++ /dev/null @@ -1,26 +0,0 @@ -- @isset($post->matter['description']) - {{ $post->matter['description'] }} - @endisset -
- Read more -- {{ $post->matter['description'] }} -
\ No newline at end of file diff --git a/resources/views/docs.blade.php b/resources/views/docs.blade.php deleted file mode 100644 index 0d96ef8..0000000 --- a/resources/views/docs.blade.php +++ /dev/null @@ -1,62 +0,0 @@ -{{-- The Documentation Page Layout based on Laradocgen --}} -@extends('layouts.app') -@section('content') -@php($withoutNavigation = true) - - -- - Syntax highlighting by Torchlight.dev - -
\ No newline at end of file diff --git a/tailwind.config.js b/tailwind.config.js index 39c62fb..6c70c65 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -3,7 +3,7 @@ const defaultTheme = require('tailwindcss/defaultTheme'); module.exports = { darkMode: 'class', content: [ - './resources/views/**/*.blade.php', + './_site/**/*.html', ], theme: { diff --git a/tests/Feature/Commands/MakePostCommandTest.php b/tests/Feature/Commands/MakePostCommandTest.php index f8550de..da06541 100644 --- a/tests/Feature/Commands/MakePostCommandTest.php +++ b/tests/Feature/Commands/MakePostCommandTest.php @@ -2,18 +2,19 @@ namespace Tests\Feature\Commands; +use Hyde\Framework\Hyde; use Tests\TestCase; class MakePostCommandTest extends TestCase { /** * Get the path of the test Markdown file. - * + * * @return string */ public function getPath(): string { - return realpath('./_posts') . '/test-post.md'; + return Hyde::path('_posts/test-post.md'); } /** @@ -39,7 +40,7 @@ public function test_command_has_expected_output_and_creates_valid_file() ->expectsQuestion('What is the primary category of the post?', 'general') ->expectsOutput('Creating a post with the following details:') ->expectsConfirmation('Do you wish to continue?', 'yes') - + ->assertExitCode(0); $this->assertFileExists($this->getPath()); @@ -56,7 +57,7 @@ public function test_that_files_are_not_overwritten_when_force_flag_is_not_set() ->expectsQuestion('What is your (the author\'s) name?', 'PHPUnit') ->expectsQuestion('What is the primary category of the post?', 'general') ->expectsOutput('Creating a post with the following details:') - + ->expectsConfirmation('Do you wish to continue?', 'yes') ->expectsOutput('If you want to overwrite the file supply the --force flag.') @@ -65,7 +66,7 @@ public function test_that_files_are_not_overwritten_when_force_flag_is_not_set() $this->assertStringContainsString('This should not be overwritten', file_get_contents($this->getPath())); } - + public function test_that_files_are_overwritten_when_force_flag_is_set() { file_put_contents($this->getPath(), 'This should be overwritten'); diff --git a/tests/Feature/Commands/Publish404PageCommandTest.php b/tests/Feature/Commands/Publish404PageCommandTest.php deleted file mode 100644 index 4faa058..0000000 --- a/tests/Feature/Commands/Publish404PageCommandTest.php +++ /dev/null @@ -1,144 +0,0 @@ -unlink(); - - parent::setUp(); - } - - /** - * Clean up after tests by removing the created files. - * @return void - */ - protected function tearDown(): void - { - $this->unlink(); - - parent::tearDown(); - } - - private function unlink(): void - { - if (file_exists($this->getBladePath())) { - unlink($this->getBladePath()); - } - if (file_exists($this->getMarkdownPath())) { - unlink($this->getMarkdownPath()); - } - } - - private function getBladePath(): string - { - return realpath('resources/views/pages') . DIRECTORY_SEPARATOR . '404.blade.php'; - } - - private function getMarkdownPath(): string - { - return realpath('_pages') . DIRECTORY_SEPARATOR . '404.md'; - } - - public function test_command_exists() - { - $this->artisan('publish:404 --help')->assertExitCode(0); - $this->assertCommandCalled('publish:404 --help'); - } - - public function test_command_creates_blade_file() - { - $path = $this->getBladePath(); - - // Assert that no old file exists which would cause issues - $this->assertFileDoesNotExist($path); - - $this->artisan('publish:404 --type="blade" --no-interaction') - ->expectsOutput("Created file $path!") - ->assertExitCode(0); - - $this->assertFileExists($path); - } - - public function test_command_creates_markdown_file() - { - $path = $this->getMarkdownPath(); - - // Assert that no old file exists which would cause issues - $this->assertFileDoesNotExist($path); - - $this->artisan('publish:404 --type="markdown" --no-interaction') - ->expectsOutput("Created file $path!") - ->assertExitCode(0); - - $this->assertFileExists($path); - } - - public function test_command_does_not_accept_invalid_type() - { - $this->artisan('publish:404 --type="invalid-type"') - ->expectsOutput('Type `invalid-type` is not valid. It must be either `blade` or `markdown`') - ->assertExitCode(400); - - $this->artisan('publish:404') - ->expectsQuestion('Which type of view would you like to publish?', 'invalid-type') - ->expectsOutput('Type `invalid-type` is not valid. It must be either `blade` or `markdown`') - ->assertExitCode(400); - } - - public function test_command_does_not_overwrite_existing_files() - { - $path = $this->getMarkdownPath(); - - file_put_contents($path, "Test File"); - - // Assert that the created file exists - $this->assertFileExists($path); - - $this->artisan('publish:404 --type="markdown" --no-interaction') - ->expectsOutput("File $path already exists!") - ->assertExitCode(409); - - // Assert the file contents were not overwritten - $this->assertStringContainsString('Test File', - file_get_contents($path)); - } - - public function test_command_does_overwrite_existing_files_when_force_flag_is_set() - { - $path = $this->getMarkdownPath(); - - file_put_contents($path, "Test File"); - - // Assert that the created file exists - $this->assertFileExists($path); - - $this->artisan('publish:404 --type="markdown" --force --no-interaction') - ->expectsOutput("Created file $path!") - ->assertExitCode(0); - - // Assert the file contents were overwritten - $this->assertStringNotContainsString('Test File', - file_get_contents($path)); - } - - public function test_command_is_interactive_and_uses_the_supplied_answer() - { - $markdownPath = $this->getMarkdownPath(); - $bladePath = $this->getBladePath(); - - $this->artisan('publish:404') - ->expectsQuestion('Which type of view would you like to publish?', 'Markdown') - ->expectsOutput("Created file $markdownPath!") - ->doesntExpectOutput("Created file $bladePath!") - ->assertExitCode(0); - } -} \ No newline at end of file diff --git a/tests/Feature/InspireCommandTest.php b/tests/Feature/InspireCommandTest.php deleted file mode 100644 index 58c71a1..0000000 --- a/tests/Feature/InspireCommandTest.php +++ /dev/null @@ -1,5 +0,0 @@ -artisan('inspire')->assertExitCode(0); -}); diff --git a/tests/Unit/CreatesDefaultDirectoriesTest.php b/tests/Unit/CreatesDefaultDirectoriesTest.php index 40daa35..97343cc 100644 --- a/tests/Unit/CreatesDefaultDirectoriesTest.php +++ b/tests/Unit/CreatesDefaultDirectoriesTest.php @@ -2,17 +2,18 @@ namespace Tests\Unit; +use Hyde\Framework\Actions\CreatesDefaultDirectories; +use Hyde\Framework\Hyde; use PHPUnit\Framework\TestCase; -use App\Actions\CreatesDefaultDirectories; class CreatesDefaultDirectoriesTest extends TestCase { /** * Test if the directories are created. - * + * * Note that the action is called by the Service Provider * when booting, so we don't call the action directly. - * + * * To properly test that it works, you should first * remove the directories manually as the action * will not have anything to do otherwise. @@ -22,7 +23,7 @@ class CreatesDefaultDirectoriesTest extends TestCase public function testDefaultDirectoriesAreCreated() { foreach (CreatesDefaultDirectories::getRequiredDirectories() as $directory) { - $this->assertTrue(is_dir(realpath("./$directory"))); + $this->assertTrue(is_dir(Hyde::path($directory))); } } } diff --git a/tests/Unit/ExampleTest.php b/tests/Unit/ExampleTest.php deleted file mode 100644 index 61cd84c..0000000 --- a/tests/Unit/ExampleTest.php +++ /dev/null @@ -1,5 +0,0 @@ -toBeTrue(); -}); diff --git a/tests/Unit/HydePathHelperTest.php b/tests/Unit/HydePathHelperTest.php new file mode 100644 index 0000000..41385bb --- /dev/null +++ b/tests/Unit/HydePathHelperTest.php @@ -0,0 +1,46 @@ +toBeTrue(); +}); + +test('string is returned', function () { + expect(Hyde::path())->toBeString(); +}); + +test('returned directory contains content expected to be in the project directory', + function () { + expect( + file_exists(Hyde::path() . DIRECTORY_SEPARATOR . 'hyde') && + file_exists(Hyde::path() . DIRECTORY_SEPARATOR . '_pages') && + file_exists(Hyde::path() . DIRECTORY_SEPARATOR . '_posts') && + file_exists(Hyde::path() . DIRECTORY_SEPARATOR . '_site') + )->toBeTrue(); + } +); + +test('method returns qualified file path when supplied with argument', function () { + expect(Hyde::path('file.php'))->toEqual(Hyde::path() . DIRECTORY_SEPARATOR . 'file.php'); +}); + +test('method strips trailing directory separators from argument', function () { + expect(Hyde::path('\\/file.php/'))->toEqual(Hyde::path() . DIRECTORY_SEPARATOR . 'file.php'); +}); + +test('method returns expected value for nested path arguments', function () { + expect(Hyde::path('directory/file.php')) + ->toEqual(Hyde::path() . DIRECTORY_SEPARATOR . 'directory/file.php'); +}); + +test('method returns expected value regardless of trailing directory separators in argument', function () { + expect(Hyde::path('directory/file.php/')) + ->toEqual(Hyde::path() . DIRECTORY_SEPARATOR . 'directory/file.php'); + expect(Hyde::path('/directory/file.php/')) + ->toEqual(Hyde::path() . DIRECTORY_SEPARATOR . 'directory/file.php'); + expect(Hyde::path('\\/directory/file.php/')) + ->toEqual(Hyde::path() . DIRECTORY_SEPARATOR . 'directory/file.php'); +}); diff --git a/tests/Unit/MarkdownPostParserTest.php b/tests/Unit/MarkdownPostParserTest.php index 3276934..b479090 100644 --- a/tests/Unit/MarkdownPostParserTest.php +++ b/tests/Unit/MarkdownPostParserTest.php @@ -2,8 +2,9 @@ namespace Tests\Unit; -use App\Hyde\MarkdownPostParser; -use App\Hyde\Models\MarkdownPost; +use Hyde\Framework\Hyde; +use Hyde\Framework\MarkdownPostParser; +use Hyde\Framework\Models\MarkdownPost; use PHPUnit\Framework\TestCase; class MarkdownPostParserTest extends TestCase @@ -17,7 +18,7 @@ protected function setUp(): void parent::setUp(); // Create a Markdown file to work with - copy(realpath('./tests') . '/_stubs/_posts/test-parser-post.md', $this->getPath()); + copy(Hyde::path('tests/_stubs/_posts/test-parser-post.md'), $this->getPath()); } /** @@ -39,7 +40,7 @@ protected function tearDown(): void */ public function getPath(): string { - return realpath('./_posts') . '/test-parser-post.md'; + return Hyde::path('_posts/test-parser-post.md'); } public function testCanParseMarkdownFile() @@ -47,9 +48,19 @@ public function testCanParseMarkdownFile() $post = (new MarkdownPostParser('test-parser-post'))->get(); $this->assertInstanceOf(MarkdownPost::class, $post); $this->assertCount(4, ($post->matter)); + $this->assertIsArray($post->matter); $this->assertIsString($post->body); $this->assertIsString($post->slug); $this->assertTrue(strlen($post->body) > 32); $this->assertTrue(strlen($post->slug) > 8); } + + public function testParsedMarkdownPostContainsValidFrontMatter() + { + $post = (new MarkdownPostParser('test-parser-post'))->get(); + $this->assertEquals('My New Post', $post->matter['title']); + $this->assertEquals('Mr. Hyde', $post->matter['author']); + $this->assertEquals('blog', $post->matter['category']); + $this->assertEquals('test-parser-post', $post->matter['slug']); + } } diff --git a/tests/Validators/CheckForPageConflictsTest.php b/tests/Validators/CheckForPageConflictsTest.php index b0fe09b..2c2c535 100644 --- a/tests/Validators/CheckForPageConflictsTest.php +++ b/tests/Validators/CheckForPageConflictsTest.php @@ -1,23 +1,25 @@ addWarning('Found conflicts: ' . implode(', ', $conflicts)); + } else { + expect($conflicts)->toBeEmpty(); + } - if (count($conflicts)) { - $this->addWarning('Found conflicts: ' . implode(', ', $conflicts)); - } else { - expect($conflicts)->toBeEmpty(); - } - -})->group('validators'); + })->group('validators'); +} diff --git a/tests/Validators/CheckIfA404PageExistsTest.php b/tests/Validators/CheckIfA404PageExistsTest.php index e7b6cfa..71eb2d6 100644 --- a/tests/Validators/CheckIfA404PageExistsTest.php +++ b/tests/Validators/CheckIfA404PageExistsTest.php @@ -1,11 +1,13 @@ addWarning('Could not find an 404.md or 404.blade.php file! You can scaffold one using `php hyde publish:404`'); + $this->addWarning('Could not find an 404.md or 404.blade.php file! You can publish the default one using `php hyde publish:views`'); } else { $this->assertTrue($assertion); } diff --git a/tests/Validators/CheckIfAnIndexPageExistsTest.php b/tests/Validators/CheckIfAnIndexPageExistsTest.php new file mode 100644 index 0000000..16ae263 --- /dev/null +++ b/tests/Validators/CheckIfAnIndexPageExistsTest.php @@ -0,0 +1,14 @@ +addWarning('Could not find an index.md or index.blade.php file! You can publish the default one using `php hyde publish:views`'); + } else { + $this->assertTrue($assertion); + } +})->group('validators'); diff --git a/tests/Validators/CheckThatAnIndexFileExistsTest.php b/tests/Validators/CheckThatAnIndexFileExistsTest.php deleted file mode 100644 index d0c2e13..0000000 --- a/tests/Validators/CheckThatAnIndexFileExistsTest.php +++ /dev/null @@ -1,12 +0,0 @@ -addWarning('Could not find an index.md or index.blade.php file!'); - } else { - $this->assertTrue($assertion); - } -})->group('validators'); diff --git a/tests/Validators/CheckThatDocumentationPagesHaveAnIndexPageTest.php b/tests/Validators/CheckThatDocumentationPagesHaveAnIndexPageTest.php index fc870fa..0a033eb 100644 --- a/tests/Validators/CheckThatDocumentationPagesHaveAnIndexPageTest.php +++ b/tests/Validators/CheckThatDocumentationPagesHaveAnIndexPageTest.php @@ -1,6 +1,6 @@ addWarning($message); + $this->addWarning($message); } else { $this->assertTrue($indexFileExists); }