File tree 3 files changed +32
-3
lines changed
3 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -15,12 +15,14 @@ class DocumentationSidebarItem
15
15
public string $ label ;
16
16
public string $ destination ;
17
17
public int $ priority ;
18
+ public bool $ hidden = false ;
18
19
19
- public function __construct (string $ label , string $ destination , ?int $ priority = null )
20
+ public function __construct (string $ label , string $ destination , ?int $ priority = null , bool $ hidden = false )
20
21
{
21
22
$ this ->label = $ label ;
22
23
$ this ->destination = $ destination ;
23
24
$ this ->priority = $ priority ?? $ this ->findPriorityInConfig ($ destination );
25
+ $ this ->hidden = $ hidden ;
24
26
}
25
27
26
28
protected function findPriorityInConfig (string $ slug ): int
@@ -34,6 +36,11 @@ protected function findPriorityInConfig(string $slug): int
34
36
return array_search ($ slug , $ orderIndexArray ); // + 250?
35
37
}
36
38
39
+ public function isHidden (): bool
40
+ {
41
+ return $ this ->hidden ;
42
+ }
43
+
37
44
public static function parseFromFile (string $ documentationPageSlug ): static
38
45
{
39
46
$ matter = YamlFrontMatter::markdownCompatibleParse (
@@ -43,7 +50,8 @@ public static function parseFromFile(string $documentationPageSlug): static
43
50
return new static (
44
51
$ matter ['label ' ] ?? Hyde::titleFromSlug ($ documentationPageSlug ),
45
52
$ documentationPageSlug ,
46
- $ matter ['priority ' ] ?? null
53
+ $ matter ['priority ' ] ?? null ,
54
+ $ matter ['hidden ' ] ?? false
47
55
);
48
56
}
49
57
}
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ class DocumentationSidebarService implements DocumentationSidebarServiceContract
23
23
*/
24
24
public static function get (): DocumentationSidebar
25
25
{
26
- return ((new static )->createSidebar ()->withoutIndex ()->getSidebar ()
26
+ return ((new static )->createSidebar ()->withoutIndex ()->withoutHidden ()-> getSidebar ()
27
27
)->sortItems ()->getCollection ();
28
28
}
29
29
@@ -63,6 +63,18 @@ protected function withoutIndex(): self
63
63
return $ this ;
64
64
}
65
65
66
+ /**
67
+ * Remove hidden files from the sidebar collection.
68
+ */
69
+ protected function withoutHidden (): self
70
+ {
71
+ $ this ->sidebar = $ this ->sidebar ->reject (function (DocumentationSidebarItem $ item ) {
72
+ return $ item ->isHidden ();
73
+ });
74
+
75
+ return $ this ;
76
+ }
77
+
66
78
/**
67
79
* Get an array of source files to add to the sidebar.
68
80
*/
Original file line number Diff line number Diff line change @@ -68,6 +68,15 @@ public function test_index_page_is_removed_from_sidebar()
68
68
$ this ->assertCount (5 , $ sidebar );
69
69
}
70
70
71
+ public function test_files_with_front_matter_hidden_set_to_true_are_removed_from_sidebar ()
72
+ {
73
+ $ this ->createTestFiles ();
74
+ File::put (Hyde::path ('_docs/test.md ' ), "--- \nhidden: true \n--- \n\n# Foo " );
75
+
76
+ $ sidebar = DocumentationSidebarService::get ();
77
+ $ this ->assertCount (5 , $ sidebar );
78
+ }
79
+
71
80
public function test_sidebar_is_ordered_alphabetically_when_no_order_is_set_in_config ()
72
81
{
73
82
Config::set ('hyde.documentationPageOrder ' , []);
You can’t perform that action at this time.
0 commit comments