Skip to content

Commit

Permalink
Merge pull request #1566 from hydephp/conditional-semantic-documentat…
Browse files Browse the repository at this point in the history
…ion-article-rendering

[2.x] Add conditional semantic documentation article rendering
  • Loading branch information
caendesilva authored Feb 13, 2024
2 parents d764907 + 886c9c6 commit 7282990
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 17 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This serves two purposes:
### Changed
- Changed how the documentation search is generated, to be an `InMemoryPage` instead of a post-build task.
- Media asset files are now copied using the new build task instead of the deprecated `BuildService::transferMediaAssets()` method.
- Minor: The documentation article component now supports disabling the semantic rendering using a falsy value in https://github.com/hydephp/develop/pull/1566

### Deprecated
- for soon-to-be removed features.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
<article id="document" itemscope itemtype="https://schema.org/Article" @class([
'mx-auto lg:ml-8 max-w-3xl p-12 md:px-16 max-w-[1000px] min-h-[calc(100vh_-_4rem)]',
config('markdown.prose_classes', 'prose dark:prose-invert'),
'torchlight-enabled' => $article->hasTorchlight()])>
'torchlight-enabled' => $article && $article->hasTorchlight()])>
@yield('content')

<header id="document-header" class="flex items-center flex-wrap justify-between prose-h1:mb-3">
{{ $article->renderHeader() }}
</header>
<section id="document-main-content" itemprop="articleBody">
{{ $article->renderBody() }}
</section>
<footer id="document-footer" class="flex items-center flex-wrap mt-8 prose-p:my-3 justify-between text-[90%]">
{{ $article->renderFooter() }}
</footer>
@if ($article)
<header id="document-header" class="flex items-center flex-wrap justify-between prose-h1:mb-3">
{{ $article->renderHeader() }}
</header>
<section id="document-main-content" itemprop="articleBody">
{{ $article->renderBody() }}
</section>
<footer id="document-footer" class="flex items-center flex-wrap mt-8 prose-p:my-3 justify-between text-[90%]">
{{ $article->renderFooter() }}
</footer>
@endif
</article>
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct()
parent::__construct(static::routeKey(), [
'title' => 'Search',
'navigation' => ['hidden' => true],
'article' => $this->makeArticle(),
'article' => false,
], view: 'hyde::pages.documentation-search');
}

Expand All @@ -59,10 +59,4 @@ protected static function anotherSearchPageExists(): bool
// we need to check the page collection directly, instead of the route collection.
return Hyde::pages()->first(fn (HydePage $file): bool => $file->getRouteKey() === static::routeKey()) !== null;
}

/** @experimental Fixes type issue {@see https://github.com/hydephp/develop/commit/37f7046251b8c0514b8d8ef821de4ef3d35bbac8#commitcomment-135026537} */
protected function makeArticle(): SemanticDocumentationArticle
{
return SemanticDocumentationArticle::make(new DocumentationPage());
}
}
30 changes: 30 additions & 0 deletions packages/framework/tests/Feature/DocumentationSearchPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,34 @@ public function testStaticRouteKeyHelperWithRootOutputDirectory()
DocumentationPage::setOutputDirectory('');
$this->assertSame('search', DocumentationSearchPage::routeKey());
}

public function testCanRenderSearchPage()
{
$page = new DocumentationSearchPage();

Hyde::shareViewData($page);
$this->assertStringContainsString('<h1>Search the documentation site</h1>', $page->compile());
}

public function testRenderedSearchPageUsesDocumentationPageLayout()
{
$page = new DocumentationSearchPage();

Hyde::shareViewData($page);
$html = $page->compile();

$this->assertStringContainsString('<body id="hyde-docs"', $html);
}

public function testRenderedSearchPageDoesNotUseSemanticDocumentationMarkup()
{
$page = new DocumentationSearchPage();

Hyde::shareViewData($page);
$html = $page->compile();

$this->assertStringNotContainsString('<header id="document-header"', $html);
$this->assertStringNotContainsString('<section id="document-main-content"', $html);
$this->assertStringNotContainsString('<footer id="document-footer"', $html);
}
}

0 comments on commit 7282990

Please sign in to comment.