]> Lady’s Gitweb - x_status_git/blobdiff - post-receive
Use titles in prev & next links on statuses
[x_status_git] / post-receive
index f6289dabf8303c50e5aa0b5fe0705f42e6bed47b..b07ad47ddfd28b92fae4bd8b7f0caaa58323404b 100755 (executable)
@@ -38,6 +38,7 @@ if stdin.read().split()[-1] == f"refs/heads/{LIVE_BRANCH}":
        cloneresult.check_returncode()
 
        # Set up various containers.
        cloneresult.check_returncode()
 
        # Set up various containers.
+       irimap = {}
        months = {}
        topics = {}
 
        months = {}
        topics = {}
 
@@ -67,23 +68,23 @@ if stdin.read().split()[-1] == f"refs/heads/{LIVE_BRANCH}":
        # The provided path must be to a `text` object.
        def statusmap (topic, path):
                status = { "@type": "MicroblogPost" }
        # The provided path must be to a `text` object.
        def statusmap (topic, path):
                status = { "@type": "MicroblogPost" }
-               version_path = next(path.parent.glob("0=*"))
+               version_path = next(path.parent.glob("0=*"), None)
                if version_path and version_path.name != "0=x_status_git_1.0":
                        warn(f"Unrecognized version for {path}; skipping.")
                        return None
                if topic:
                        status["subject"] = topic
                if version_path and version_path.name != "0=x_status_git_1.0":
                        warn(f"Unrecognized version for {path}; skipping.")
                        return None
                if topic:
                        status["subject"] = topic
-               author_path = next(path.parent.glob("1=*"))
+               author_path = next(path.parent.glob("1=*"), None)
                if author_path:
                if author_path:
-                       status["author"] = { "name": author_path.name[2:] }
+                       status["creator"] = { "name": author_path.name[2:] }
                        with author_path.open("r", encoding="utf-8") as text:
                        with author_path.open("r", encoding="utf-8") as text:
-                               status["author"]["@id"] = text.read().strip()
-               title_path = next(path.parent.glob("2=*"))
+                               status["creator"]["@id"] = text.read().strip()
+               title_path = next(path.parent.glob("2=*"), None)
                if title_path:
                        with title_path.open("r", encoding="utf-8") as text:
                                title = text.read().strip()
                                status["title"] = title
                if title_path:
                        with title_path.open("r", encoding="utf-8") as text:
                                title = text.read().strip()
                                status["title"] = title
-               date_path = next(path.parent.glob("3=*"))
+               date_path = next(path.parent.glob("3=*"), None)
                datetime = ""
                if date_path:
                        with date_path.open("r", encoding="utf-8") as text:
                datetime = ""
                if date_path:
                        with date_path.open("r", encoding="utf-8") as text:
@@ -92,18 +93,21 @@ if stdin.read().split()[-1] == f"refs/heads/{LIVE_BRANCH}":
                else:
                        warn(f"Missing date for {path}; skipping.")
                        return None
                else:
                        warn(f"Missing date for {path}; skipping.")
                        return None
-               identifier_path = next(path.parent.glob("4=*"))
+               identifier_path = next(path.parent.glob("4=*"), None)
                identifier = ""
                if identifier_path:
                        identifier = identifier_path.name[2:]
                        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()
                identifier = ""
                if identifier_path:
                        identifier = identifier_path.name[2:]
                        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
                with path.open("r", encoding="utf-8") as text:
                else:
                        warn(f"Missing identifier for {path}; skipping.")
                        return None
                with path.open("r", encoding="utf-8") as text:
-                       status["content"] = statusxml(text.read().strip())
+                       source = text.read().strip()
+                       status["content"] = statusxml(source)
+                       status["source"] = { "content": source, "mediaType": "text/plain" }
                return (datetime, identifier, status)
 
        def atomForLD (ld):
                return (datetime, identifier, status)
 
        def atomForLD (ld):
@@ -141,7 +145,11 @@ if stdin.read().split()[-1] == f"refs/heads/{LIVE_BRANCH}":
                        linkElt.setAttribute("href", href)
                for item in ld["items"]:
                        entryElt = atomElt.appendChild(doc.createElement("entry"))
                        linkElt.setAttribute("href", href)
                for item in ld["items"]:
                        entryElt = atomElt.appendChild(doc.createElement("entry"))
-                       title = item["title"] if "title" in item else item["content"][0:27] + "…"
+                       title = item["source"]["content"].partition("\n")[0]
+                       if "title" in item:
+                               title = item["title"]
+                       elif len(title) >= 28:
+                               title = title[0:27] + "…"
                        titleElt = entryElt.appendChild(doc.createElement("title"))
                        titleElt.appendChild(doc.createTextNode(title))
                        idElt = entryElt.appendChild(doc.createElement("id"))
                        titleElt = entryElt.appendChild(doc.createElement("title"))
                        titleElt.appendChild(doc.createTextNode(title))
                        idElt = entryElt.appendChild(doc.createElement("id"))
@@ -152,11 +160,11 @@ if stdin.read().split()[-1] == f"refs/heads/{LIVE_BRANCH}":
                                publishedElt = entryElt.appendChild(doc.createElement("published"))
                                publishedElt.appendChild(doc.createTextNode(item["created"]))
                        authorElt = entryElt.appendChild(doc.createElement("author"))
                                publishedElt = entryElt.appendChild(doc.createElement("published"))
                                publishedElt.appendChild(doc.createTextNode(item["created"]))
                        authorElt = entryElt.appendChild(doc.createElement("author"))
-                       if "author" in item:
+                       if "creator" in item:
                                nameElt = authorElt.appendChild(doc.createElement("name"))
                                nameElt = authorElt.appendChild(doc.createElement("name"))
-                               nameElt.appendChild(doc.createTextNode(item["author"]["name"]))
+                               nameElt.appendChild(doc.createTextNode(item["creator"]["name"]))
                                uriElt = authorElt.appendChild(doc.createElement("uri"))
                                uriElt = authorElt.appendChild(doc.createElement("uri"))
-                               uriElt.appendChild(doc.createTextNode(item["author"]["@id"]))
+                               uriElt.appendChild(doc.createTextNode(item["creator"]["@id"]))
                        else:
                                nameElt = authorElt.appendChild(doc.createElement("name"))
                                nameElt.appendChild(doc.createTextNode("Anonymous"))
                        else:
                                nameElt = authorElt.appendChild(doc.createElement("name"))
                                nameElt.appendChild(doc.createTextNode("Anonymous"))
@@ -189,12 +197,12 @@ if stdin.read().split()[-1] == f"refs/heads/{LIVE_BRANCH}":
                if "subject" in status:
                        topic = status["subject"]
                        if topic not in topics:
                if "subject" in status:
                        topic = status["subject"]
                        if topic not in topics:
-                               topics[topic] = { "@context": { "@language": LANG, "activity": "https://www.w3.org/ns/activitystreams#", "dct": "http://purl.org/dc/terms/", "foaf": "http://xmlns.com/foaf/0.1/", "sioc": "http://rdfs.org/sioc/ns#", "sioct": "http://rdfs.org/sioc/types#", "OrderedCollection": "activity:OrderedCollection", "Thread": "sioc:Thread", "MicroblogPost": "sioct:MicroblogPost", "items": { "@id": "activity:items", "@type": "@id", "@container": "@list" }, "created": { "@id": "dct:created", "@type": "http://www.w3.org/2001/XMLSchema#dateTime" }, "creator": { "@id": "dct:creator", "@type": "@id" }, "identifier": { "@id":  "dct:identifier", "@type": "http://www.w3.org/2001/XMLSchema#anyURI" }, "subject": "dct:subject", "name": "foaf:name", "title": "dct:title", "content": { "@id": "sioc:content", "@type": "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral" } }, "@id": f"{PUBLIC_URL}/topics/{topic}", "@type": ["OrderedCollection", "Thread"], "items": [], "subject": topic }
+                               topics[topic] = { "@context": { "@language": LANG, "activity": "https://www.w3.org/ns/activitystreams#", "dct": "http://purl.org/dc/terms/", "foaf": "http://xmlns.com/foaf/0.1/", "sioc": "http://rdfs.org/sioc/ns#", "sioct": "http://rdfs.org/sioc/types#", "OrderedCollection": "activity:OrderedCollection", "Thread": "sioc:Thread", "MicroblogPost": "sioct:MicroblogPost", "items": { "@id": "activity:items", "@type": "@id", "@container": "@list" }, "source": { "@id": "activity:source", "@type": "@id", "@context": { "content": { "@id": "activity:content", "@type": "http://www.w3.org/2001/XMLSchema#string" }, "mediaType": "activity:mediaType" } }, "created": { "@id": "dct:created", "@type": "http://www.w3.org/2001/XMLSchema#dateTime" }, "creator": { "@id": "dct:creator", "@type": "@id" }, "identifier": { "@id":  "dct:identifier", "@type": "http://www.w3.org/2001/XMLSchema#anyURI" }, "subject": "dct:subject", "title": "dct:title", "name": "foaf:name", "content": { "@id": "sioc:content", "@type": "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral" }, "feed": { "@id": "sioc:feed", "@type": "@id" } }, "@id": f"{PUBLIC_URL}/topics/{topic}", "@type": ["OrderedCollection", "Thread"], "feed": f"{PUBLIC_URL}/topics/{topic}.atom", "items": [], "subject": topic }
                        topics[topic]["items"].append(status)
                else:
                        yyyy_mm = datetime[0:7]
                        if yyyy_mm not in months:
                        topics[topic]["items"].append(status)
                else:
                        yyyy_mm = datetime[0:7]
                        if yyyy_mm not in months:
-                               months[yyyy_mm] = { "@context": { "@language": LANG, "activity": "https://www.w3.org/ns/activitystreams#", "dct": "http://purl.org/dc/terms/", "foaf": "http://xmlns.com/foaf/0.1/", "sioc": "http://rdfs.org/sioc/ns#", "sioct": "http://rdfs.org/sioc/types#", "OrderedCollectionPage": "activity:OrderedCollectionPage", "Thread": "sioc:Thread", "MicroblogPost": "sioct:MicroblogPost", "current": { "@id": "activity:current", "@type": "@id" }, "first": { "@id": "activity:first", "@type": "@id" }, "items": { "@id": "activity:items", "@type": "@id", "@container": "@list" }, "partOf": { "@id": "activity:partOf", "@type": "@id" }, "prev": { "@id": "activity:prev", "@type": "@id" }, "next": { "@id": "activity:next", "@type": "@id" }, "created": { "@id": "dct:created", "@type": "http://www.w3.org/2001/XMLSchema#dateTime" }, "creator": { "@id": "dct:creator", "@type": "@id" }, "identifier": { "@id":  "dct:identifier", "@type": "http://www.w3.org/2001/XMLSchema#anyURI" }, "name": "foaf:name", "title": "dct:title", "content": { "@id": "sioc:content", "@type": "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral" } }, "@id": f"{PUBLIC_URL}/statuses/{yyyy_mm}", "@type": ["OrderedCollectionPage", "Thread"], "items": [], "partOf": f"{PUBLIC_URL}/statuses" }
+                               months[yyyy_mm] = { "@context": { "@language": LANG, "activity": "https://www.w3.org/ns/activitystreams#", "dct": "http://purl.org/dc/terms/", "foaf": "http://xmlns.com/foaf/0.1/", "sioc": "http://rdfs.org/sioc/ns#", "sioct": "http://rdfs.org/sioc/types#", "OrderedCollectionPage": "activity:OrderedCollectionPage", "Thread": "sioc:Thread", "MicroblogPost": "sioct:MicroblogPost", "current": { "@id": "activity:current", "@type": "@id" }, "first": { "@id": "activity:first", "@type": "@id" }, "items": { "@id": "activity:items", "@type": "@id", "@container": "@list" }, "partOf": { "@id": "activity:partOf", "@type": "@id" }, "prev": { "@id": "activity:prev", "@type": "@id" }, "next": { "@id": "activity:next", "@type": "@id" }, "source": { "@id": "activity:source", "@type": "@id", "@context": { "content": { "@id": "activity:content", "@type": "http://www.w3.org/2001/XMLSchema#string" }, "mediaType": "activity:mediaType" } }, "created": { "@id": "dct:created", "@type": "http://www.w3.org/2001/XMLSchema#dateTime" }, "creator": { "@id": "dct:creator", "@type": "@id" }, "identifier": { "@id":  "dct:identifier", "@type": "http://www.w3.org/2001/XMLSchema#anyURI" }, "title": "dct:title", "name": "foaf:name", "content": { "@id": "sioc:content", "@type": "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral" } }, "@id": f"{PUBLIC_URL}/statuses/{yyyy_mm}", "@type": ["OrderedCollectionPage", "Thread"], "feed": f"{PUBLIC_URL}/statuses.atom", "items": [], "partOf": f"{PUBLIC_URL}/statuses" }
                        months[yyyy_mm]["items"].append(status)
 
        # Set up the public directory.
                        months[yyyy_mm]["items"].append(status)
 
        # Set up the public directory.
@@ -235,7 +243,7 @@ if stdin.read().split()[-1] == f"refs/heads/{LIVE_BRANCH}":
                with open(f"{PUBLIC_DIRECTORY}/{atomlink[len(PUBLIC_URL):-5]}/index.atom", "w", encoding="utf-8") as f:
                        f.write(atomxml)
        with open(f"{PUBLIC_DIRECTORY}/statuses/index.jsonld", "w", encoding="utf-8") as f:
                with open(f"{PUBLIC_DIRECTORY}/{atomlink[len(PUBLIC_URL):-5]}/index.atom", "w", encoding="utf-8") as f:
                        f.write(atomxml)
        with open(f"{PUBLIC_DIRECTORY}/statuses/index.jsonld", "w", encoding="utf-8") as f:
-               json.dump({ "@context": { "@language": LANG, "activity": "https://www.w3.org/ns/activitystreams#", "sioc": "http://rdfs.org/sioc/ns#", "OrderedCollection": "activity:OrderedCollection", "Thread": "sioc:Thread", "current": { "@id": "activity:current", "@type": "@id" }, "first": { "@id": "activity:first", "@type": "@id" }, "has_parent": { "@id": "sioc:has_parent", "@type": "id" } }, "@id": f"{PUBLIC_URL}/statuses", "@type": ["OrderedCollection", "Thread"], "first": f"{PUBLIC_URL}/statuses/{statuspairs[0][1][0]}", "current": f"{PUBLIC_URL}/statuses/{statuspairs[-1][1][0]}", "has_parent": f"{PUBLIC_URL}" }, f, ensure_ascii=False, allow_nan=False)
+               json.dump({ "@context": { "@language": LANG, "activity": "https://www.w3.org/ns/activitystreams#", "sioc": "http://rdfs.org/sioc/ns#", "OrderedCollection": "activity:OrderedCollection", "Thread": "sioc:Thread", "current": { "@id": "activity:current", "@type": "@id" }, "first": { "@id": "activity:first", "@type": "@id" }, "has_parent": { "@id": "sioc:has_parent", "@type": "@id" }, "feed": { "@id": "sioc:feed", "@type": "@id" } }, "@id": f"{PUBLIC_URL}/statuses", "@type": ["OrderedCollection", "Thread"], "feed": f"{PUBLIC_URL}/statuses.atom", "first": f"{PUBLIC_URL}/statuses/{statuspairs[0][1][0]}", "current": f"{PUBLIC_URL}/statuses/{statuspairs[-1][1][0]}", "has_parent": f"{PUBLIC_URL}" }, f, ensure_ascii=False, allow_nan=False)
 
        # Output topic‐based listings and the topic index
        if not exists(f"{PUBLIC_DIRECTORY}/topics"):
 
        # Output topic‐based listings and the topic index
        if not exists(f"{PUBLIC_DIRECTORY}/topics"):
@@ -249,7 +257,23 @@ if stdin.read().split()[-1] == f"refs/heads/{LIVE_BRANCH}":
                with open(f"{PUBLIC_DIRECTORY}/{atomlink[len(PUBLIC_URL):-5]}/index.atom", "w", encoding="utf-8") as f:
                        f.write(atomxml)
        with open(f"{PUBLIC_DIRECTORY}/topics/index.jsonld", "w", encoding="utf-8") as f:
                with open(f"{PUBLIC_DIRECTORY}/{atomlink[len(PUBLIC_URL):-5]}/index.atom", "w", encoding="utf-8") as f:
                        f.write(atomxml)
        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)
+               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)
 
        # Remove the build directory.
        rmtree(BUILD_DIRECTORY)
This page took 0.029701 seconds and 4 git commands to generate.