Skip to content

Commit 4759869

Browse files
committed
redirect: Make the trailing slash optional
1 parent 700db8a commit 4759869

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

hypernode/redirect/generate_nginx_redirects.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ def get_path_for_doc(doc: Path) -> str:
2727
def main():
2828
for doc in get_all_docs():
2929
for redirect in get_redirects_from_doc(doc):
30+
redirect = redirect.rstrip("/")
3031
doc_path = get_path_for_doc(doc)
31-
print("rewrite ^{}$ {} permanent;".format(redirect, doc_path))
32+
print("rewrite ^{}/?$ {} permanent;".format(redirect, doc_path))

tests/redirect/test_generate_nginx_redirects.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
from pathlib import Path
3+
from unittest.mock import call
34

45
from hypernode.common.settings import DOCS_DIR
56
from hypernode.redirect.generate_nginx_redirects import (
@@ -18,16 +19,19 @@ def setUp(self) -> None:
1819
module + "get_all_docs", return_value=[DOCS_DIR / "index.html"]
1920
)
2021
self.get_redirects_from_doc = self.set_up_patch(
21-
module + "get_redirects_from_doc", return_value=["/old-url/"]
22+
module + "get_redirects_from_doc",
23+
return_value=["/old-url/", "/en/another-url"],
2224
)
2325

2426
def test_main_prints_rewrites(self):
2527
main()
2628

27-
expected_output = """
28-
rewrite ^/old-url/$ / permanent;
29-
""".strip()
30-
self.print.assert_called_once_with(expected_output)
29+
self.print.assert_has_calls(
30+
[
31+
call("rewrite ^/old-url/?$ / permanent;"),
32+
call("rewrite ^/en/another-url/?$ / permanent;"),
33+
]
34+
)
3135

3236

3337
class TestGetPathForDoc(HypernodeTestCase):

0 commit comments

Comments
 (0)