Skip to content

Commit 9e9d0cc

Browse files
Merge pull request #1 from xentral/static-content-support
static-content-support
2 parents 6c63051 + 836263a commit 9e9d0cc

10 files changed

+3004
-71
lines changed

README.md

Lines changed: 293 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ A Laravel package that automatically generates beautiful documentation from your
99
## Features
1010

1111
- 🔍 **Automated extraction** of functional documentation from PHPDoc comments
12+
- 📄 **Static content support** for including existing markdown files
13+
- 🏗️ **Hierarchical navigation** with parent-child page relationships
14+
- 🔗 **Smart cross-reference linking** with auto-generated titles and bi-directional discovery
1215
- 📚 **MkDocs integration** with Material Design theme
1316
- 🎯 **Selective documentation** using `@functional` annotation
14-
- 🔗 **Dependency tracking** and visualization with Mermaid diagrams
17+
- 📊 **Dependency tracking** and visualization with Mermaid diagrams
1518
- 📱 **Responsive documentation** with navigation and search
1619
- 🐍 **Python dependencies** managed automatically via uv
1720
-**Laravel commands** for easy integration
@@ -60,6 +63,17 @@ return [
6063
// Add other directories to scan
6164
],
6265
'output' => base_path('docs'),
66+
'static_content' => [
67+
'specifications' => [
68+
'path' => base_path('docs/specifications'),
69+
'nav_prefix' => 'Specifications',
70+
],
71+
'guides' => [
72+
'path' => base_path('docs/guides'),
73+
'nav_prefix' => 'Guides',
74+
],
75+
// Add more static content types as needed
76+
],
6377
'commands' => [
6478
'build' => 'uvx -w mkdocs-material -w pymdown-extensions mkdocs build',
6579
'publish' => 'uvx -w mkdocs-material -w pymdown-extensions mkdocs gh-deploy',
@@ -81,30 +95,30 @@ The package uses `uv` (via `uvx`) to automatically manage the Python dependencie
8195

8296
Add the `@functional` annotation to your PHPDoc comments to mark them for extraction:
8397

84-
```php
98+
````php
8599
<?php
86100

87101
namespace App\Services;
88102

89103
/**
90104
* User authentication service
91-
*
105+
*
92106
* @functional
93107
* This service handles all user authentication processes including login,
94108
* logout, password resets, and session management.
95-
*
109+
*
96110
* # Key Features
97111
* - **Secure Login**: Multi-factor authentication support
98112
* - **Session Management**: Automatic session cleanup
99113
* - **Password Security**: Bcrypt hashing with salt
100-
*
114+
*
101115
* ## Usage Example
102-
*
116+
*
103117
* ```php
104118
* $auth = new AuthService();
105119
* $result = $auth->authenticate($credentials);
106120
* ```
107-
*
121+
*
108122
* @nav Authentication / User Service
109123
* @uses \App\Models\User
110124
* @uses \App\Services\EmailService
@@ -114,29 +128,296 @@ class AuthService
114128
{
115129
/**
116130
* Authenticate user credentials
117-
*
131+
*
118132
* @functional
119133
* This method validates user credentials against the database and
120134
* creates a secure session if authentication is successful.
121-
*
135+
*
136+
* This process appears as a child page under the main User Service
137+
* in the navigation, demonstrating hierarchical organization.
138+
*
122139
* @nav Authentication / Login Process
123140
* @uses \App\Models\User
124141
*/
125142
public function authenticate(array $credentials): bool
126143
{
127144
// Implementation...
128145
}
146+
147+
/**
148+
* Multi-factor authentication verification
149+
*
150+
* @functional
151+
* Handles the second factor of authentication using TOTP tokens,
152+
* SMS codes, or backup codes for enhanced security.
153+
*
154+
* This also appears under the User Service section, showing how
155+
* multiple related methods are grouped together.
156+
*
157+
* @nav Authentication / MFA Verification
158+
* @uses \App\Models\User
159+
* @uses \App\Services\TotpService
160+
*/
161+
public function verifyMfaToken(string $token): bool
162+
{
163+
// Implementation...
164+
}
129165
}
130-
```
166+
````
131167

132168
### Available Annotations
133169

134-
- **`@functional`**: Marks the documentation block for extraction (required)
170+
The following annotations work in **both** PHPDoc comments and static markdown files:
171+
172+
##### Navigation Annotations
135173
- **`@nav`**: Sets the navigation path (e.g., "Authentication / User Service")
174+
- **`@navid`**: Sets a unique identifier for referencing this page as a parent
175+
- **`@navparent`**: References a parent page by its `@navid` for explicit hierarchical navigation
176+
177+
##### Content Annotations
136178
- **`@uses`**: Links to dependencies that will be cross-referenced
137179
- **`@link`**: Adds external links to the documentation
138180
- **`@links`**: Alternative syntax for links
139181

182+
##### PHPDoc-Specific Annotations
183+
- **`@functional`**: Marks the documentation block for extraction (required)
184+
185+
> **Note**: Hierarchical navigation works in two ways:
186+
> - **Automatic grouping**: Pages with shared path prefixes in `@nav` paths (like "Authentication / User Service" and "Authentication / Login Process") are automatically grouped under "Authentication"
187+
> - **Explicit parent-child**: Use `@navid` and `@navparent` for explicit parent-child relationships across any content type
188+
189+
### Working with Static Content Files
190+
191+
In addition to PHPDoc comments, you can include existing markdown files in your documentation. This is useful for specifications, guides, tutorials, or any content that exists outside your code.
192+
193+
#### Setting up Static Content
194+
195+
1. **Configure paths** in your `config/docs.php`:
196+
197+
```php
198+
'static_content' => [
199+
'specifications' => [
200+
'path' => base_path('docs/specifications'),
201+
'nav_prefix' => 'Specifications',
202+
],
203+
'guides' => [
204+
'path' => base_path('docs/guides'),
205+
'nav_prefix' => 'User Guides',
206+
],
207+
],
208+
```
209+
210+
2. **Create your markdown files** with cross-references:
211+
212+
```markdown
213+
<!-- docs-content/specifications/api-overview.md -->
214+
@navid api
215+
@nav API / Overview
216+
217+
# API Overview
218+
219+
This document describes our REST API architecture and design principles.
220+
221+
## Related Documentation
222+
223+
- [Authentication Guide](../guides/authentication.md) - Detailed authentication setup
224+
- [API Endpoints Reference](./endpoints/rest-api.md) - Complete endpoint documentation
225+
- [Error Handling](../guides/troubleshooting.md) - Common error scenarios
226+
227+
For implementation examples, see our [Getting Started Guide](../guides/getting-started.md).
228+
```
229+
230+
#### Hierarchical Navigation
231+
232+
Create parent-child relationships between pages:
233+
234+
```markdown
235+
<!-- docs-content/specifications/api-overview.md -->
236+
@navid api
237+
# API Overview
238+
239+
This is the main API documentation page.
240+
241+
Related pages:
242+
- [Authentication Details](../guides/auth-setup.md)
243+
- [Rate Limiting](./rate-limits.md)
244+
```
245+
246+
```markdown
247+
<!-- docs-content/specifications/api-endpoints.md -->
248+
@navparent api
249+
# API Endpoints
250+
251+
This page describes individual endpoints and inherits from the API Overview page.
252+
253+
See also: [Database Schema](../specifications/database.md) for data structure details.
254+
```
255+
256+
#### Features of Static Content
257+
258+
- **Automatic processing**: Files are automatically discovered and processed
259+
- **Flexible navigation**: Use `@nav` to customize navigation paths
260+
- **Hierarchical structure**: Use `@navid` and `@navparent` for parent-child relationships
261+
- **Cross-references**: Use standard markdown links to reference other files
262+
- **YAML frontmatter support**: Standard markdown frontmatter is automatically stripped
263+
- **Title extraction**: Page titles are extracted from the first `# heading` in the file
264+
- **Directory structure**: File organization is preserved in the navigation structure
265+
266+
### Cross-Reference Linking
267+
268+
The package includes a powerful cross-reference linking system that allows you to create links between documentation pages using special syntax. The system automatically generates link text, validates references, and creates bi-directional links.
269+
270+
#### Basic Syntax
271+
272+
There are two ways to create cross-references:
273+
274+
**1. Reference by Class/Owner (`@ref`)**
275+
276+
Use `@ref:` to reference a page by its fully qualified class name or owner identifier:
277+
278+
```markdown
279+
For authentication, see [@ref:App\Services\AuthService].
280+
```
281+
282+
This automatically generates a link with smart title extraction from the target page.
283+
284+
**2. Reference by Navigation ID (`@navid`)**
285+
286+
Use `@navid:` to reference a page by its custom navigation identifier:
287+
288+
```markdown
289+
More details in the [@navid:api] documentation.
290+
```
291+
292+
#### Auto-Generated Titles
293+
294+
The cross-reference system automatically generates meaningful link text using a smart fallback chain:
295+
296+
1. **H1 Title**: First, it extracts the first H1 heading from the target page's content
297+
2. **Navigation Path**: If no H1 is found, it uses the last segment of the `@nav` path
298+
3. **Class Name**: Finally, it falls back to the class name from the owner identifier
299+
300+
**Example:**
301+
302+
```php
303+
/**
304+
* User authentication service
305+
*
306+
* @functional
307+
* This service handles authentication.
308+
*
309+
* # Complete Authentication System
310+
* ...
311+
*
312+
* @nav Services / Auth
313+
*/
314+
class AuthService {}
315+
```
316+
317+
When referenced with `[@ref:App\Services\AuthService]`, the generated link text will be:
318+
- "Complete Authentication System" (from H1 title)
319+
- If no H1: "Auth" (from nav path)
320+
- If no nav path: "AuthService" (from class name)
321+
322+
#### Custom Link Text
323+
324+
You can override the auto-generated title by providing custom link text:
325+
326+
```markdown
327+
See the [authentication setup guide](@ref:App\Services\AuthService).
328+
Read more about [our API](@navid:api).
329+
```
330+
331+
#### Bi-Directional Discovery
332+
333+
The system automatically tracks all cross-references and generates "Referenced by" sections on target pages. This creates bidirectional linking without any manual maintenance.
334+
335+
**Example:**
336+
337+
If you reference `App\Services\AuthService` from multiple pages:
338+
339+
```markdown
340+
<!-- In guards.md -->
341+
The guard system uses [@ref:App\Services\AuthService].
342+
343+
<!-- In middleware.md -->
344+
Middleware delegates to [@ref:App\Services\AuthService].
345+
```
346+
347+
The `AuthService` documentation page will automatically include:
348+
349+
```markdown
350+
## Referenced by
351+
352+
This page is referenced by the following pages:
353+
354+
* [Guards / Authentication Guards](./guards/)
355+
* [Middleware / Auth Middleware](./middleware/)
356+
```
357+
358+
#### Error Handling and Validation
359+
360+
The build process validates all cross-references and **fails with informative errors** if broken references are found:
361+
362+
```
363+
RuntimeException: Broken reference: @ref:App\NonExistent\Class in App\Services\AuthService
364+
```
365+
366+
This ensures your documentation links stay accurate as your codebase evolves.
367+
368+
#### Cross-Referencing Between PHPDoc and Static Content
369+
370+
Cross-references work seamlessly across both PHPDoc comments and static markdown files:
371+
372+
**PHPDoc referencing static content:**
373+
```php
374+
/**
375+
* @functional
376+
* Implementation details in [@navid:api-spec].
377+
*/
378+
class ApiController {}
379+
```
380+
381+
**Static content referencing PHPDoc:**
382+
```markdown
383+
<!-- docs/guides/api-guide.md -->
384+
@navid api-spec
385+
386+
# API Specification
387+
388+
The implementation is in [@ref:App\Controllers\ApiController].
389+
```
390+
391+
#### Best Practices
392+
393+
**When to use `@ref` vs `@navid`:**
394+
395+
- **Use `@ref`** for referencing specific classes, methods, or PHPDoc-documented code
396+
- **Use `@navid`** for referencing conceptual pages, guides, or when you want a stable reference that won't change with refactoring
397+
398+
**Setting up navigation IDs:**
399+
400+
```php
401+
/**
402+
* @functional
403+
* Main authentication service documentation
404+
*
405+
* @navid auth-service // Stable identifier for references
406+
* @nav Services / Authentication
407+
*/
408+
class AuthService {}
409+
```
410+
411+
```markdown
412+
<!-- docs/guides/authentication.md -->
413+
@navid auth-guide
414+
@nav Guides / Authentication Setup
415+
416+
# Authentication Guide
417+
418+
This guide complements the [@navid:auth-service] implementation.
419+
```
420+
140421
### Generate Documentation
141422

142423
Generate your documentation using the Artisan command:
@@ -288,7 +569,7 @@ If you discover any security related issues, please email [email protected]
288569
## Credits
289570

290571
- [Manuel Christlieb](https://github.com/bambamboole)
291-
- [All Contributors](../../contributors)
572+
- [Fabian Koenig](https://github.com/fabian-xentral)
292573

293574
## License
294575

src/Console/Commands/ServeMKDocsCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function handle(): int
3636
if ($errorOutput = trim($process->latestErrorOutput())) {
3737
$this->output->error($errorOutput);
3838
}
39-
sleep(1);
39+
\Illuminate\Support\Sleep::sleep(1);
4040
}
4141
if ($process->running()) {
4242
$process->stop();

0 commit comments

Comments
 (0)