Skip to content

Commit 6d4f70f

Browse files
committed
Merge branch 'main' into update-home
2 parents 12b7444 + 879bc5d commit 6d4f70f

File tree

12 files changed

+77
-22
lines changed

12 files changed

+77
-22
lines changed

src/Markdown/HeadingRenderer.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@
44

55
use InvalidArgumentException;
66
use League\CommonMark\Extension\CommonMark\Node\Block\Heading;
7-
use League\CommonMark\Extension\CommonMark\Node\Inline\Code;
8-
use League\CommonMark\Extension\HeadingPermalink\HeadingPermalink;
9-
use League\CommonMark\Node\Inline\Text;
107
use League\CommonMark\Node\Node;
118
use League\CommonMark\Renderer\ChildNodeRendererInterface;
129
use League\CommonMark\Renderer\NodeRendererInterface;
1310
use League\CommonMark\Util\HtmlElement;
14-
use Tempest\Highlight\Highlighter;
1511
use Tempest\Support\Str\ImmutableString;
1612

1713
final class HeadingRenderer implements NodeRendererInterface

src/Markdown/LinkRenderer.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
namespace App\Markdown;
4+
5+
use InvalidArgumentException;
6+
use League\CommonMark\Extension\CommonMark\Node\Inline\Link;
7+
use League\CommonMark\Extension\CommonMark\Renderer\Inline\LinkRenderer as InlineLinkRenderer;
8+
use League\CommonMark\Node\Node;
9+
use League\CommonMark\Renderer\ChildNodeRendererInterface;
10+
use League\CommonMark\Renderer\NodeRendererInterface;
11+
use League\CommonMark\Xml\XmlNodeRendererInterface;
12+
use League\Config\ConfigurationAwareInterface;
13+
use League\Config\ConfigurationInterface;
14+
use Tempest\Support\Regex;
15+
16+
final class LinkRenderer implements NodeRendererInterface, XmlNodeRendererInterface, ConfigurationAwareInterface
17+
{
18+
private ConfigurationInterface $config;
19+
20+
public function render(Node $node, ChildNodeRendererInterface $childRenderer): \Stringable
21+
{
22+
if (! ($node instanceof Link)) {
23+
throw new InvalidArgumentException('Node must be instance of ' . Link::class);
24+
}
25+
26+
// Replace .md at the end, before a / or a #
27+
$node->setUrl(
28+
Regex\replace($node->getUrl(), '/\.md((?=[\/#?])|$)/', '')
29+
);
30+
31+
$renderer = new InlineLinkRenderer;
32+
$renderer->setConfiguration($this->config);
33+
34+
return $renderer->render($node, $childRenderer);
35+
}
36+
37+
public function setConfiguration(ConfigurationInterface $configuration): void
38+
{
39+
$this->config = $configuration;
40+
}
41+
42+
public function getXmlTagName(Node $node): string
43+
{
44+
return 'link';
45+
}
46+
47+
public function getXmlAttributes(Node $node): array
48+
{
49+
if (! ($node instanceof Link)) {
50+
throw new InvalidArgumentException('Node must be instance of ' . Link::class);
51+
}
52+
53+
return [
54+
'destination' => $node->getUrl(),
55+
'title' => $node->getTitle() ?? '',
56+
];
57+
}
58+
}

src/Markdown/MarkdownInitializer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
use App\Markdown\Symbols\AttributeParser;
1010
use App\Markdown\Symbols\FqcnParser;
1111
use League\CommonMark\Environment\Environment;
12+
use League\CommonMark\Extension\Attributes\AttributesExtension;
1213
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
1314
use League\CommonMark\Extension\CommonMark\Node\Block\FencedCode;
1415
use League\CommonMark\Extension\CommonMark\Node\Block\Heading;
1516
use League\CommonMark\Extension\CommonMark\Node\Inline\Code;
17+
use League\CommonMark\Extension\CommonMark\Node\Inline\Link;
1618
use League\CommonMark\Extension\FrontMatter\FrontMatterExtension;
1719
use League\CommonMark\MarkdownConverter;
1820
use Tempest\Container\Container;
@@ -32,13 +34,15 @@ public function initialize(Container $container): MarkdownConverter
3234
$environment
3335
->addExtension(new CommonMarkCoreExtension())
3436
->addExtension(new FrontMatterExtension())
37+
->addExtension(new AttributesExtension())
3538
->addExtension(new AlertExtension())
3639
->addInlineParser(new TempestPackageParser())
3740
->addInlineParser(new FqcnParser())
3841
->addInlineParser(new AttributeParser())
3942
->addInlineParser(new HandleParser())
4043
->addRenderer(FencedCode::class, new CodeBlockRenderer($highlighter))
4144
->addRenderer(Code::class, new InlineCodeBlockRenderer($highlighter))
45+
->addRenderer(Link::class, new LinkRenderer())
4246
->addRenderer(Heading::class, new HeadingRenderer());
4347

4448
return new MarkdownConverter($environment);

src/Web/Blog/BlogController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App\Web\Meta\MetaType;
66
use DateTimeImmutable;
77
use Tempest\Cache\Cache;
8+
use Tempest\DateTime\DateTime;
89
use Tempest\Http\Response;
910
use Tempest\Http\Responses\NotFound;
1011
use Tempest\Http\Responses\Ok;
@@ -47,7 +48,7 @@ public function rss(
4748
$xml = $cache->resolve(
4849
key: 'rss',
4950
cache: fn () => $this->renderRssFeed($repository->all(loadContent: true)),
50-
expiresAt: new DateTimeImmutable('+1 hour'),
51+
expiresAt: DateTime::now()->plusHours(1),
5152
);
5253

5354
return new Ok($xml)

src/Web/Documentation/RedirectMiddleware.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ public function __invoke(Request $request, HttpMiddlewareCallable $next): Respon
4949
return new Redirect($path->replace("/{$matched->params['version']}/", "/{$version->value}/"));
5050
}
5151

52-
// Redirect to docs index if not found
53-
if ($response instanceof NotFound) {
54-
return new Redirect(uri([ChapterController::class, 'index']));
55-
}
56-
5752
return $response;
5853
}
5954
}

src/Web/Documentation/content/main/0-getting-started/00-introduction.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ final readonly class BookController
3737
}
3838
```
3939

40-
The above snippet is an example of a controller controller. It features [attribute-based routes](../1-framework/03-controllers), mapping a request to a data object using the [mapper](../1-framework/11-mapper), [URL generation](../1-framework/03-controllers#generating-uris) and [dependency injection](../1-framework/02-the-container#autowired-dependencies).
40+
The above snippet is an example of a controller controller. It features [attribute-based routes](../1-essentials/02-controllers), mapping a request to a data object using the [mapper](../2-tempest-in-depth/01-mapper), [URL generation](../1-essentials/02-controllers#generating-uris) and [dependency injection](../1-essentials/01-container#autowired-dependencies).
4141

4242
```php
4343
use Tempest\Console\Console;
@@ -83,12 +83,12 @@ final readonly class MigrateUpCommand
8383
}
8484
```
8585

86-
This is a [console command](../2-console/02-building-console-commands). Console commands can be defined in any class, as long as the `#[ConsoleCommand]` attribute is used on a method. Command arguments are defined as the method's arguments, effectively removing the need to learn some specific framework syntax.
86+
This is a [console command](../3-console/02-building-console-commands). Console commands can be defined in any class, as long as the `#[ConsoleCommand]` attribute is used on a method. Command arguments are defined as the method's arguments, effectively removing the need to learn some specific framework syntax.
8787

88-
This example also shows how to [register events globally](../1-framework/07-events) using the `#[EventHandler]`.
88+
This example also shows how to [register events globally](../2-tempest-in-depth/03-events) using the `#[EventHandler]`.
8989

9090
---
9191

9292
:::info Ready to give it a try?
93-
Keep on reading and consider [**giving Tempest a star️ on GitHub**](https://github.com/tempestphp/tempest-framework). If you want to be part of the community, you can [**join our Discord server**](https://discord.gg/pPhpTGUMPQ), and if you feel like contributing, you can check out our [contributing guide](/docs/internals/contributing)!
93+
Keep on reading and consider [**giving Tempest a star️ on GitHub**](https://github.com/tempestphp/tempest-framework). If you want to be part of the community, you can [**join our Discord server**](https://discord.gg/pPhpTGUMPQ), and if you feel like contributing, you can check out our [contributing guide](/docs/extra-topics/contributing)!
9494
:::

src/Web/Documentation/content/main/0-getting-started/01-getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Tempest won't impose any file structure on you: one of its core features is that
7373
For instance, Tempest is able to differentiate between a controller method and a console command by looking at the code, instead of relying on naming conventions or configuration files.
7474

7575
:::info
76-
This concept is called [discovery](../3-internals/02-discovery), and is one of Tempest's most powerful features.
76+
This concept is called [discovery](../4-internals/02-discovery), and is one of Tempest's most powerful features.
7777
:::
7878

7979
### Examples

src/Web/Documentation/content/main/1-essentials/02-controllers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ final readonly class JsonController
479479

480480
### Post-processing responses
481481

482-
There are some situations in which you may need to act on a response right before it is sent to the client. For instance, you may want to display custom error error pages when an exception occurred, or redirect somewhere instead of displaying the [built-in HTTP 404](/hello-from-the-void) page.
482+
There are some situations in which you may need to act on a response right before it is sent to the client. For instance, you may want to display custom error error pages when an exception occurred, or redirect somewhere instead of displaying the [built-in HTTP 404](/hello-from-the-void){:ssg-ignore="true"} page.
483483

484484
This may be done using a response processor. Similar to [view processors](./03-views#pre-processing-views), they are classes that implement the {`Tempest\Response\ResponseProcessor`} interface. In the `process()` method, you may mutate and return the response object:
485485

src/Web/Documentation/content/main/2-tempest-in-depth/02-validation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Validation
33
---
44

5-
Validation with Tempest is done by taking an array of raw input data, and validating whether that array of data is valid against a class. While validation and [data mapping](/main/framework/validation) often work together, the two are separate components and can also be used separately.
5+
Validation with Tempest is done by taking an array of raw input data, and validating whether that array of data is valid against a class. While validation and [data mapping](./01-mapper) often work together, the two are separate components and can also be used separately.
66

77
Here's an object that can be validated:
88

@@ -51,13 +51,13 @@ final class Book
5151

5252
#[NotEmpty]
5353
public string $description;
54-
54+
5555
#[DateTimeFormat('Y-m-d')]
5656
public ?DateTimeImmutable $publishedAt = null;
5757
}
5858
```
5959

60-
A list of all available validation rules can be found on [GitHub](https://github.com/tempestphp/tempest-framework/tree/main/src/Tempest/Validation/src/Rules).
60+
A list of all available validation rules can be found on [GitHub](https://github.com/tempestphp/tempest-framework/tree/main/src/Tempest/Validation/src/Rules).
6161

6262
## Skipping Validation
6363

src/Web/Documentation/content/main/5-highlight/01-getting-started.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ The gutter will show additions and deletions, and can start at any given line nu
8484
}
8585
```
8686

87-
Finally, you can enable gutter rendering on the fly if you're using [commonmark code blocks](#commonmark-integration) by appending <code>{startAt}</code> to the language definition:
87+
Finally, you can enable gutter rendering on the fly if you're using [commonmark code blocks](#common-mark-integration) by appending <code>{startAt}</code> to the language definition:
8888

8989
<pre>
9090
&#96;&#96;&#96;php{10}
@@ -194,7 +194,7 @@ Within inline Markdown code tags, you can specify the language by prepending it
194194
&#96;{php}public function before(TokenType $tokenType): string&#96;
195195
</pre>
196196

197-
You'll need to set up [commonmark](#commonmark-integration) properly to get this to work.
197+
You'll need to set up [commonmark](#common-mark-integration) properly to get this to work.
198198

199199
## CommonMark integration
200200

0 commit comments

Comments
 (0)