diff --git a/pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs/manual.py b/pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs/manual.py index aae5232e4d9e2..0b88c246446c5 100644 --- a/pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs/manual.py +++ b/pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs/manual.py @@ -321,7 +321,7 @@ def _file_header(self, toc: TocEntry) -> str: for style in self._html_params.stylesheets)), "".join((f'' for script in self._html_params.scripts)), - f'', + f'', f' ', f' ' if home.target.href() else "", f' {up_link}{prev_link}{next_link}', diff --git a/pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs/redirects.py b/pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs/redirects.py index 1a45d9495acdb..5c35172fda97e 100644 --- a/pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs/redirects.py +++ b/pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs/redirects.py @@ -106,7 +106,10 @@ def get_client_redirects(self, redirection_target: str): if path != redirection_target: continue client_redirects[anchor] = f"{locations[0]}#{identifier}" + return client_redirects + def get_redirect_script(self, redirection_target: str) -> str: + client_redirects = self.get_client_redirects(redirection_target) return self._redirects_script.replace('REDIRECTS_PLACEHOLDER', json.dumps(client_redirects)) diff --git a/pkgs/tools/nix/nixos-render-docs/src/tests/test_redirects.py b/pkgs/tools/nix/nixos-render-docs/src/tests/test_redirects.py index 20aab596c33c1..4c7802f80a2dc 100644 --- a/pkgs/tools/nix/nixos-render-docs/src/tests/test_redirects.py +++ b/pkgs/tools/nix/nixos-render-docs/src/tests/test_redirects.py @@ -180,11 +180,8 @@ def test_client_path_with_server_redirect(self): class TestGetClientRedirects(unittest.TestCase): def test_no_client_redirects(self): """Test fetching client side redirects and ignore server-side ones.""" - redirects = Redirects( - {"foo": ["index.html"], "bar": ["index.html", "foo.html"]}, - "const redirects = REDIRECTS_PLACEHOLDER;", - ) - self.assertEqual(redirects.get_client_redirects("index.html"), "const redirects = {};") + redirects = Redirects({"foo": ["index.html"], "bar": ["index.html", "foo.html"]}, "") + self.assertEqual(redirects.get_client_redirects("index.html"), {}) def test_basic_redirect_matching(self): redirects = Redirects( @@ -192,13 +189,12 @@ def test_basic_redirect_matching(self): 'foo': ['index.html', 'index.html#some-section', 'index.html#another-section'], 'bar': ['index.html'], }, - "const redirects = REDIRECTS_PLACEHOLDER;", + "", ) - result = redirects.get_client_redirects("index.html") + client_redirects = redirects.get_client_redirects("index.html") expected_redirects = {'some-section': 'index.html#foo', 'another-section': 'index.html#foo'} - expected_script = f"const redirects = {json.dumps(expected_redirects)};" - self.assertEqual(result, expected_script) + self.assertEqual(client_redirects, expected_redirects) def test_advanced_redirect_matching(self): redirects = Redirects( @@ -206,16 +202,14 @@ def test_advanced_redirect_matching(self): 'foo': ['foo.html', 'foo.html#some-section', 'bar.html#foo'], 'bar': ['bar.html', 'bar.html#another-section'], }, - "const redirects = REDIRECTS_PLACEHOLDER;", + "", ) - self.assertEqual(redirects.get_client_redirects("index.html"), "const redirects = {};") + self.assertEqual(redirects.get_client_redirects("index.html"), {}) - result = redirects.get_client_redirects("foo.html") + client_redirects = redirects.get_client_redirects("foo.html") expected_redirects = {'some-section': 'foo.html#foo'} - expected_script = f"const redirects = {json.dumps(expected_redirects)};" - self.assertEqual(result, expected_script) + self.assertEqual(client_redirects, expected_redirects) - result = redirects.get_client_redirects("bar.html") + client_redirects = redirects.get_client_redirects("bar.html") expected_redirects = {'foo': 'foo.html#foo', 'another-section': 'bar.html#bar'} - expected_script = f"const redirects = {json.dumps(expected_redirects)};" - self.assertEqual(result, expected_script) + self.assertEqual(client_redirects, expected_redirects)