aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2021-05-09 19:20:53 +0200
committerFlorian Dold <florian@dold.me>2021-05-09 19:20:53 +0200
commitebed74abfc2c3acb1c12df6c5b4453c6da227027 (patch)
tree8d3cb430f5d6336b9c7e80017f66c9684bd21e58
parent9e9363ec2797fcb51f998ce6e388eb9877e8788c (diff)
downloadwww_shared-ebed74abfc2c3acb1c12df6c5b4453c6da227027.tar.gz
www_shared-ebed74abfc2c3acb1c12df6c5b4453c6da227027.zip
check internal links for validity
-rw-r--r--sitegen/site.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/sitegen/site.py b/sitegen/site.py
index 2220eac..1767a2a 100644
--- a/sitegen/site.py
+++ b/sitegen/site.py
@@ -90,8 +90,30 @@ def make_helpers(root, in_file, locale):
90 + str(Path(abs_file).relative_to(root / "template")).rstrip(".j2") 90 + str(Path(abs_file).relative_to(root / "template")).rstrip(".j2")
91 ) 91 )
92 92
93 def url(x): 93 def url(x, virtual=False):
94 abs_file = Path(in_file).resolve() 94 abs_file = Path(in_file).resolve()
95
96 def check_exists():
97 if virtual:
98 return True
99 if Path(root / "static" / x).exists():
100 return True
101 if Path(root / "template" / (x + ".j2")).exists():
102 return True
103 if Path(root / "template" / (x + ".j2")).exists():
104 return True
105 slashpos = x.find("/")
106 if slashpos < 0:
107 return False
108 rest = x[slashpos+1:]
109 # Heuristic search for translated file
110 if Path(root / "template" / (rest + ".j2")).exists():
111 return True
112 return False
113
114 if not check_exists():
115 raise FileNotFoundError("can't find " + x)
116
95 url = "" 117 url = ""
96 current_location = Path(abs_file).relative_to(root / "template") 118 current_location = Path(abs_file).relative_to(root / "template")
97 for p in current_location.parts: 119 for p in current_location.parts: