From: Lady <redacted>
Date: Wed, 22 May 2024 05:21:45 +0000 (-0400)
Subject: Drop CKSUM and SRCTIME params; add as attributes
X-Git-Url: https://git.ladys.computer/Shushe/commitdiff_plain/78cdffb646748c9d519ce5b92e2566b7ac7a852b?ds=inline;hp=4ea2291b22300ff429f10a55d6989d87f66c9407

Drop CKSUM and SRCTIME params; add as attributes

`@书社:cksum`, `@书社:mtime`, and `@书社:identifier` are now all added
during the parsing phase. (`@书社:identifier` used to be added during
the transformation phase, but badly. `@书社:mtime` is new.)

This hardcodes the location of the metadata file for now; ideally the
metadata would be embedded.
---

diff --git a/GNUmakefile b/GNUmakefile
index dbf37c6..c15aeaa 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -264,16 +264,6 @@ override comma := ,
 # (callable) Quote the given string for use within shell calls.
 override quote = '$(subst ','"'"',$1)'
 
-# (callable) Get the modified time of the provided file.
-#
-# This touches a file containing only a newline and then diffs it with `/dev/null´ and extracts the timestamp from the diff.
-# Interestingly, on Macintosh, the format of `diff -u´ is only Posixy (including a fractional component and timezone) when `COMMAND_MODE=legacy´; however, the timezone will always be zero and the fractional component is ignorable, so it’s not necessary to worry about that here.
-#
-# The diff will always have an exit status of 1, but this is ignored by piping into Sed.
-#
-# ☡ This variable creates a subshell every time it is computed.
-override modtime = $(shell if $(TEST) ! -f $(call quote,$(BUILDDIR)/.mtime); then $(PRINTF) '%b' '\n' > $(call quote,$(BUILDDIR)/.mtime); fi; $(TOUCH) -r $(call quote,$1) $(call quote,$(BUILDDIR)/.mtime); TZ=UTC0 $(DIFF) -u $(call quote,$(BUILDDIR)/.mtime) /dev/null | $(SED) '1!d;s/.*	\([^ ]*\) \([^ ]*\).*$$/\1T\2Z/')
-
 # ─ ¶ Recipe Variable Definitions ─────────────────────────────────────
 
 # Outputs an `@´ to silence rules, unless `VERBOSE´ is non·empty.
@@ -537,7 +527,7 @@ install : $(call installed,$(recursivefiles) $(installablefiles)) ;
 
 # List all source files and includes and their computed types.
 list :
-	@$(PRINTF) '%b' $(call quote,$(foreach file,$(sort $(sourcefiles)) $(sort $(sourceincludes)),\0033[1m$(file)\0033[22m|$(call typeoffile,$(file))|[\0033[3m$(if $(filter $(file),$(xmlfiles)),xml,$(if $(filter $(file),$(plaintextfiles)),text,asset))$(if $(filter $(file),$(sourceincludes)),|include,)\0033[23m] Modified:|$(call modtime,$(file))$(if $(call dependencies,$(file))$(call recursives,$(file)), $(strip $(foreach recursive,$(call recursives,$(file)),\0033[93;41m•|Recursive|Dependency|\0033[39;49m|$(recursive)) $(foreach dependency,$(call dependencies,$(file)),\0033[2m•|Dependency|\0033[22m|$(dependency))))$(if $(filter $(file),$(sourcefiles)), →|<\0033[4m/$(call destination,$(file))\0033[24m>,) )) | $(TR) ' |' '\n '
+	@$(PRINTF) '%b' $(call quote,$(foreach file,$(sort $(sourcefiles)) $(sort $(sourceincludes)),\0033[1m$(file)\0033[22m|$(call typeoffile,$(file))|[\0033[3m$(if $(filter $(file),$(xmlfiles)),xml,$(if $(filter $(file),$(plaintextfiles)),text,asset))$(if $(filter $(file),$(sourceincludes)),|include,)\0033[23m]$(if $(call dependencies,$(file))$(call recursives,$(file)), $(strip $(foreach recursive,$(call recursives,$(file)),\0033[93;41m•|Recursive|Dependency|\0033[39;49m|$(recursive)) $(foreach dependency,$(call dependencies,$(file)),\0033[2m•|Dependency|\0033[22m|$(dependency))))$(if $(filter $(file),$(sourcefiles)), →|<\0033[4m/$(call destination,$(file))\0033[24m>,) )) | $(TR) ' |' '\n '
 
 # Lists out the destinations of all resulting files (relative to `DESTDIR´).
 listout :
@@ -640,7 +630,7 @@ $(call metadata,$(sourcefiles) $(sourceincludes)) : % : $$(call datadata,$$@) $(
 $(call parsed,$(sourcefiles) $(sourceincludes)) : % : $$(call unparsed,$$@) $(BUILDDIR)/parser.xslt $(typeupdates)
 	$(call inform,$(PRINTF) '%s\n' $(call quote,Processing `$<´…) >&2)
 	$(silent)$(call ensuredirectory,$(dir $@))
-	$(silent)$(if $(filter $<,$(assetfiles)),$(PRINTF) '%s\n' $(call quote,<?xml version="1.0"?><object xmlns="http://www.w3.org/1999/xhtml" type="$(call typeoffile,$<)" data="$(call datauri,$<)"/>) >|$(call quote,$@),$(if $(filter $<,$(plaintextfiles)),$(call wrapplaintext,$<),$(call serializexml,$<)) | $(XSLTPROC) --nonet --novalid -o $(call quote,$@) --stringparam BUILDTIME $$($(DATE) -u '+%Y-%m-%dT%H:%M:%SZ') --stringparam IDENTIFIER $(call quote,$(call localuri,$<)) --stringparam SRCTIME '$(call modtime,$<)' --stringparam CKSUM $$($(CKSUM) $(call quote,$<) | $(SED) 's/[ ].*//')$(if $(THISREV), --stringparam THISREV $(call quote,$(THISREV)),)$(if $(SRCREV), --stringparam SRCREV $(call quote,$(SRCREV)),) $(call quote,$(BUILDDIR)/parser.xslt) -)
+	$(silent)$(if $(filter $<,$(assetfiles)),$(PRINTF) '%s\n' $(call quote,<?xml version="1.0"?><object xmlns="http://www.w3.org/1999/xhtml" type="$(call typeoffile,$<)" data="$(call datauri,$<)"/>) >|$(call quote,$@),$(if $(filter $<,$(plaintextfiles)),$(call wrapplaintext,$<),$(call serializexml,$<)) | $(XSLTPROC) --nonet --novalid -o $(call quote,$@) --stringparam BUILDTIME $$($(DATE) -u '+%Y-%m-%dT%H:%M:%SZ') --stringparam IDENTIFIER $(call quote,$(call localuri,$<))$(if $(THISREV), --stringparam THISREV $(call quote,$(THISREV)),)$(if $(SRCREV), --stringparam SRCREV $(call quote,$(SRCREV)),) $(call quote,$(BUILDDIR)/parser.xslt) -)
 
 # Collect the metadata into a single file.
 $(BUILDDIR)/metadata : $(call diffprereqs,metadatas,$(call metadata,$(sort $(sourcefiles) $(sourceincludes))))
@@ -675,7 +665,7 @@ $(BUILDDIR)/transform.xslt : $(BUILDDIR)/transform.catalog $(THISDIR)/lib/catalo
 $(call compiled,$(compilablefiles)) : $(BUILDDIR)/results/% : $$(call parsed,$$(call uncompiled,$$@)) $$(call parsed,$$(call dependencies,$$(call uncompiled,$$@))) $(BUILDDIR)/transform.xslt $(BUILDDIR)/metadata
 	$(call inform,$(PRINTF) '%s\n' $(call quote,Compiling </$*>…) >&2)
 	$(silent)$(call ensuredirectory,$(dir $@))
-	$(silent)$(XSLTPROC) --nonet --novalid -o $(call quote,$@) --stringparam METADATA 'metadata' --stringparam BUILDTIME $$($(DATE) -u '+%Y-%m-%dT%H:%M:%SZ') --stringparam SRCTIME '$(call modtime,$(call uncompiled,$@))' --stringparam IDENTIFIER $(call quote,$(call localuri,$(call uncompiled,$@))) --stringparam PATH $(call quote,/$*) --stringparam CKSUM $$($(CKSUM) $(call quote,$(call uncompiled,$@)) | $(SED) 's/[ ].*//')$(if $(THISREV), --stringparam THISREV $(call quote,$(THISREV)),)$(if $(SRCREV), --stringparam SRCREV $(call quote,$(SRCREV)),) $(call quote,$(BUILDDIR)/transform.xslt) $(call quote,$<)
+	$(silent)$(XSLTPROC) --nonet --novalid -o $(call quote,$@) --stringparam METADATA 'metadata' --stringparam BUILDTIME $$($(DATE) -u '+%Y-%m-%dT%H:%M:%SZ') --stringparam IDENTIFIER $(call quote,$(call localuri,$(call uncompiled,$@))) --stringparam PATH $(call quote,/$*)$(if $(THISREV), --stringparam THISREV $(call quote,$(THISREV)),)$(if $(SRCREV), --stringparam SRCREV $(call quote,$(SRCREV)),) $(call quote,$(BUILDDIR)/transform.xslt) $(call quote,$<)
 
 # Create the final files from the compiled results (or error in the case of recursive ones).
 $(call built,$(compilablefiles)) : $(BUILDDIR)/public/% : $(BUILDDIR)/results/%
diff --git a/README.markdown b/README.markdown
index 9921983..e21052c 100644
--- a/README.markdown
+++ b/README.markdown
@@ -465,8 +465,17 @@ It is **strongly recommended** that auxillary templates in parsers be
 ⛩️📰 书社 will add a few attributes to the output of the parsing step,
   namely :⁠—
 
-- A `@书社:cksum` attribute on toplevel result elements, giving the
-    `cksum` checksum of the corresponding source file.
+- For toplevel result elements :⁠—
+
+  - A `@书社:cksum` attribute giving the `cksum` checksum of the
+      corresponding source file.
+
+  - A `@书社:mtime` attribute giving the last modified time of the
+      corresponding source file.
+
+  - A `@书社:identifier` attribute giving the ⛩️📰 书社 identifier
+      (i·e, starting with `about:shushe?`) of the corresponding source
+      file.
 
 - For the elements which result from parsing plaintext `<html:script>`
     elements :⁠—
@@ -586,9 +595,6 @@ The following params are made available globally in parsers and
 - **`BUILDTIME`:**
   The current time.
 
-- **`CKSUM`:**
-  The checksum of the source file (⅌ `cksum`).
-
 - **`IDENTIFIER`:**
   The ⛩️📰 书社 identifier of the source file (a u·r·i beginning with
     `about:shushe`).
@@ -596,9 +602,6 @@ The following params are made available globally in parsers and
 - **`SRCREV`:**
   The value of the `SRCREV` variable (if present).
 
-- **`SRCTIME`:**
-  The time at which the source file was last modified.
-
 - **`THISREV`:**
   The value of the `THISREV` variable (if present).
 
diff --git a/lib/catalog2parser.xslt b/lib/catalog2parser.xslt
index 799bfeb..f3afd7f 100644
--- a/lib/catalog2parser.xslt
+++ b/lib/catalog2parser.xslt
@@ -17,6 +17,8 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
 	xmlns:exsl="http://exslt.org/common"
 	xmlns:exslstr="http://exslt.org/strings"
 	xmlns:html="http://www.w3.org/1999/xhtml"
+	xmlns:nfo="http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#"
+	xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 	xmlns:xslt="http://www.w3.org/1999/XSL/TransformAlias"
 	xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
@@ -28,10 +30,8 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
 	<template match="/">
 		<xslt:transform extension-element-prefixes="exsl" version="1.0">
 			<xslt:param name="BUILDTIME" select="'1972-12-31T00:00:00Z'"/>
-			<xslt:param name="CKSUM" select="false()"/>
 			<xslt:param name="IDENTIFIER" select="false()"/>
 			<xslt:param name="SRCREV" select="false()"/>
-			<xslt:param name="SRCTIME" select="'1972-12-31T00:00:00Z'"/>
 			<xslt:param name="THISREV" select="false()"/>
 			<xslt:variable name="书社:parsers">
 				<html:dl>
@@ -130,9 +130,15 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
 						<xslt:when test="self::*">
 							<xslt:copy>
 								<xslt:attribute name="书社:cksum">
-									<xslt:value-of select="$CKSUM"/>
+									<xslt:value-of select="document('metadata')//*[@rdf:about=$IDENTIFIER]/nfo:hasHash[@nfo:hashAlgorithm='CRC32']/@nfo:hashValue"/>
 								</xslt:attribute>
-								<xslt:copy-of select="@*|node()"/>
+								<xslt:attribute name="书社:identifier">
+									<xslt:value-of select="$IDENTIFIER"/>
+								</xslt:attribute>
+								<xslt:attribute name="书社:mtime">
+									<xslt:value-of select="document('metadata')//*[@rdf:about=$IDENTIFIER]/nfo:fileLastModified"/>
+								</xslt:attribute>
+								<xslt:copy-of select="@*[namespace-uri()!='urn:fdc:ladys.computer:20231231:Shu1She4' or not(contains(' cksum identifier mtime ', concat(' ', local-name(), ' ')))]|node()"/>
 							</xslt:copy>
 						</xslt:when>
 						<xslt:otherwise>
diff --git a/lib/catalog2transform.xslt b/lib/catalog2transform.xslt
index b0e3be1..da9c605 100644
--- a/lib/catalog2transform.xslt
+++ b/lib/catalog2transform.xslt
@@ -36,12 +36,10 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
 	<template match="/">
 		<xslt:transform exclude-result-prefixes="nie nfo" extension-element-prefixes="exsl exslstr" version="1.0">
 			<xslt:param name="BUILDTIME" select="'1972-12-31T00:00:00Z'"/>
-			<xslt:param name="CKSUM" select="false()"/>
 			<xslt:param name="IDENTIFIER" select="false()"/>
 			<xslt:param name="METADATA" select="'metadata'"/>
 			<xslt:param name="PATH" select="'/unknown'"/>
 			<xslt:param name="SRCREV" select="false()"/>
-			<xslt:param name="SRCTIME" select="'1972-12-31T00:00:00Z'"/>
 			<xslt:param name="THISREV" select="false()"/>
 			<xslt:variable name="书社:source" select="/"/>
 			<xslt:variable name="书社:expansion">
@@ -338,9 +336,6 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
 			</xslt:template>
 			<xslt:template match="/node()" mode="书社:expand" priority="0">
 				<xslt:copy>
-					<xslt:attribute name="书社:identifier">
-						<xslt:value-of select="$IDENTIFIER"/>
-					</xslt:attribute>
 					<xslt:choose>
 						<xslt:when test="self::html:*">
 							<xslt:attribute name="itemscope">itemscope</xslt:attribute>
@@ -373,9 +368,6 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
 						</xslt:variable>
 						<xslt:for-each select="exsl:node-set($expanded)/node()">
 							<xslt:copy>
-								<xslt:attribute name="书社:identifier">
-									<xslt:value-of select="$identifier"/>
-								</xslt:attribute>
 								<xslt:choose>
 									<xslt:when test="self::html:*">
 										<xslt:attribute name="itemscope">itemscope</xslt:attribute>
@@ -390,10 +382,10 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
 												<xslt:value-of select="."/>
 											</xslt:for-each>
 										</xslt:attribute>
-										<xslt:copy-of select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype')) and not(namespace-uri()='&书社;' and local-name()='identifier')]|node()"/>
+										<xslt:copy-of select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype'))]|node()"/>
 									</xslt:when>
 									<xslt:otherwise>
-										<xslt:apply-templates select="@*[not(namespace-uri()='&书社;' and local-name()='identifier')]|node()" mode="书社:expand"/>
+										<xslt:apply-templates select="@*|node()" mode="书社:expand"/>
 									</xslt:otherwise>
 								</xslt:choose>
 							</xslt:copy>