Skip to content

Commit dfb1d63

Browse files
author
github-actions
committed
Merge pull request #419 from hydephp/399-markdownfileparser-not-using-the-hyde-path
Fix #399: MarkdownFileParser not using the Hyde path hydephp/develop@379c37b
1 parent 26e94ad commit dfb1d63

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

src/Models/MarkdownDocument.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Hyde\Framework\Models;
44

55
use Hyde\Framework\Contracts\MarkdownDocumentContract;
6-
use Hyde\Framework\Hyde;
76
use Hyde\Framework\Modules\Markdown\MarkdownFileParser;
87

98
/**
@@ -41,6 +40,6 @@ public function markdown(): Markdown
4140

4241
public static function parse(string $localFilepath): static
4342
{
44-
return (new MarkdownFileParser(Hyde::path($localFilepath)))->get();
43+
return (new MarkdownFileParser($localFilepath))->get();
4544
}
4645
}

src/Modules/DataCollections/DataCollection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static function markdown(string $key): static
5656
$collection = new DataCollection($key);
5757
foreach ($collection->getMarkdownFiles() as $file) {
5858
$collection->push(
59-
(new MarkdownFileParser($file))->get()
59+
(new MarkdownFileParser(Hyde::pathToRelative($file)))->get()
6060
);
6161
}
6262

src/Modules/Markdown/MarkdownFileParser.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Hyde\Framework\Modules\Markdown;
44

5+
use Hyde\Framework\Hyde;
56
use Hyde\Framework\Models\MarkdownDocument;
67
use Spatie\YamlFrontMatter\YamlFrontMatter;
78

@@ -26,9 +27,9 @@ class MarkdownFileParser
2627
*/
2728
public string $markdown = '';
2829

29-
public function __construct(string $filepath)
30+
public function __construct(string $localFilepath)
3031
{
31-
$stream = file_get_contents($filepath);
32+
$stream = file_get_contents(Hyde::path($localFilepath));
3233

3334
// Check if the file has Front Matter.
3435
if (str_starts_with($stream, '---')) {

tests/Feature/MarkdownFileParserTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function test_can_parse_markdown_file()
3535
{
3636
file_put_contents(Hyde::path('_posts/test-post.md'), 'Foo bar');
3737

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

4141
$this->assertEquals('Foo bar', $document->markdown);
@@ -45,7 +45,7 @@ public function test_can_parse_markdown_file_with_front_matter()
4545
{
4646
$this->makeTestPost();
4747

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

5151
$this->assertEquals(FrontMatter::fromArray([
@@ -64,7 +64,7 @@ public function test_parsed_markdown_post_contains_valid_front_matter()
6464
{
6565
$this->makeTestPost();
6666

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

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

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

0 commit comments

Comments
 (0)