From: Lady Date: Sat, 16 Dec 2023 01:47:58 +0000 (-0500) Subject: Support lookup by identifier X-Git-Tag: 0.3.1^0 X-Git-Url: https://git.ladys.computer/x_status_git/commitdiff_plain/6b8de961c3f0e23435afe54d072951d9dd007f79?ds=inline;hp=760145cc6cea91fe442ac247c0d947b455320276 Support lookup by identifier --- diff --git a/Caddyfile b/Caddyfile index 5b8aca5..a430aae 100644 --- a/Caddyfile +++ b/Caddyfile @@ -29,6 +29,20 @@ status.site.example { header Link ;rel=alternate;type="application/atom+xml" } + @iri { + path_regexp matcher ^/(?P[^/:]+:[^/]+)/?$ + } + + handle @iri { + handle @bare { + rewrite * /.lookup.xhtml + } + + handle @slash { + redir * /{re.matcher.iri} + } + } + handle /about { rewrite * /.about.html header Link ;rel=meta;type="application/ld+json" diff --git a/README.markdown b/README.markdown index a03f40a..0d7d027 100644 --- a/README.markdown +++ b/README.markdown @@ -130,6 +130,16 @@ Note that these paths **do not** have a trailing slash. `;rel=meta;type="application/ld+json"` (or equivalent) **must** be provided. +### X·H·T·M·L responses + +These responses **must** be served with a `Content-Type` of + `application/xhtml+xml` (or equivalent). +Note that these paths **do not** have a trailing slash. + + + **`GET /$IRI`** (where `$IRI` contains a colon and no slash): + Serve the file at `/.lookup.xhtml`. + This can be used to look up statuses by their identifier. + ### Json‐L·D responses These responses **should** be served with a `Content-Type` of diff --git a/post-receive b/post-receive index f6289da..d273055 100755 --- a/post-receive +++ b/post-receive @@ -38,6 +38,7 @@ if stdin.read().split()[-1] == f"refs/heads/{LIVE_BRANCH}": cloneresult.check_returncode() # Set up various containers. + irimap = {} months = {} topics = {} @@ -99,6 +100,7 @@ if stdin.read().split()[-1] == f"refs/heads/{LIVE_BRANCH}": status["@id"] = f"{PUBLIC_URL}/topics/{topic}/{identifier}" if topic else f"{PUBLIC_URL}/statuses/{datetime[0:7]}/{identifier}" with identifier_path.open("r", encoding="utf-8") as text: status["identifier"] = text.read().strip() + irimap[status["identifier"]] = status["@id"] else: warn(f"Missing identifier for {path}; skipping.") return None @@ -251,5 +253,21 @@ if stdin.read().split()[-1] == f"refs/heads/{LIVE_BRANCH}": with open(f"{PUBLIC_DIRECTORY}/topics/index.jsonld", "w", encoding="utf-8") as f: json.dump({ "@context": { "@language": LANG, "activity": "https://www.w3.org/ns/activitystreams#", "dct": "http://purl.org/dc/terms/", "sioc": "http://rdfs.org/sioc/ns#", "Collection": "activity:Collection", "Forum": "sioc:Forum", "items": { "@id": "activity:items", "@type": "@id" }, "has_parent": { "@id": "sioc:has_parent", "@type": "id" }, "subject": "dct:subject" }, "@id": f"{PUBLIC_URL}/topics", "@type": ["Collection", "Forum"], "items": list(map(lambda a: { "@id": a["@id"], "subject": a["subject"] }, topics.values())), "has_parent": f"{PUBLIC_URL}" }, f, ensure_ascii=False, allow_nan=False) + # Output the I·R·I redirection page + with open(f"{PUBLIC_DIRECTORY}/.lookup.xhtml", "w", encoding="utf-8") as f: + doc = getDOMImplementation().createDocument(None, "xml", None) + htmlElt = doc.documentElement + htmlElt.setAttribute("xmlns", XHTML_NAMESPACE) + htmlElt.setAttribute("lang", LANG) + headElt = htmlElt.appendChild(doc.createElement("head")) + titleElt = headElt.appendChild(doc.createElement("title")) + titleElt.appendChild(doc.createTextNode("Redirecting…")) + scriptElt = headElt.appendChild(doc.createElement("script")) + scriptElt.setAttribute("type", "text/javascript") + scriptElt.appendChild(doc.createTextNode(f"location={json.dumps(irimap)}[location.pathname.substring(1)]??`/`")) + bodyElt = htmlElt.appendChild(doc.createElement("body")) + bodyElt.appendChild(doc.createTextNode("Attempting to redirect to the proper page… (Requires Javascript.)")) + f.write(doc.toxml()) + # Remove the build directory. rmtree(BUILD_DIRECTORY)