Skip to content

Commit

Permalink
Merge pull request #419 from hydephp/399-markdownfileparser-not-using…
Browse files Browse the repository at this point in the history
…-the-hyde-path

Fix #399: MarkdownFileParser not using the Hyde path hydephp/develop@379c37b
  • Loading branch information
github-actions committed Aug 12, 2022
1 parent 26e94ad commit dfb1d63
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
3 changes: 1 addition & 2 deletions src/Models/MarkdownDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Hyde\Framework\Models;

use Hyde\Framework\Contracts\MarkdownDocumentContract;
use Hyde\Framework\Hyde;
use Hyde\Framework\Modules\Markdown\MarkdownFileParser;

/**
Expand Down Expand Up @@ -41,6 +40,6 @@ public function markdown(): Markdown

public static function parse(string $localFilepath): static
{
return (new MarkdownFileParser(Hyde::path($localFilepath)))->get();
return (new MarkdownFileParser($localFilepath))->get();
}
}
2 changes: 1 addition & 1 deletion src/Modules/DataCollections/DataCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static function markdown(string $key): static
$collection = new DataCollection($key);
foreach ($collection->getMarkdownFiles() as $file) {
$collection->push(
(new MarkdownFileParser($file))->get()
(new MarkdownFileParser(Hyde::pathToRelative($file)))->get()
);
}

Expand Down
5 changes: 3 additions & 2 deletions src/Modules/Markdown/MarkdownFileParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Hyde\Framework\Modules\Markdown;

use Hyde\Framework\Hyde;
use Hyde\Framework\Models\MarkdownDocument;
use Spatie\YamlFrontMatter\YamlFrontMatter;

Expand All @@ -26,9 +27,9 @@ class MarkdownFileParser
*/
public string $markdown = '';

public function __construct(string $filepath)
public function __construct(string $localFilepath)
{
$stream = file_get_contents($filepath);
$stream = file_get_contents(Hyde::path($localFilepath));

// Check if the file has Front Matter.
if (str_starts_with($stream, '---')) {
Expand Down
10 changes: 5 additions & 5 deletions tests/Feature/MarkdownFileParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function test_can_parse_markdown_file()
{
file_put_contents(Hyde::path('_posts/test-post.md'), 'Foo bar');

$document = (new MarkdownFileParser(Hyde::path('_posts/test-post.md')))->get();
$document = (new MarkdownFileParser(('_posts/test-post.md')))->get();
$this->assertInstanceOf(MarkdownDocument::class, $document);

$this->assertEquals('Foo bar', $document->markdown);
Expand All @@ -45,7 +45,7 @@ public function test_can_parse_markdown_file_with_front_matter()
{
$this->makeTestPost();

$document = (new MarkdownFileParser(Hyde::path('_posts/test-post.md')))->get();
$document = (new MarkdownFileParser(('_posts/test-post.md')))->get();
$this->assertInstanceOf(MarkdownDocument::class, $document);

$this->assertEquals(FrontMatter::fromArray([
Expand All @@ -64,7 +64,7 @@ public function test_parsed_markdown_post_contains_valid_front_matter()
{
$this->makeTestPost();

$post = (new MarkdownFileParser(Hyde::path('_posts/test-post.md')))->get();
$post = (new MarkdownFileParser(('_posts/test-post.md')))->get();
$this->assertEquals('My New Post', $post->matter('title'));
$this->assertEquals('Mr. Hyde', $post->matter('author'));
$this->assertEquals('blog', $post->matter('category'));
Expand All @@ -74,7 +74,7 @@ public function test_parsed_front_matter_does_not_contain_slug_key()
{
file_put_contents(Hyde::path('_posts/test-post.md'), "---\nslug: foo\n---\n");

$post = (new MarkdownFileParser(Hyde::path('_posts/test-post.md')))->get();
$post = (new MarkdownFileParser(('_posts/test-post.md')))->get();
$this->assertNull($post->matter('slug'));
$this->assertEquals(FrontMatter::fromArray([]), $post->matter);
}
Expand All @@ -83,7 +83,7 @@ public function test_static_parse_shorthand()
{
$this->makeTestPost();

$post = MarkdownFileParser::parse(Hyde::path('_posts/test-post.md'));
$post = MarkdownFileParser::parse(('_posts/test-post.md'));
$this->assertEquals('My New Post', $post->matter('title'));
$this->assertEquals('Mr. Hyde', $post->matter('author'));
$this->assertEquals('blog', $post->matter('category'));
Expand Down

0 comments on commit dfb1d63

Please sign in to comment.