]> Lady’s Gitweb - x_status_git/blobdiff - post-receive
Fail on git clone error
[x_status_git] / post-receive
index 1b20aa89ef699edbe43aa9708e273f9e188c7d11..17a8d227d298970e66e597183367cd5e0d4ba0e5 100755 (executable)
@@ -27,7 +27,10 @@ if stdin.read().split()[-1] == f"refs/heads/{LIVE_BRANCH}":
        # Set up the build directory.
        if exists(BUILD_DIRECTORY):
                rmtree(BUILD_DIRECTORY)
-       run(["git", "clone", "--local", "--branch", "live", GIT_DIRECTORY, BUILD_DIRECTORY], capture_output=True, encoding="utf-8")
+       cloneresult = run(["git", "clone", "--local", "--branch", LIVE_BRANCH, GIT_DIRECTORY, BUILD_DIRECTORY], capture_output=True, encoding="utf-8")
+       # if cloneresult.stderr:
+               # print(cloneresult.stderr)
+       cloneresult.check_returncode()
 
        # Set up various containers.
        months = {}
@@ -58,7 +61,7 @@ if stdin.read().split()[-1] == f"refs/heads/{LIVE_BRANCH}":
        #
        # The provided path must be to a `text` object.
        def statusmap (topic, path):
-               status = { }
+               status = { "@type": "MicroblogPost" }
                version_path = next(path.parent.glob("0=*"))
                if version_path and version_path.name != "0=x_status_git_1.0":
                        warn(f"Unrecognized version for {path}; skipping.")
@@ -70,6 +73,11 @@ if stdin.read().split()[-1] == f"refs/heads/{LIVE_BRANCH}":
                        status["author"] = { "name": author_path.name[2:] }
                        with author_path.open("r", encoding="utf-8") as text:
                                status["author"]["@id"] = text.read().strip()
+               title_path = next(path.parent.glob("2=*"))
+               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=*"))
                datetime = ""
                if date_path:
@@ -83,7 +91,7 @@ if stdin.read().split()[-1] == f"refs/heads/{LIVE_BRANCH}":
                identifier = ""
                if identifier_path:
                        identifier = identifier_path.name[2:]
-                       status["@id"] = f"{PUBLIC_URL}/topics/{topic}/{identifier}" if topic else f"{PUBLIC_URL}/{datetime[0:7]}/{identifier}"
+                       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()
                else:
@@ -113,12 +121,12 @@ if stdin.read().split()[-1] == f"refs/heads/{LIVE_BRANCH}":
                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#", "OrderedCollection": "activity:OrderedCollection", "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", "content": { "@id": "sioc:content", "@type": "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral" } }, "@id": f"{PUBLIC_URL}/topics/{topic}", "@type": "OrderedCollection", "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" }, "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]["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#", "OrderedCollectionPage": "activity:OrderedCollectionPage", "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", "content": { "@id": "sioc:content", "@type": "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral" } }, "@id": f"{PUBLIC_URL}/{yyyy_mm}", "@type": "OrderedCollectionPage", "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" }, "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]["items"].append(status)
 
        # Set up the public directory.
@@ -128,28 +136,35 @@ if stdin.read().split()[-1] == f"refs/heads/{LIVE_BRANCH}":
 
        # Copy H·T·M·L files to their expected locations.
        copy2(f"{BUILD_DIRECTORY}/index.html", f"{PUBLIC_DIRECTORY}/index.html")
+       copy2(f"{BUILD_DIRECTORY}/about.html", f"{PUBLIC_DIRECTORY}/.about.html")
        copy2(f"{BUILD_DIRECTORY}/status.html", f"{PUBLIC_DIRECTORY}/.status.html")
        copy2(f"{BUILD_DIRECTORY}/statuses.html", f"{PUBLIC_DIRECTORY}/.statuses.html")
        copy2(f"{BUILD_DIRECTORY}/topic.html", f"{PUBLIC_DIRECTORY}/.topic.html")
        copy2(f"{BUILD_DIRECTORY}/topics.html", f"{PUBLIC_DIRECTORY}/.topics.html")
 
+       # Output “about” metadata
+       if not exists(f"{PUBLIC_DIRECTORY}/about"):
+               mkdir(f"{PUBLIC_DIRECTORY}/about")
+       with open(f"{PUBLIC_DIRECTORY}/about/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#", "sioct": "http://rdfs.org/sioc/types#", "Forum": "sioc:Forum", "Thread": "sioc:Thread", "Microblog": "sioct:Microblog", "streams": { "@id": "activity:streams", "@type": "@id" } }, "@id": f"{PUBLIC_URL}", "@type": "Microblog", "streams": [{ "@id": f"{PUBLIC_URL}/statuses", "@type": "Thread" }, { "@id": f"{PUBLIC_URL}/topics", "@type": "Forum" }] }, f, ensure_ascii=False, allow_nan=False)
+
        # Output month‐based listings and the non‐topic index
+       if not exists(f"{PUBLIC_DIRECTORY}/statuses"):
+               mkdir(f"{PUBLIC_DIRECTORY}/statuses")
        statuspairs = list(enumerate(months.items()))
        for (index, (yyyy_mm, ld)) in statuspairs:
-               if not exists(f"{PUBLIC_DIRECTORY}/{yyyy_mm}"):
-                       mkdir(f"{PUBLIC_DIRECTORY}/{yyyy_mm}")
-               ld["first"] = f"{PUBLIC_URL}/{statuspairs[0][1][0]}"
-               ld["current"] = f"{PUBLIC_URL}/{statuspairs[-1][1][0]}"
+               if not exists(f"{PUBLIC_DIRECTORY}/statuses/{yyyy_mm}"):
+                       mkdir(f"{PUBLIC_DIRECTORY}/statuses/{yyyy_mm}")
+               ld["first"] = f"{PUBLIC_URL}/statuses/{statuspairs[0][1][0]}"
+               ld["current"] = f"{PUBLIC_URL}/statuses/{statuspairs[-1][1][0]}"
                if index > 0:
-                       ld["prev"] = f"{PUBLIC_URL}/{statuspairs[index - 1][1][0]}"
+                       ld["prev"] = f"{PUBLIC_URL}/statuses/{statuspairs[index - 1][1][0]}"
                if index < len(statuspairs) - 1:
-                       ld["next"] = f"{PUBLIC_URL}/{statuspairs[index + 1][1][0]}"
-               with open(f"{PUBLIC_DIRECTORY}/{yyyy_mm}/index.jsonld", "w", encoding="utf-8") as f:
+                       ld["next"] = f"{PUBLIC_URL}/statuses/{statuspairs[index + 1][1][0]}"
+               with open(f"{PUBLIC_DIRECTORY}/statuses/{yyyy_mm}/index.jsonld", "w", encoding="utf-8") as f:
                        json.dump(ld, f, ensure_ascii=False, allow_nan=False)
-       if not exists(f"{PUBLIC_DIRECTORY}/statuses"):
-               mkdir(f"{PUBLIC_DIRECTORY}/statuses")
        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#", "OrderedCollection": "activity:OrderedCollection", "current": { "@id": "activity:current", "@type": "@id" }, "first": { "@id": "activity:first", "@type": "@id" } }, "@id": f"{PUBLIC_URL}/statuses", "@type": "OrderedCollection", "first": f"{PUBLIC_URL}/{statuspairs[0][1][0]}", "current": f"{PUBLIC_URL}/{statuspairs[-1][1][0]}" }, 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" } }, "@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)
 
        # Output topic‐based listings and the topic index
        if not exists(f"{PUBLIC_DIRECTORY}/topics"):
@@ -160,7 +175,7 @@ if stdin.read().split()[-1] == f"refs/heads/{LIVE_BRANCH}":
                with open(f"{PUBLIC_DIRECTORY}/topics/{topic}/index.jsonld", "w", encoding="utf-8") as f:
                        json.dump(ld, f, ensure_ascii=False, allow_nan=False)
        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/", "Collection": "activity:Collection", "items": { "@id": "activity:items", "@type": "@id" }, "subject": "dct:subject" }, "@id": f"{PUBLIC_URL}/topics", "@type": "Collection", "items": list(map(lambda a: { "@id": a["@id"], "subject": a["subject"] }, topics.values())) }, 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)
 
        # Remove the build directory.
        rmtree(BUILD_DIRECTORY)
This page took 0.028223 seconds and 4 git commands to generate.