Skip to content

Commit e1bc23a

Browse files
authored
Removed .md suffix from documentation urls (#1277)
1 parent dc8ead1 commit e1bc23a

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

web/landing/src/Flow/Website/Service/Documentation/Pages.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public function all() : array
3434
continue;
3535
}
3636

37+
$relativePath = str_replace('.md', '', $relativePath);
38+
3739
$pages[] = new Page($relativePath, \file_get_contents($file->path->path()));
3840
}
3941

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Flow\Website\Service\Markdown;
6+
7+
use League\CommonMark\Extension\CommonMark\Node\Inline\Link;
8+
use League\CommonMark\Node\Node;
9+
use League\CommonMark\Renderer\{ChildNodeRendererInterface, NodeRendererInterface};
10+
use League\CommonMark\Util\HtmlElement;
11+
12+
class FlowLinkRenderer implements NodeRendererInterface
13+
{
14+
public function render(Node $node, ChildNodeRendererInterface $childRenderer)
15+
{
16+
if (!$node instanceof Link) {
17+
throw new \InvalidArgumentException('Incompatible node type: ' . $node::class);
18+
}
19+
20+
$attrs = $node->data->get('attributes');
21+
22+
$urlParts = parse_url($node->getUrl());
23+
24+
if (!isset($urlParts['scheme']) && !isset($urlParts['host'])) {
25+
$node->setUrl(str_replace('.md', '', $node->getUrl()));
26+
}
27+
28+
$attrs['href'] = $node->getUrl();
29+
30+
if ($node->getTitle()) {
31+
$attrs['title'] = $node->getTitle();
32+
}
33+
34+
return new HtmlElement('a', $attrs, $childRenderer->renderNodes($node->children()));
35+
}
36+
}

web/landing/src/Flow/Website/Service/Markdown/LeagueCommonMarkConverterFactory.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use League\CommonMark\CommonMarkConverter;
88
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
99
use League\CommonMark\Extension\CommonMark\Node\Block\FencedCode;
10+
use League\CommonMark\Extension\CommonMark\Node\Inline\Link;
1011
use League\CommonMark\Extension\ExternalLink\ExternalLinkExtension;
1112

1213
final class LeagueCommonMarkConverterFactory
@@ -24,7 +25,8 @@ public function __invoke() : CommonMarkConverter
2425

2526
$converter->getEnvironment()
2627
->addExtension(new ExternalLinkExtension())
27-
->addRenderer(FencedCode::class, new FlowCodeRenderer(), 0);
28+
->addRenderer(FencedCode::class, new FlowCodeRenderer(), 0)
29+
->addRenderer(Link::class, new FlowLinkRenderer(), 0);
2830
// $converter->getEnvironment()->addExtension(new CommonMarkCoreExtension());
2931
// foreach ($this->extensions as $extension) {
3032
// $converter->getEnvironment()->addRenderer(new FlowCodeRenderer());

0 commit comments

Comments
 (0)