Skip to content

Commit 3378157

Browse files
authored
Support comments in the redirects file (#29)
1 parent 703d601 commit 3378157

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Sphinx Extension to redirect files
77
![Rediraffe](assets/rediraffe_logo.svg)
88

99
This sphinx extension redirects non-existent pages to working pages.
10-
Additionally, a builder is provided to check that deleted/renamed files in your git repo are redirected.
10+
Additionally, a builder is provided to check that deleted/renamed files in your git repo are redirected.
1111

1212
Rediraffe supports the html and dirhtml builders.
1313

@@ -69,6 +69,7 @@ rediraffe_redirects = "redirects.txt"
6969

7070
redirects.txt:
7171
```
72+
# comments start with "#"
7273
"another file.rst" index.rst
7374
another2.rst 'another file.rst'
7475
```

sphinxext/rediraffe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def create_graph(path: Path) -> Dict[str, str]:
5252
with open(path, "r") as file:
5353
for line_num, line in enumerate(file):
5454
line = line.strip()
55-
if len(line) == 0:
55+
if len(line) == 0 or line.startswith("#"):
5656
continue
5757
match = RE_OBJ.fullmatch(line)
5858

tests/test_create_graph.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,24 @@ def test_both_single_quotes(self, tmp_path):
113113
"d": "e",
114114
}
115115

116+
def test_commented(self, tmp_path):
117+
path = tmp_path / "rediraffe.txt"
118+
path.write_text(
119+
"""
120+
# a comment
121+
a b
122+
c d
123+
# another comment
124+
d e
125+
"""
126+
)
127+
graph = create_graph(path)
128+
assert graph == {
129+
"a": "b",
130+
"c": "d",
131+
"d": "e",
132+
}
133+
116134
def test_double_quotes(self, tmp_path):
117135
path = tmp_path / "rediraffe.txt"
118136
path.write_text(

0 commit comments

Comments
 (0)