Skip to content

Commit a037ab1

Browse files
committed
Use consistent naming for heading identifiers
1 parent cd66953 commit a037ab1

File tree

3 files changed

+51
-51
lines changed

3 files changed

+51
-51
lines changed

packages/framework/resources/views/components/docs/table-of-contents.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<ul class="{{ ! $isChild ? 'table-of-contents pb-3' : 'pl-2' }}">
55
@foreach($items as $item)
66
<li class="my-0.5">
7-
<a href="#{{ $item['slug'] }}" class="-ml-8 pl-8 opacity-80 hover:opacity-100 hover:bg-gray-200/20 transition-all duration-300">
7+
<a href="#{{ $item['identifier'] }}" class="-ml-8 pl-8 opacity-80 hover:opacity-100 hover:bg-gray-200/20 transition-all duration-300">
88
<span class="text-[75%] opacity-50 hover:opacity-100 transition-opacity duration-300">#</span>
99
{{ $item['title'] }}
1010
</a>

packages/framework/src/Framework/Actions/GeneratesTableOfContents.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ public function __construct(Markdown|string $markdown)
2727
}
2828

2929
/**
30-
* @return array<int, array{title: string, slug: string, children: array}>
30+
* @return array<int, array{title: string, identifier: string, children: array}>
3131
*/
3232
public function execute(): array
3333
{
3434
return $this->buildTableOfContents($this->parseHeadings());
3535
}
3636

3737
/**
38-
* @return array<int, array{level: int, title: string, slug: string}>
38+
* @return array<int, array{level: int, title: string, identifier: string}>
3939
*/
4040
protected function parseHeadings(): array
4141
{
@@ -110,20 +110,20 @@ protected function parseSetextHeading(string $title, string $marker): ?array
110110

111111
/**
112112
* @param array{level: int, title: string} $headingData
113-
* @return array{level: int, title: string, slug: string}
113+
* @return array{level: int, title: string, identifier: string}
114114
*/
115115
protected function createHeadingEntry(array $headingData): array
116116
{
117117
return [
118118
'level' => $headingData['level'],
119119
'title' => $headingData['title'],
120-
'slug' => HeadingRenderer::makeIdentifier($headingData['title']),
120+
'identifier' => HeadingRenderer::makeIdentifier($headingData['title']),
121121
];
122122
}
123123

124124
/**
125-
* @param array<int, array{level: int, title: string, slug: string}> $headings
126-
* @return array<int, array{title: string, slug: string, children: array}>
125+
* @param array<int, array{level: int, title: string, identifier: string}> $headings
126+
* @return array<int, array{title: string, identifier: string, children: array}>
127127
*/
128128
protected function buildTableOfContents(array $headings): array
129129
{
@@ -145,7 +145,7 @@ protected function buildTableOfContents(array $headings): array
145145
}
146146

147147
/**
148-
* @param array{level: int, title: string, slug: string} $heading
148+
* @param array{level: int, title: string, identifier: string} $heading
149149
*/
150150
protected function isHeadingWithinBounds(array $heading): bool
151151
{
@@ -154,20 +154,20 @@ protected function isHeadingWithinBounds(array $heading): bool
154154
}
155155

156156
/**
157-
* @param array{level: int, title: string, slug: string} $heading
158-
* @return array{title: string, slug: string, children: array}
157+
* @param array{level: int, title: string, identifier: string} $heading
158+
* @return array{title: string, identifier: string, children: array}
159159
*/
160160
protected function createTableItem(array $heading): array
161161
{
162162
return [
163163
'title' => $heading['title'],
164-
'slug' => $heading['slug'],
164+
'identifier' => $heading['identifier'],
165165
'children' => [],
166166
];
167167
}
168168

169169
/**
170-
* @param array<int, array<int, array{title: string, slug: string, children: array}>> $stack
170+
* @param array<int, array<int, array{title: string, identifier: string, children: array}>> $stack
171171
*/
172172
protected function updateStackForHeadingLevel(array &$stack, int $currentLevel, int $previousLevel): void
173173
{
@@ -181,7 +181,7 @@ protected function updateStackForHeadingLevel(array &$stack, int $currentLevel,
181181
}
182182

183183
/**
184-
* @param array<int, array<int, array{title: string, slug: string, children: array}>> $stack
184+
* @param array<int, array<int, array{title: string, identifier: string, children: array}>> $stack
185185
*/
186186
protected function nestNewLevel(array &$stack): void
187187
{
@@ -192,7 +192,7 @@ protected function nestNewLevel(array &$stack): void
192192
}
193193

194194
/**
195-
* @param array<int, array<int, array{title: string, slug: string, children: array}>> $stack
195+
* @param array<int, array<int, array{title: string, identifier: string, children: array}>> $stack
196196
*/
197197
protected function unwindStack(array &$stack, int $currentLevel): void
198198
{

packages/framework/tests/Unit/GeneratesSidebarTableOfContentsTest.php

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ public function testCanGenerateTableOfContents()
2626
$this->assertSame([
2727
[
2828
'title' => 'Level 2',
29-
'slug' => 'level-2',
29+
'identifier' => 'level-2',
3030
'children' => [],
3131
],
3232
[
3333
'title' => 'Level 2B',
34-
'slug' => 'level-2b',
34+
'identifier' => 'level-2b',
3535
'children' => [
3636
[
3737
'title' => 'Level 3',
38-
'slug' => 'level-3',
38+
'identifier' => 'level-3',
3939
'children' => [],
4040
],
4141
],
@@ -56,11 +56,11 @@ public function testReturnStringContainsExpectedContent()
5656
$this->assertSame([
5757
[
5858
'title' => 'Level 2',
59-
'slug' => 'level-2',
59+
'identifier' => 'level-2',
6060
'children' => [
6161
[
6262
'title' => 'Level 3',
63-
'slug' => 'level-3',
63+
'identifier' => 'level-3',
6464
'children' => [],
6565
],
6666
],
@@ -94,12 +94,12 @@ public function testCanGenerateTableOfContentsForDocumentUsingSetextHeaders()
9494
[
9595
[
9696
'title' => 'Level 2',
97-
'slug' => 'level-2',
97+
'identifier' => 'level-2',
9898
'children' => [],
9999
],
100100
[
101101
'title' => 'Level 2B',
102-
'slug' => 'level-2b',
102+
'identifier' => 'level-2b',
103103
'children' => [],
104104
],
105105
],
@@ -133,11 +133,11 @@ public function testNonHeadingMarkdownIsIgnored()
133133
[
134134
[
135135
'title' => 'Level 2',
136-
'slug' => 'level-2',
136+
'identifier' => 'level-2',
137137
'children' => [
138138
[
139139
'title' => 'Level 3',
140-
'slug' => 'level-3',
140+
'identifier' => 'level-3',
141141
'children' => [],
142142
],
143143
],
@@ -159,11 +159,11 @@ public function testWithNoLevelOneHeading()
159159
$this->assertSame([
160160
[
161161
'title' => 'Level 2',
162-
'slug' => 'level-2',
162+
'identifier' => 'level-2',
163163
'children' => [
164164
[
165165
'title' => 'Level 3',
166-
'slug' => 'level-3',
166+
'identifier' => 'level-3',
167167
'children' => [],
168168
],
169169
],
@@ -193,15 +193,15 @@ public function testWithMultipleNestedHeadings()
193193
$this->assertSame([
194194
[
195195
'title' => 'Level 2',
196-
'slug' => 'level-2',
196+
'identifier' => 'level-2',
197197
'children' => [
198198
[
199199
'title' => 'Level 3',
200-
'slug' => 'level-3',
200+
'identifier' => 'level-3',
201201
'children' => [
202202
[
203203
'title' => 'Level 4',
204-
'slug' => 'level-4',
204+
'identifier' => 'level-4',
205205
'children' => [],
206206
],
207207
],
@@ -210,27 +210,27 @@ public function testWithMultipleNestedHeadings()
210210
],
211211
[
212212
'title' => 'Level 2B',
213-
'slug' => 'level-2b',
213+
'identifier' => 'level-2b',
214214
'children' => [
215215
[
216216
'title' => 'Level 3B',
217-
'slug' => 'level-3b',
217+
'identifier' => 'level-3b',
218218
'children' => [],
219219
],
220220
[
221221
'title' => 'Level 3C',
222-
'slug' => 'level-3c',
222+
'identifier' => 'level-3c',
223223
'children' => [],
224224
],
225225
],
226226
],
227227
[
228228
'title' => 'Level 2C',
229-
'slug' => 'level-2c',
229+
'identifier' => 'level-2c',
230230
'children' => [
231231
[
232232
'title' => 'Level 3D',
233-
'slug' => 'level-3d',
233+
'identifier' => 'level-3d',
234234
'children' => [],
235235
],
236236
],
@@ -254,22 +254,22 @@ public function testWithMultipleLevelOneHeadings()
254254
$this->assertSame([
255255
[
256256
'title' => 'Level 2',
257-
'slug' => 'level-2',
257+
'identifier' => 'level-2',
258258
'children' => [
259259
[
260260
'title' => 'Level 3',
261-
'slug' => 'level-3',
261+
'identifier' => 'level-3',
262262
'children' => [],
263263
],
264264
],
265265
],
266266
[
267267
'title' => 'Level 2B',
268-
'slug' => 'level-2b',
268+
'identifier' => 'level-2b',
269269
'children' => [
270270
[
271271
'title' => 'Level 3B',
272-
'slug' => 'level-3b',
272+
'identifier' => 'level-3b',
273273
'children' => [],
274274
],
275275
],
@@ -305,11 +305,11 @@ public function testRespectsMinHeadingLevelConfig()
305305
$this->assertSame([
306306
[
307307
'title' => 'Level 3',
308-
'slug' => 'level-3',
308+
'identifier' => 'level-3',
309309
'children' => [
310310
[
311311
'title' => 'Level 4',
312-
'slug' => 'level-4',
312+
'identifier' => 'level-4',
313313
'children' => [],
314314
],
315315
],
@@ -335,7 +335,7 @@ public function testRespectsMaxHeadingLevelConfig()
335335
$this->assertSame([
336336
[
337337
'title' => 'Level 2',
338-
'slug' => 'level-2',
338+
'identifier' => 'level-2',
339339
'children' => [],
340340
],
341341
], $result);
@@ -361,11 +361,11 @@ public function testRespectsMinAndMaxHeadingLevelConfig()
361361
$this->assertSame([
362362
[
363363
'title' => 'Level 2',
364-
'slug' => 'level-2',
364+
'identifier' => 'level-2',
365365
'children' => [
366366
[
367367
'title' => 'Level 3',
368-
'slug' => 'level-3',
368+
'identifier' => 'level-3',
369369
'children' => [],
370370
],
371371
],
@@ -394,27 +394,27 @@ public function testWithAllHeadingLevels()
394394
$this->assertSame([
395395
[
396396
'title' => 'Level 1',
397-
'slug' => 'level-1',
397+
'identifier' => 'level-1',
398398
'children' => [
399399
[
400400
'title' => 'Level 2',
401-
'slug' => 'level-2',
401+
'identifier' => 'level-2',
402402
'children' => [
403403
[
404404
'title' => 'Level 3',
405-
'slug' => 'level-3',
405+
'identifier' => 'level-3',
406406
'children' => [
407407
[
408408
'title' => 'Level 4',
409-
'slug' => 'level-4',
409+
'identifier' => 'level-4',
410410
'children' => [
411411
[
412412
'title' => 'Level 5',
413-
'slug' => 'level-5',
413+
'identifier' => 'level-5',
414414
'children' => [
415415
[
416416
'title' => 'Level 6',
417-
'slug' => 'level-6',
417+
'identifier' => 'level-6',
418418
'children' => [],
419419
],
420420
],
@@ -478,11 +478,11 @@ public function testSetextHeadersWithDifferentConfigLevels()
478478
$this->assertSame([
479479
[
480480
'title' => 'Level 1',
481-
'slug' => 'level-1',
481+
'identifier' => 'level-1',
482482
'children' => [
483483
[
484484
'title' => 'Level 2',
485-
'slug' => 'level-2',
485+
'identifier' => 'level-2',
486486
'children' => [],
487487
],
488488
],
@@ -516,7 +516,7 @@ public function testEmptyRangeConfig()
516516
$this->assertSame([
517517
[
518518
'title' => 'Level 2',
519-
'slug' => 'level-2',
519+
'identifier' => 'level-2',
520520
'children' => [],
521521
],
522522
], $result);

0 commit comments

Comments
 (0)