Skip to content

Commit 9fe9ea1

Browse files
authored
Merge pull request #330 from hydephp/make-file-parser-helpers-public
Make file parser helpers public
2 parents 4553440 + 338445c commit 9fe9ea1

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

RELEASE_NOTES.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ The identifier property is closely related to the page model's route key propert
2424
- Breaking: Rename AbstractPage property `slug` to `identifier`
2525
- Breaking: Change `AbstractMarkdownPage` constructor argument positions, putting `identifier` first
2626
- Begin changing references to slugs to identifiers, see motivation above
27+
- Makes some helpers in SourceFileParser public static allowing them to be used outside the class
2728

2829
### Deprecated
2930
- for soon-to-be removed features.

packages/framework/src/Actions/SourceFileParser.php

+14-14
Original file line numberDiff line numberDiff line change
@@ -68,29 +68,29 @@ protected function parseMarkdownPage(string $pageClass): AbstractMarkdownPage
6868

6969
protected function constructDynamicData(): void
7070
{
71-
$this->page->title = $this->findTitleForPage();
71+
$this->page->title = static::findTitleForPage($this->page, $this->slug);
7272

7373
if ($this->page instanceof DocumentationPage) {
74-
$this->page->category = $this->getDocumentationPageCategory();
74+
$this->page->category = static::getDocumentationPageCategory($this->slug, $this->page);
7575
}
7676
}
7777

78-
protected function findTitleForPage(): string
78+
public static function findTitleForPage($page, $slug): string
7979
{
80-
if ($this->page instanceof BladePage) {
81-
return Hyde::makeTitle($this->slug);
80+
if ($page instanceof BladePage) {
81+
return Hyde::makeTitle($slug);
8282
}
8383

84-
if ($this->page->matter('title')) {
85-
return $this->page->matter('title');
84+
if ($page->matter('title')) {
85+
return $page->matter('title');
8686
}
8787

88-
return $this->findTitleFromMarkdownHeadings() ?? Hyde::makeTitle($this->slug);
88+
return static::findTitleFromMarkdownHeadings($page) ?? Hyde::makeTitle($slug);
8989
}
9090

91-
protected function findTitleFromMarkdownHeadings(): ?string
91+
public static function findTitleFromMarkdownHeadings($page): ?string
9292
{
93-
foreach ($this->page->markdown()->toArray() as $line) {
93+
foreach ($page->markdown()->toArray() as $line) {
9494
if (str_starts_with($line, '# ')) {
9595
return trim(substr($line, 2), ' ');
9696
}
@@ -99,15 +99,15 @@ protected function findTitleFromMarkdownHeadings(): ?string
9999
return null;
100100
}
101101

102-
protected function getDocumentationPageCategory(): ?string
102+
public static function getDocumentationPageCategory($slug, $page): ?string
103103
{
104104
// If the documentation page is in a subdirectory,
105105
// then we can use that as the category name.
106106
// Otherwise, we look in the front matter.
107107

108-
return str_contains($this->slug, '/')
109-
? Str::before($this->slug, '/')
110-
: $this->page->matter('category');
108+
return str_contains($slug, '/')
109+
? Str::before($slug, '/')
110+
: $page->matter('category');
111111
}
112112

113113
public function get(): PageContract

0 commit comments

Comments
 (0)