Skip to content

Commit eb0f922

Browse files
authored
Merge pull request #1594 from hydephp/massively-simplify-sidebar-footer-text-handling
[2.x] Massively simplify sidebar footer text handling
2 parents 08981bd + 2fcf75a commit eb0f922

File tree

7 files changed

+25
-63
lines changed

7 files changed

+25
-63
lines changed

config/docs.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@
3030
// When using a grouped sidebar, should the groups be collapsible?
3131
'collapsible' => true,
3232

33-
// Should the sidebar footer be shown? You can also set this to a string
34-
// of Markdown to show in the footer. Set to `false` to disable.
35-
'footer' => true,
33+
// A string of Markdown to show in the footer. Set to `false` to disable.
34+
'footer' => '[Back to home page](../)',
3635

3736
/*
3837
|--------------------------------------------------------------------------
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
<p>
2-
@if(is_bool($sidebar->getFooter())))
3-
<a href="{{ Hyde::relativeLink('index.html') }}">Back to home page</a>
4-
@else
5-
{{ Hyde::markdown($sidebar->getFooter()) }}
6-
@endif
7-
</p>
1+
{{ Hyde::markdown($sidebar->getFooter()) }}

packages/framework/src/Framework/Features/Navigation/DocumentationSidebar.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,25 @@ public function __construct(Arrayable|array $items = [])
2828
parent::__construct($items);
2929
}
3030

31-
public function getFooter(): bool|string
31+
public function getFooter(): ?string
3232
{
33-
return Config::get('docs.sidebar.footer', true);
34-
}
35-
36-
public function getFooterText(): ?string
37-
{
38-
$option = Config::get('docs.sidebar.footer', true);
33+
$option = Config::get('docs.sidebar.footer', '[Back to home page](../)');
3934

4035
if (is_string($option)) {
4136
return $option;
4237
}
4338

39+
if ($option === true) {
40+
/** @deprecated Backwards compatibility */
41+
return '[Back to home page](../)';
42+
}
43+
4444
return null;
4545
}
4646

4747
public function hasFooter(): bool
4848
{
49-
if (is_string(Config::get('docs.sidebar.footer', true))) {
50-
return true;
51-
}
52-
53-
return Config::getBool('docs.sidebar.footer', true);
49+
return $this->getFooter() !== null;
5450
}
5551

5652
public function isCollapsible(): bool

packages/framework/tests/Feature/SidebarViewTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function testBaseSidebar()
3737
->assertSeeHtml('<ul id="sidebar-items" role="list"')
3838
->assertSeeHtml('<nav id="sidebar-navigation"')
3939
->assertSeeHtml('<footer id="sidebar-footer"')
40-
->assertSeeHtml('<a href="index.html">Back to home page</a>')
40+
->assertSeeHtml('<a href="../">Back to home page</a>')
4141
->assertSeeHtml('<span class="sr-only">Toggle dark theme</span>')
4242
->assertDontSee('<a href="docs/index.html">')
4343
->assertDontSee('<li class="sidebar-item')
@@ -53,9 +53,10 @@ public function testBaseSidebarWithoutFooter()
5353
{
5454
config(['docs.sidebar.footer' => false]);
5555

56-
$this->renderComponent(view('hyde::components.docs.sidebar'));
57-
58-
$this->assertViewWasNotRendered(view('hyde::components.docs.sidebar-footer-text'));
56+
$this->renderComponent(view('hyde::components.docs.sidebar'))
57+
->assertDontSee('<footer id="sidebar-footer"')
58+
->assertDontSee('Back to home page')
59+
->allGood();
5960
}
6061

6162
public function testBaseSidebarWithCustomFooterText()

packages/framework/tests/Feature/Views/SidebarFooterTextViewTest.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function testSidebarFooterTextViewWithDefaultConfig()
1717
{
1818
$view = $this->test(view('hyde::components.docs.sidebar-footer-text', $this->withSidebar()));
1919

20-
$view->assertSeeHtml('<a href="index.html">Back to home page</a>');
20+
$view->assertSeeHtml('<a href="../">Back to home page</a>');
2121
}
2222

2323
public function testSidebarFooterTextViewWhenConfigOptionIsTrue()
@@ -26,7 +26,7 @@ public function testSidebarFooterTextViewWhenConfigOptionIsTrue()
2626

2727
$view = $this->test(view('hyde::components.docs.sidebar-footer-text', $this->withSidebar()));
2828

29-
$view->assertSeeHtml('<a href="index.html">Back to home page</a>');
29+
$view->assertSeeHtml('<a href="../">Back to home page</a>');
3030
}
3131

3232
public function testSidebarFooterTextViewWhenConfigOptionIsMarkdownString()
@@ -38,13 +38,6 @@ public function testSidebarFooterTextViewWhenConfigOptionIsMarkdownString()
3838
$view->assertSeeText('Your Markdown String Here');
3939
}
4040

41-
public function testSidebarFooterTextViewWhenConfigOptionIsFalse()
42-
{
43-
// This state is handled earlier in the component by the sidebar component so we don't need to test it here.
44-
45-
$this->assertTrue(true);
46-
}
47-
4841
protected function withSidebar(): array
4942
{
5043
return ['sidebar' => new DocumentationSidebar()];

packages/framework/tests/Unit/DocumentationSidebarUnitTest.php

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ public function testGetMethodResolvesInstanceFromServiceContainer()
122122
$this->assertSame($instance, DocumentationSidebar::get());
123123
}
124124

125-
public function testGetFooterReturnsTrueByDefault()
125+
public function testGetFooterReturnsBackLinkByDefault()
126126
{
127127
self::mockConfig();
128128

129-
$this->assertTrue((new DocumentationSidebar())->getFooter());
129+
$this->assertSame('[Back to home page](../)', (new DocumentationSidebar())->getFooter());
130130
}
131131

132132
public function testGetFooterReturnsStringWhenConfigIsString()
@@ -136,39 +136,18 @@ public function testGetFooterReturnsStringWhenConfigIsString()
136136
$this->assertSame('Some footer content', (new DocumentationSidebar())->getFooter());
137137
}
138138

139-
public function testGetFooterReturnsTrueWhenConfigIsTrue()
139+
public function testGetFooterReturnsBackLinkWhenConfigIsTrue()
140140
{
141141
self::mockConfig(['docs.sidebar.footer' => true]);
142142

143-
$this->assertTrue((new DocumentationSidebar())->getFooter());
143+
$this->assertSame('[Back to home page](../)', (new DocumentationSidebar())->getFooter());
144144
}
145145

146-
public function testGetFooterReturnsFalseWhenConfigIsFalse()
146+
public function testGetFooterReturnsNullWhenConfigIsFalse()
147147
{
148148
self::mockConfig(['docs.sidebar.footer' => false]);
149149

150-
$this->assertFalse((new DocumentationSidebar())->getFooter());
151-
}
152-
153-
public function testGetFooterTextReturnsStringWhenConfigIsString()
154-
{
155-
self::mockConfig(['docs.sidebar.footer' => 'Some footer content']);
156-
157-
$this->assertSame('Some footer content', (new DocumentationSidebar())->getFooterText());
158-
}
159-
160-
public function testGetFooterTextReturnsNullWhenConfigIsTrue()
161-
{
162-
self::mockConfig(['docs.sidebar.footer' => true]);
163-
164-
$this->assertNull((new DocumentationSidebar())->getFooterText());
165-
}
166-
167-
public function testGetFooterTextReturnsNullWhenConfigIsFalse()
168-
{
169-
self::mockConfig(['docs.sidebar.footer' => false]);
170-
171-
$this->assertNull((new DocumentationSidebar())->getFooterText());
150+
$this->assertNull((new DocumentationSidebar())->getFooter());
172151
}
173152

174153
public function testIsCollapsibleReturnsTrueByDefault()

packages/framework/tests/Unit/RelativeLinksAcrossPagesRetainsIntegrityTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function testRelativeLinksAcrossPagesRetainsIntegrity()
9393
'<link rel="stylesheet" href="../media/app.css">',
9494
'<a href="../docs/index.html">',
9595
'<a href="../docs/docs.html"',
96-
'<a href="../index.html">Back to home page</a>',
96+
'<a href="../">Back to home page</a>',
9797
]);
9898
}
9999
}

0 commit comments

Comments
 (0)