Saved page: write a short ?s= link once a list passes ten trails
Up to ten trails the link stays ?t=id,id,... With more it is a version character and a base64url bit set over the trails' permanent numbers (trail-numbers.txt), 70 characters for any list instead of 1,013 for 49 trails. Both forms open for good; ?s= wins when both are there; a retired or unknown number is ignored and a code that cannot be read shows the page's existing no-trails state. A short link does not keep the order saved, so that list opens A to Z. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
358f0c4928
commit
07b023f31b
3 files changed
+288
-12
No files matched your search
+28
-5
@@ -2,8 +2,12 @@
|
||||
|
||||
Saved trails are kept in the visitor's browser only: localStorage, key
|
||||
lh-saved, the trail ids in the order saved (app.js). A link carries a list in
|
||||
its own address, /saved/?t=<id>,<id>,..., so it opens the same list on any
|
||||
device, in any browser, with nothing remembered.
|
||||
its own address, so it opens the same list on any device, in any browser, with
|
||||
nothing remembered. Up to ten trails the link names them, /saved/?t=<id>,<id>,...;
|
||||
with more it is a short code, /saved/?s=<code>, a bit set over the trails' permanent
|
||||
numbers (trail-numbers.txt). The page carries the numbers as data-saved-numbers on
|
||||
its head: the trail ids in number order, "-" for a number whose trail is gone.
|
||||
app.js (SavedCode) writes and reads both forms; docs/schema.md has the format.
|
||||
|
||||
The page is written like every other, so it cannot know the list. It holds
|
||||
every trail's row, hidden (the same rows as the catalogue, about as heavy as
|
||||
@@ -13,7 +17,7 @@ the home page's list; the hidden rows' logos are not fetched), and app.js
|
||||
own list no t= in the address: the visitor's saved trails, the map
|
||||
of them, and the link to them with a Copy link button
|
||||
nothing saved no t=, nothing saved: how to save a trail, and a link to the trails
|
||||
from a link t= in the address: that list, marked as from a link, with
|
||||
from a link t= or s= in the address: that list, marked as from a link, with
|
||||
"Save these" (adds it to the visitor's own) and a way to
|
||||
their own list; ids that match no trail are dropped and
|
||||
counted. A link holding the visitor's own list is shown as theirs.
|
||||
@@ -21,19 +25,38 @@ the home page's list; the hidden rows' logos are not fetched), and app.js
|
||||
Without JavaScript the page says that saved trails need it. It is not
|
||||
indexed (layout noindex) and not in the sitemap (seo.all_paths).
|
||||
"""
|
||||
from . import common, home
|
||||
import os
|
||||
|
||||
from . import common, home, records
|
||||
from .markup import Markup
|
||||
|
||||
NUMBERS_FILE = "trail-numbers.txt"
|
||||
|
||||
PATH = "/saved/"
|
||||
TITLE = "Saved trails"
|
||||
DESCRIPTION = "The trails you saved, kept in this browser, and a link that opens the same list anywhere."
|
||||
|
||||
|
||||
def trail_numbers(ids, root=records.ROOT):
|
||||
"""The page's number list: the ids of the trails that exist, in registry order, one
|
||||
entry per number, with "-" for a number whose trail is gone (retired). The index of an
|
||||
entry is the trail's number. A trail with no line in the registry is left out, and the
|
||||
script then writes the readable link for any list that holds it."""
|
||||
here = set(ids)
|
||||
with open(os.path.join(root, NUMBERS_FILE), encoding="utf-8") as f:
|
||||
lines = [ln.rstrip("\n") for ln in f if ln.strip() and not ln.startswith("#")]
|
||||
out = [ln if ln in here else "-" for ln in lines]
|
||||
while out and out[-1] == "-":
|
||||
out.pop()
|
||||
return out
|
||||
|
||||
|
||||
def saved_page(records, site):
|
||||
"""(title, description, body) for /saved/."""
|
||||
recs = sorted(records, key=home.sort_name)
|
||||
numbers = " ".join(trail_numbers([r["id"] for r in recs]))
|
||||
star = common.ICON_STAR
|
||||
body = f"""<div class="page-head saved-head" data-saved-page>
|
||||
body = f"""<div class="page-head saved-head" data-saved-page data-saved-numbers="{numbers}">
|
||||
<div class="container">
|
||||
<header class="titleblock"><div class="titleblock__text">
|
||||
<h1 data-saved-title>{TITLE}</h1>
|
||||
|
||||
Reference in new issue
Block a user