Skip to content

Commit e0c58c8

Browse files
committed
Group packages in generated index page.
This patch updates the component list preparation script to sort packages by their `group` attribute, and use that sorting to list groups of packages.
1 parent e765f90 commit e0c58c8

File tree

2 files changed

+63
-22
lines changed

2 files changed

+63
-22
lines changed

docs/book/index.html.dist

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
<div class="jumbotron">
2-
<h1>Zend Framework Components</h1>
2+
<h1>Zend Framework Documentation</h1>
33

4-
<p>Documentation for the ZF components</p>
5-
</div>
6-
7-
<div class="panel panel-info">
8-
<div class="panel-heading">Tutorials</div>
9-
10-
<div class="panel-body">
11-
Learn Zend Framework and Expressive in-depth via our <a href="/tutorials">tutorials</a>.
12-
</div>
4+
<p>Documentation for the MVC Framework, Expressive, and all Components</p>
135
</div>
146

docs/scripts/prepare_component_list.php

Lines changed: 61 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php
22

33
const TEMPLATE = <<< 'EOT'
4-
<h2>Components</h2>
4+
<h2>%group%</h2>
5+
56
<div class="components">
67
%components%
78
</div>
@@ -34,18 +35,66 @@
3435
$json = file_get_contents($listFile);
3536
$packages = json_decode($json, true);
3637

37-
$componentMarkup = [];
38-
foreach ($packages as $package) {
39-
// @codingStandardsIgnoreStart
40-
$componentMarkup []= str_replace(
41-
[ '%href%', '%name%', '%package%', '%description%'],
42-
[$package['url'], $package['name'], $package['package'], $package['description']],
43-
PACKAGE_TEMPLATE
44-
);
45-
}
46-
$componentMarkup = implode("\n\n", $componentMarkup);
38+
// Group packages by type
39+
$packagesByType = [
40+
'learn' => [
41+
'title' => 'Learn ZF',
42+
'packages' => [],
43+
],
44+
'mvc' => [
45+
'title' => 'MVC Framework',
46+
'packages' => [],
47+
],
48+
'middleware' => [
49+
'title' => 'Expressive and PSR-15 Middleware',
50+
'packages' => [],
51+
],
52+
'projects' => [
53+
'title' => 'Tooling and Composer Plugins',
54+
'packages' => [],
55+
],
56+
'components' => [
57+
'title' => 'Components',
58+
'packages' => [],
59+
],
60+
];
61+
62+
$types = array_keys($packagesByType);
63+
64+
// Sort packages into various groups, generating markup for each as we do.
65+
$packagesByType = array_reduce(
66+
$packages,
67+
function ($grouped, $package) use ($types) {
68+
if (! isset($package['group']) || ! in_array($package['group'], $types, true)) {
69+
$package['group'] = 'components';
70+
}
71+
72+
$grouped[$package['group']]['packages'][] = str_replace(
73+
[ '%href%', '%name%', '%package%', '%description%'],
74+
[$package['url'], $package['name'], $package['package'], $package['description']],
75+
PACKAGE_TEMPLATE
76+
);
77+
78+
return $grouped;
79+
},
80+
$packagesByType
81+
);
82+
83+
// Generate per-group markup
84+
$markup = array_reduce(
85+
$packagesByType,
86+
function ($markup, $group) {
87+
$markup []= str_replace(
88+
[ '%group%', '%components%'],
89+
[$group['title'], implode("\n\n", $group['packages'])],
90+
TEMPLATE
91+
);
92+
return $markup;
93+
},
94+
[]
95+
);
4796

48-
$markup = str_replace('%components%', $componentMarkup, TEMPLATE);
97+
$markup = implode("\n\n", $markup);
4998

5099
copy($distPath, $indexPath);
51100
$fh = fopen($indexPath, 'a');

0 commit comments

Comments
 (0)