]> Lady’s Gitweb - Shushe/commitdiff
Drop CKSUM and SRCTIME params; add as attributes 0.10.0
authorLady <redacted>
Wed, 22 May 2024 05:21:45 +0000 (01:21 -0400)
committerLady <redacted>
Thu, 11 Jul 2024 01:46:30 +0000 (21:46 -0400)
`@书社: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.

GNUmakefile
README.markdown
lib/catalog2parser.xslt
lib/catalog2transform.xslt

index 1cf21d27fa361240ba3dda1aa65771832a4a9bc0..50be48d2ef074c93ff6f7b1788c1c5544d91d256 100644 (file)
@@ -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.
@@ -542,7 +532,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 :
@@ -645,7 +635,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))))
@@ -680,7 +670,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/%
index b3789ad52731f96b6f68c85470bfe414c4ed53cf..e70361e3160b68b98656993439f61f38f36d5f52 100644 (file)
@@ -467,8 +467,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 :⁠—
@@ -588,9 +597,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`).
@@ -598,9 +604,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).
 
index 799bfeb30e53a33f86db4869d77007c192c07e8f..f3afd7fa945d8a763e30cbe22f792269910e290c 100644 (file)
@@ -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>
index c41e3b1c7bae35a516b07c0b7db88514bd36d827..dc09330ed10c461f1d5059d41ce1fe472a92bcdf 100644 (file)
@@ -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">
@@ -340,9 +338,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>
@@ -375,9 +370,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>
@@ -392,10 +384,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>
This page took 0.034082 seconds and 4 git commands to generate.