-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #325 from hydephp/improve-file-parsing
Handle complex parsing logic in new parser action hydephp/develop@c7f34a0
- Loading branch information
github-actions
committed
Aug 3, 2022
1 parent
eabedd7
commit 1a3937b
Showing
11 changed files
with
104 additions
and
177 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,3 @@ | ||
<?php | ||
|
||
namespace Hyde\Framework\Concerns; | ||
|
||
use Hyde\Framework\Hyde; | ||
|
||
/** | ||
* Find and get the title to use for a Markdown Document. | ||
* | ||
* First check the front matter for a title. If one is not found, | ||
* it searches the Markdown for a level one heading. Falls back to | ||
* generating a title from the slug if no other title could be found. | ||
* | ||
* @deprecated Move to action to generate when constructing a page. | ||
*/ | ||
trait HasDynamicTitle | ||
{ | ||
public function constructDynamicTitle(): void | ||
{ | ||
if (! isset($this->title) || $this->title === '') { | ||
$this->title = $this->findTitleForDocument(); | ||
} | ||
} | ||
|
||
public function findTitleForDocument(): string | ||
{ | ||
if (isset($this->matter['title'])) { | ||
return $this->matter['title']; | ||
} | ||
|
||
return $this->findTitleTagInMarkdown($this->body) | ||
?: Hyde::makeTitle($this->slug); | ||
} | ||
|
||
/** | ||
* Attempt to find the title based on the first H1 tag. | ||
*/ | ||
protected function findTitleTagInMarkdown(string $stream): string|false | ||
{ | ||
$lines = explode("\n", $stream); | ||
|
||
foreach ($lines as $line) { | ||
if (str_starts_with($line, '# ')) { | ||
return trim(substr($line, 2), ' '); | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.