Add 130 views of the same records, speed up map pages, and say who maintains the site
- New pages built from the records: lists by length, time to walk, month, kind of walking and holder; place-by-list pages; a Triple Crown table and key-figure tables for the National Scenic and Recreation Trails; highest points, most climbing and climb per mile; a page for every route author, with the authors of three or more routes leading the authors page; connected trails; recently added and changed; a glossary and a method page. Every place page opens with a summary. - Trail pages open with an "In brief" paragraph generated from the record and show when the record was last checked. The About page says who maintains the site and how to reach them. - The map starts when it is reached, not with the page. The site's own CSS, scripts and fonts are fingerprinted and cached for a year. Every image has its dimensions. - Titles are held to 60 characters and share previews get their own shorter description. - Social cards are redrawn so a long name can no longer push text into the footer, and the site-wide card takes its wording from the site settings instead of an old hand-made image. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
5b80fccd1e
commit
f2d3b71810
266 files changed
+4658
-252
No files matched your search
@@ -53,14 +53,24 @@ def repository_png_logos():
|
||||
return found
|
||||
|
||||
|
||||
def repository_logos():
|
||||
"""{id: path} for each logo with a thumbnail: <id>/shield.png, or <id>/shield.svg where there is no PNG."""
|
||||
found = dict(repository_png_logos())
|
||||
for name in os.listdir(ROOT):
|
||||
path = os.path.join(ROOT, name, "shield.svg")
|
||||
if not name.startswith((".", "_")) and name not in found and os.path.isfile(path):
|
||||
found[name] = path
|
||||
return found
|
||||
|
||||
|
||||
def build():
|
||||
subprocess.run([sys.executable, os.path.join(WEB, "build.py"), "--out", OUT],
|
||||
check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
|
||||
|
||||
class ThumbFilesTest(unittest.TestCase):
|
||||
def test_every_repository_png_logo_has_a_thumbnail_no_larger_than_256(self):
|
||||
logos = repository_png_logos()
|
||||
def test_every_repository_logo_has_a_thumbnail_no_larger_than_256(self):
|
||||
logos = repository_logos()
|
||||
self.assertTrue(logos)
|
||||
for tid in logos:
|
||||
thumb = os.path.join(WEB, "thumbs", f"{tid}.png")
|
||||
@@ -71,7 +81,7 @@ class ThumbFilesTest(unittest.TestCase):
|
||||
self.assertGreater(min(w, h), 0, tid)
|
||||
|
||||
def test_no_thumbnail_without_a_source(self):
|
||||
logos = repository_png_logos()
|
||||
logos = repository_logos()
|
||||
thumbs_dir = os.path.join(WEB, "thumbs")
|
||||
for name in os.listdir(thumbs_dir):
|
||||
self.assertIn(name[:-len(".png")], logos, f"orphan thumbnail {name}")
|
||||
@@ -96,8 +106,39 @@ class ThumbFilesTest(unittest.TestCase):
|
||||
self.assertEqual((logo["width"], logo["height"]), thumbs.png_size(src))
|
||||
self.assertFalse(os.path.exists(os.path.join(out, "trails", tid, thumbs.THUMB_NAME)))
|
||||
|
||||
def test_svg_logo_gets_no_thumbnail(self):
|
||||
rec = {"id": "x", "derived": {"files": {"shield": "x/shield.svg"}, "logo_img": {"src": "stale"}}}
|
||||
def test_svg_logo_gets_a_thumbnail_like_a_png_one(self):
|
||||
tid = "x"
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
repo, out, made = (os.path.join(tmp, n) for n in ("repo", "out", "thumbs"))
|
||||
for d in (os.path.join(repo, tid), os.path.join(out, "trails", tid), made):
|
||||
os.makedirs(d)
|
||||
with open(os.path.join(repo, tid, "shield.svg"), "w", encoding="utf-8") as f:
|
||||
f.write('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 170 92"></svg>')
|
||||
shutil.copyfile(repository_png_logos()["cohos"], os.path.join(made, f"{tid}.png"))
|
||||
rec = {"id": tid, "derived": {"files": {"shield": f"{tid}/shield.svg"}, "logo_img": {"src": "stale"}}}
|
||||
thumbs.prepare(rec, out, repo, thumb_dir=made)
|
||||
logo = rec["derived"]["logo_img"]
|
||||
self.assertEqual(logo["src"], f"/trails/{tid}/{thumbs.THUMB_NAME}")
|
||||
self.assertEqual((logo["width"], logo["height"]), thumbs.png_size(os.path.join(made, f"{tid}.png")))
|
||||
self.assertTrue(os.path.isfile(os.path.join(out, "trails", tid, thumbs.THUMB_NAME)))
|
||||
|
||||
def test_svg_logo_with_no_thumbnail_falls_back_to_the_svg_with_its_own_shape(self):
|
||||
tid = "x"
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
repo, out, empty = (os.path.join(tmp, n) for n in ("repo", "out", "thumbs"))
|
||||
for d in (os.path.join(repo, tid), os.path.join(out, "trails", tid), empty):
|
||||
os.makedirs(d)
|
||||
with open(os.path.join(repo, tid, "shield.svg"), "w", encoding="utf-8") as f:
|
||||
f.write('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 170 92"></svg>')
|
||||
rec = {"id": tid, "derived": {"files": {"shield": f"{tid}/shield.svg"}}}
|
||||
err = io.StringIO()
|
||||
with contextlib.redirect_stderr(err):
|
||||
thumbs.prepare(rec, out, repo, thumb_dir=empty)
|
||||
self.assertEqual(err.getvalue().count("warning"), 1)
|
||||
self.assertEqual(rec["derived"]["logo_img"], {"src": f"/trails/{tid}/shield.svg", "width": 256, "height": 139})
|
||||
|
||||
def test_a_logo_of_another_type_gets_no_thumbnail(self):
|
||||
rec = {"id": "x", "derived": {"files": {"shield": "x/shield.gif"}, "logo_img": {"src": "stale"}}}
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
thumbs.prepare(rec, tmp, tmp, thumb_dir=tmp)
|
||||
self.assertNotIn("logo_img", rec["derived"])
|
||||
|
||||
Reference in new issue
Block a user