From: Lady Date: Wed, 22 May 2024 06:37:02 +0000 (-0400) Subject: Provide metadata in transform; add attributes there X-Git-Tag: 0.10.1~5 X-Git-Url: https://git.ladys.computer/Shushe/commitdiff_plain/20650221fbf76f8444d66ec16a00e773f9d86647 Provide metadata in transform; add attributes there The metadata actually depends on the parser, so it’s a recursive dependency to make the parser use it. Instead, just make it available in transforms and add the various ⛩️📰 书社 attributes during the expansion phase. Literally including the metadata R·D·F in the transform greatly increases its file size, but it “should” be fine. This commit also brings with it a few other improvements and changes to transforms :⁠— - All of the `$书社:*` variables which used to return result tree fragments now return node sets. - The `书社:application` mode has been renamed to `书社:apply`, to match `书社:expand`. --- diff --git a/GNUmakefile b/GNUmakefile index 50be48d..e9514eb 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -426,10 +426,10 @@ override parsed = $(foreach file,$1,$(patsubst $(file)|%,%,$(filter $(file)|%,$( # (callable) Get the source files for the given parsed file. override unparsed = $(foreach file,$1,$(patsubst %|$(file),%,$(filter %|$(file),$(sourceparsedpair)))) -# Pair each parser, transform, source file, or parsed file with its file u·r·i. -override fileuripairs := $(join $(patsubst %,%|,$(PARSERS) $(TRANSFORMS) $(sourcefiles) $(sourceincludes) $(call parsed,$(sourcefiles) $(sourceincludes))),$(call pathenc,$(foreach uriable,$(PARSERS) $(TRANSFORMS) $(sourcefiles) $(sourceincludes) $(call parsed,$(sourcefiles) $(sourceincludes)),file://$(abspath $(uriable))))) +# Pair each parser, transform, source file, parsed file, or metadata compilation with its file u·r·i. +override fileuripairs := $(join $(patsubst %,%|,$(PARSERS) $(TRANSFORMS) $(sourcefiles) $(sourceincludes) $(call parsed,$(sourcefiles) $(sourceincludes)) $(BUILDDIR)/metadata),$(call pathenc,$(foreach uriable,$(PARSERS) $(TRANSFORMS) $(sourcefiles) $(sourceincludes) $(call parsed,$(sourcefiles) $(sourceincludes)) $(BUILDDIR)/metadata,file://$(abspath $(uriable))))) -# (callable) Get the file u·r·is for the given parsers, transforms, or parsed files. +# (callable) Get the file u·r·is for the given parsers, transforms, parsed files, or metadata compilations. override fileuri = $(foreach file,$1,$(or $(patsubst $(file)|%,%,$(filter $(file)|%,$(fileuripairs))),$(error Unable to get file u·r·i for `$(file)´))) ifneq ($(wildcard $(BUILDDIR)/dependencies),) @@ -626,7 +626,7 @@ $(BUILDDIR)/parser.xslt : $(BUILDDIR)/parser.catalog $(THISDIR)/lib/catalog2pars $(call metadata,$(sourcefiles) $(sourceincludes)) : % : $$(call datadata,$$@) $(typeupdates) $(call inform,$(PRINTF) '%s\n' $(call quote,Generating metadata for `$<´…) >&2) $(silent)$(call ensuredirectory,$(dir $@)) - $(silent){ if $(TEST) ! -f $(call quote,$(BUILDDIR)/.mtime); then $(PRINTF) '%b' '\n' >|$(call quote,$(BUILDDIR)/.mtime); fi; $(TOUCH) -r $(call quote,$<) $(call quote,$(BUILDDIR)/.mtime); TZ=UTC0 $(DIFF) -u $(call quote,$(BUILDDIR)/.mtime) /dev/null | $(SED) '1!d;s/.* \([^ ]*\) \([^ ]*\).*$$/\1T\2Z/'; $(CKSUM) $(call quote,$<) | $(SED) 's/[ ].*//'; } | $(xargsmultiquote) | $(XARGS) -E '' $(PRINTF) '$(if $(filter $(source),$(assetfiles)),,)%s' $(call quote,$(call attresc,$(call localuri,$<))) $(call quote,$(call attresc,$(call fileuri,$<))) $(call quote,$(call attresc,$(call typeoffile,$<))) $(call quote,$(call attresc,$(call fileuri,$(call parsed,$<)))) >|$(call quote,$@) + $(silent){ if $(TEST) ! -f $(call quote,$(BUILDDIR)/.mtime); then $(PRINTF) '%b' '\n' >|$(call quote,$(BUILDDIR)/.mtime); fi; $(TOUCH) -r $(call quote,$<) $(call quote,$(BUILDDIR)/.mtime); TZ=UTC0 $(DIFF) -u $(call quote,$(BUILDDIR)/.mtime) /dev/null | $(SED) '1!d;s/.* \([^ ]*\) \([^ ]*\).*$$/\1T\2Z/'; $(CKSUM) $(call quote,$<) | $(SED) 's/[ ].*//'; } | $(xargsmultiquote) | $(XARGS) -E '' $(PRINTF) '$(if $(filter $<,$(assetfiles)),,)%s' $(call quote,$(call attresc,$(call localuri,$<))) $(call quote,$(call attresc,$(call fileuri,$<))) $(call quote,$(call attresc,$(call typeoffile,$<))) $(call quote,$(call attresc,$(call fileuri,$(call parsed,$<)))) >|$(call quote,$@) # Parse the files. # @@ -662,9 +662,9 @@ $(BUILDDIR)/transform.catalog : $(call diffprereqs,transforms,$(sort $(TRANSFORM $(call inform,$(PRINTF) '%s\n' 'Generating catalog of transforms…' >&2) $(silent)$(XMLCATALOG) --create --noout $(call quote,$@) $(foreach transform,$(TRANSFORMS),$(silent){ $(call id,$(transform)); $(PRINTF) '%s\n' $(call quote,$(call fileuri,$(transform))) '--noout' $(call quote,$@); } | $(xargsmultiquote) | $(XARGS) -E '' $(XMLCATALOG) --add uri$(newline)) -$(BUILDDIR)/transform.xslt : $(BUILDDIR)/transform.catalog $(THISDIR)/lib/catalog2transform.xslt +$(BUILDDIR)/transform.xslt : $(BUILDDIR)/transform.catalog $(BUILDDIR)/metadata $(THISDIR)/lib/catalog2transform.xslt $(call inform,$(PRINTF) '%s\n' 'Generating main transform…' >&2) - $(silent)$(XSLTPROC) --nonet --novalid -o $(call quote,$@) $(call quote,$(THISDIR)/lib/catalog2transform.xslt) $(call quote,$<) + $(silent)$(XSLTPROC) --nonet --novalid -o $(call quote,$@) --stringparam METADATA $(call quote,$(call fileuri,$(BUILDDIR)/metadata)) $(call quote,$(THISDIR)/lib/catalog2transform.xslt) $(call quote,$<) # Compile the result files using the dependencies as necessary. $(call compiled,$(compilablefiles)) : $(BUILDDIR)/results/% : $$(call parsed,$$(call uncompiled,$$@)) $$(call parsed,$$(call dependencies,$$(call uncompiled,$$@))) $(BUILDDIR)/transform.xslt $(BUILDDIR)/metadata diff --git a/README.markdown b/README.markdown index e70361e..e5a24ed 100644 --- a/README.markdown +++ b/README.markdown @@ -464,32 +464,27 @@ It is **strongly recommended** that auxillary templates in parsers be ### Attributes added during parsing -⛩️📰 书社 will add a few attributes to the output of the parsing step, - namely :⁠— +⛩️📰 书社 will add a few attributes to elements which result from + parsing plaintext `` elements. +These include :⁠— -- For toplevel result elements :⁠— +- A `@书社:parsed-by` attribute, giving a space‐separated list of + parsers which parsed the node. + (Generally, this will be a list of one, but it is possible for the + result of a parse to be another plaintext node, which may be parsed + by a different parser.) - - A `@书社:cksum` attribute giving the `cksum` checksum of the - corresponding source file. +- A `@书社:media-type` attribute, giving the identified media type of + the plaintext node. - - 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 `` - elements :⁠— - - - A `@书社:parsed-by` attribute, giving a space‐separated list of - parsers which parsed the node. - (Generally, this will be a list of one, but it is possible for the - result of a parse to be another plaintext node, which may be - parsed by a different parser.) +## Output Redirection - - A `@书社:media-type` attribute, giving the identified media type of - the plaintext node. +By default, ⛩️📰 书社 installs files to the same location in `DESTDIR` + as they were placed in their `SRCDIR`. +This behaviour can be customized by setting the `@书社:destination` + attribute on the root element, whose value can give a different path. +This attribute is read after parsing, but before transformation (where + it is silently dropped). ## Embedding @@ -516,14 +511,30 @@ Embedding takes place after parsing but before transformation, so and update them accordingly; it will signal an error if the dependencies are recursive. -## Output Redirection +### Attributes added during expansion -By default, ⛩️📰 书社 installs files to the same location in `DESTDIR` - as they were placed in their `SRCDIR`. -This behaviour can be customized by setting the `@书社:destination` - attribute on the root element, whose value can give a different path. -This attribute is read after parsing, but before transformation (where - it is silently dropped). +⛩️📰 书社 will add a few attributes to toplevel result elements, both + in the main document and any embedded documents, during the expansion + phase prior to the main transformation. +These include :⁠— + +- 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 elements in the `html` namespace, an `itemscope` attribute and an + `itemtype` attribute with a value of + `urn:fdc:ladys.computer:20231231:Shu1She4:document` (for the main + document) or `urn:fdc:ladys.computer:20231231:Shu1She4:embed` (for + embedded documents). + These attributes are used to scope any nested `` elements + with `@itemprop` attributes to their containing documents. ## Transforms @@ -609,9 +620,6 @@ The following params are made available globally in parsers and The following params are only available in transforms :⁠— -- **`METADATA`:** - The path of the metadata file (within `BUILDDIR`). - - **`PATH`:** The path of the output file (within `DESTDIR`). diff --git a/lib/catalog2parser.xslt b/lib/catalog2parser.xslt index f3afd7f..381fee3 100644 --- a/lib/catalog2parser.xslt +++ b/lib/catalog2parser.xslt @@ -122,30 +122,7 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/lib/catalog2transform.xslt b/lib/catalog2transform.xslt index dc09330..fe16087 100644 --- a/lib/catalog2transform.xslt +++ b/lib/catalog2transform.xslt @@ -32,22 +32,29 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one exclude-result-prefixes="catalog" version="1.0" > + + diff --git a/transforms/serialization.xslt b/transforms/serialization.xslt index 6d6dacd..2565fa6 100644 --- a/transforms/serialization.xslt +++ b/transforms/serialization.xslt @@ -22,10 +22,10 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one > <书社:id>urn:fdc:ladys.computer:20231231:Shu1She4:serialization.xslt -