Skip to content

Commit 2efe808

Browse files
Generate the documentation list
1 parent 21449d3 commit 2efe808

8 files changed

Lines changed: 99 additions & 4 deletions

File tree

Phakefile.php

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,51 @@ function gen_cmd_pages( $cmd, $parent = array() ) {
209209
file_put_contents( '_includes/internal-api-list.html', $out );
210210
});
211211

212+
desc( 'Update the /docs/ page.' );
213+
task( 'doc-list', function( $app ){
214+
$docs = array(
215+
'Guides' => array(),
216+
'References' => array(),
217+
'Contributing' => array(),
218+
'Misc' => array(),
219+
);
220+
foreach( glob( __DIR__ . '/docs/*/index.md' ) as $file ) {
221+
$contents = file_get_contents( $file );
222+
$parts = explode( '---', $contents );
223+
$header = $parts[1];
224+
preg_match( '#category:\s(.+)#', $header, $matches );
225+
if ( ! empty( $matches[1] ) && array_key_exists( $matches[1], $docs ) ) {
226+
$category = $matches[1];
227+
} else {
228+
$category = 'Misc';
229+
}
230+
preg_match( '#title:\s(.+)#', $header, $matches );
231+
$title = ! empty( $matches[1] ) ? $matches[1] : '';
232+
preg_match( '#description:\s(.+)#', $header, $matches );
233+
$description = ! empty( $matches[1] ) ? $matches[1] : '';
234+
$docs[ $category ][] = array(
235+
'path' => basename( dirname( $file ) ),
236+
'title' => $title,
237+
'description' => $description,
238+
);
239+
}
240+
$out = '';
241+
foreach( $docs as $category => $cat_docs ) {
242+
$out .= '<h3>' . $category . '</h3>' . PHP_EOL . PHP_EOL;
243+
$out .= '<ul>' . PHP_EOL;
244+
foreach( $cat_docs as $cat_doc ) {
245+
$out .= '<li><a href="/docs/' . $cat_doc['path'] . '/"><strong>' . $cat_doc['title'] . '</strong></a>';
246+
if ( ! empty( $cat_doc['description'] ) ) {
247+
$out .= ' - ' . $cat_doc['description'];
248+
}
249+
$out .= '</li>' . PHP_EOL;
250+
}
251+
$out .= '</ul>' . PHP_EOL . PHP_EOL;
252+
}
253+
254+
file_put_contents( '_includes/doc-list.html', $out );
255+
});
256+
212257
desc( 'Build the site.' );
213-
task( 'default', 'cmd-list', 'param-list', 'internal-api-list' );
258+
task( 'default', 'cmd-list', 'param-list', 'internal-api-list', 'doc-list' );
214259

_includes/doc-list.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<h3>Guides</h3>
2+
3+
<ul>
4+
<li><a href="/docs/installing/"><strong>Installing</strong></a> - Recommended and alternative installation mechanisms.</li>
5+
</ul>
6+
7+
<h3>References</h3>
8+
9+
<ul>
10+
<li><a href="/docs/internal-api/"><strong>Internal API</strong></a> - Stable utilities considered safe to use in community commands.</li>
11+
</ul>
12+
13+
<h3>Contributing</h3>
14+
15+
<ul>
16+
</ul>
17+
18+
<h3>Misc</h3>
19+
20+
<ul>
21+
</ul>
22+

_includes/header.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<link rel="alternate" type="application/atom+xml" href="/atom.xml" title="Atom Feed">
1313

1414
<title>{{ page.title }} | WP-CLI</title>
15+
<meta name="description" content="{{ page.description }}">
1516
</head>
1617

1718
{% if page.display_global_parameters %}

_layouts/doc.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{% include header.html %}
2+
3+
{% capture page_url %}{{ page.url | remove:'index.html' }}{% endcapture %}
4+
{% if page_url != '/docs/' %}
5+
<a href="/docs/">Docs</a> &raquo; {{ page.category }}
6+
{% endif %}
7+
8+
{{ content }}
9+
10+
{% include footer.html %}

_templates/internal-api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ layout: default
33
title: {{full_name}}()
44
---
55

6-
<a href="/docs/internal-api/">Internal API</a> &raquo; {{category}}
6+
<a href="/docs/">Docs</a> &raquo; <a href="/docs/internal-api/">Internal API</a> &raquo; {{category}}
77

88
## {{full_name}}()
99

docs/index.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
layout: doc
3+
title: Documentation
4+
description: Helpful guides and resources for using WP-CLI.
5+
---
6+
7+
## Documentation
8+
9+
Here are some helpful guides and resources for using WP-CLI.
10+
11+
Can't find what you're looking for? [Open an issue](https://github.com/wp-cli/wp-cli/issues) to request improvements.
12+
13+
{% include doc-list.html %}

docs/installing/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
2-
layout: default
2+
layout: doc
33
title: Installing
4+
category: Guides
5+
description: Recommended and alternative installation mechanisms.
46
---
57

68
## Recommended Installation

docs/internal-api/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
2-
layout: default
2+
layout: doc
33
title: Internal API
4+
category: References
5+
description: Stable utilities considered safe to use in community commands.
46
---
57

68
## Internal API

0 commit comments

Comments
 (0)