Skip to content

Commit

Permalink
Merge pull request #27 from loic425/feature/fix-redirection
Browse files Browse the repository at this point in the history
Fix redirection
  • Loading branch information
loic425 authored Dec 2, 2020
2 parents b608ff7 + 96bd65a commit 46d8456
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
},
"scripts": {
"analyse": [
"@php vendor/bin/ecs check src"
"@php vendor/bin/ecs check src tests --set symfony"
],
"fix": [
"@php vendor/bin/ecs check src --fix"
"@php vendor/bin/ecs check src tests --set symfony --fix"
]
},
"extra": {
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/MenuAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __invoke(Request $request): Response
$menuItems = [];

foreach ($finder as $file) {
$slug = rtrim($file->getRelativePathName(), '.md');
$slug = preg_replace('/\.md$/', '', $file->getRelativePathName());
$menuItems[] = [
'slug' => $slug,
'path' => $this->generateUrl('mobizel_markdown_docs_page_show', ['slug' => $slug]),
Expand Down
4 changes: 3 additions & 1 deletion src/Controller/PageAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ public function __construct(TemplateHandlerInterface $templateHandler)
public function __invoke(string $slug): Response
{
if (false !== strpos($slug, '.md')) {
return $this->redirectToRoute('mobizel_markdown_docs_page_show', ['slug' => rtrim($slug, '.md')]);
$slug = preg_replace('/\.md$/', '', $slug);

return $this->redirectToRoute('mobizel_markdown_docs_page_show', ['slug' => $slug]);
}

try {
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/views/search/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<h1>Search results for terms "<em>{{ app.request.get('query') }}</em>"</h1>
<ul>
{% for file in files %}
{% set slug = file.relativePathname|trim('.md', 'right') %}
{% set slug = file.relativePathname|split('.md')[0] %}
<li>
<a href="{{ path('mobizel_markdown_docs_page_show', { 'slug': slug }) }}">
{{ page_title(slug) }} [{{ slug }}]
Expand Down
3 changes: 2 additions & 1 deletion tests/Controller/PageActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ public function testRedirection()
{
$client = static::createClient();

$client->request('GET', 'index.md');
$client->request('GET', 'bdd.md');

$this->assertEquals(302, $client->getResponse()->getStatusCode());
$this->assertEquals('/bdd', $client->getResponse()->getTargetUrl());
}

public function testShowPage()
Expand Down
1 change: 1 addition & 0 deletions tests/docs/bdd.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# BDD - Behaviour-driven development

0 comments on commit 46d8456

Please sign in to comment.