Lady [Tue, 26 Nov 2024 04:16:36 +0000 (23:16 -0500)]
Don’t use literal result elements in parsers
Literal result elements inherit name·spaces from their surrounding
context. Using `<xslt:element>` elements avoids this trouble (and also
allows for the removal of name·space prefixes, reducing sizes of
results).
Lady [Sun, 27 Oct 2024 19:28:09 +0000 (15:28 -0400)]
Move parse/magic building into different stage
There is a lot of calculation which goes into every “default” run
(every source file must be found and characterized every time), which
results in a lot of file·system reads. This is unnecessary, and
needlessly slow for large numbers of files, on the first run (building
the magic and parsers). This commit moves parser‐building into a new
“initial” mode which then calls into a submake for the actual build,
negating the need for the first restart, simplyfying various aspects of
the code, and generally making things quite a bit more efficient.
The existing “_2stage” mode is combined with the new “initial” mode, as
their functionalities largely overlap.
Lady [Sat, 26 Oct 2024 21:17:56 +0000 (17:17 -0400)]
Don’t recompile without transform/dependency change
Because any change to a file updates its metadata, and metadata is
a dependency of the main transform, changing any file used to require
recompiling all of them. This is needlessly expensive: Files should
only be recompiled for changes to files they actually depend on. (Of
course, files might have an undeclared dependency, but relying on this
is at user’s own risk.)
This commit changes compiled files to depend only on the transform
catalog, not the transform itself, and only the metadata of files they
depend on (which presumably will always be updated alongside the
files). The main transform itself is now a make·file prerequisite,
mirroring the main parser, to ensure it is always current even tho no
compilation properly depends on it anymore.
Lady [Sat, 26 Oct 2024 20:45:08 +0000 (16:45 -0400)]
Use <书社:apply-attributes-to-root> to add version
Now that application happens after every stage, it is simple enough to
just inject an `<书社:apply-attributes-to-root>` into the result
fragment prior to application, rather than supporting an entirely
separate `and-version` param (which may not have been properly applied
in recent commits).
Lady [Sat, 26 Oct 2024 20:32:03 +0000 (16:32 -0400)]
Fix multi‐stage exclusion of [$%] in file·names
Make interprets the dollar signs in commandline variable assignments as
variable references, so they need to be escaped (doubled) when
forwarding values to a submake thru the commandline.
Lady [Sat, 21 Sep 2024 05:16:33 +0000 (01:16 -0400)]
Simplify two‐step build
The two‐step build originally installed to `$(BUILDDIR)/data`, but this
installation step is unnecessary (it just copies over files from the
`public/` folder of the first build). This commit uses the `public/`
folder of the first build directly, allowing both builds to have the
same `$(DESTDIR)` which is only used when actually `make install`ing.
This also enables renaming the folders for the first and second build
from `stage1/` and `stage2/` to `data/` and `site/`, which are more
informative.
Lady [Fri, 20 Sep 2024 03:21:16 +0000 (23:21 -0400)]
Apply attributes at every stage
Previously, there was a lot of complicated logic to account for the
fact that certain important attributes might not be added until the end
of the transformation process (via `<书社:apply-attributes>` or
`<书社:apply-attributes-to-root>`). It’s much simpler, conceptually, to
just apply attributes after every transformation phase and not worry
about them besides.
This does mean that if an embed contains an
`<书社:apply-attributes-to-root>` element, it _will_ almost definitely
be applied when·ever that embed is embedded, before the next phase gets
a chance to put a word in edge·wise. Presumably, tho, this is one of
the main utilities of the `<书社:apply-attributes-to-root>` element in
the first place, so maybe that is okay.
This commit introduces a new `书社:finalize` mode for things wot used
to be in the `书社:apply` mode but weren’t actually related to
attribute application.
Lady [Fri, 20 Sep 2024 03:21:04 +0000 (23:21 -0400)]
Don’t remove invalid @书社:* attributes
There is a lot of difficult logic particularly around
`@书社:archived-as` to remove it if it won’t have any effect. This is
unnecessary and it is probably better to just leave these attributes
untouched (akin to how `<书社:link>` is left untouched when invalid).
Lady [Sun, 15 Sep 2024 19:57:34 +0000 (15:57 -0400)]
Update list, listout for two‐stage builds
`make list` and `make listout` now list files from both stages. Note
that in the case of `make listout`, these files may be in _either_
`/build/stage1/public/` or `/build/stage2/public/` (but hopefully not
both).
`list1`, `list2`, `listout1`, and `listout2` are added to list files
just from a particular stage.
Lady [Sun, 15 Sep 2024 19:08:51 +0000 (15:08 -0400)]
Use diffprereqs files as dependencies, not FORCE
“`diffprereqs`” files are updated whenever the prereqs change, as part
of dependency expansion (and so, obviously, before dependency
comparison). So depending on them is effectively the same as depending
on FORCE iff the dependency changed. However, this approach continues
working across Make restarts.
Previously, if a transform was removed, but Make restarted due to a
parser change, the removal would be ignored because the prereqs would
be updated on the first run but the transform catalog would not. This
commit resolves this issue.
Lady [Sun, 15 Sep 2024 17:31:34 +0000 (13:31 -0400)]
Allow empty archives
Previously, when an archive was empty, it would cause Make to endlessly
restart. This was especially a problem for archives generated from
includes, as if the include was missing (or an empty folder), the
archive would have no members and Make would get stuck in a retry loop.
This commit provides the necessary adjustments to ensure archive code
continues working even when the archive is empty: The archive index
file is always written, and the archive files folder is made to exist
before attempting to `cd` into it.
Lady [Sun, 15 Sep 2024 04:24:45 +0000 (00:24 -0400)]
Enable two‐stage builds using a “data” directory
One pattern for building sites is to use a large number of data files
which are all compiled into a single large file, which is then used to
derive the various pages of the website (using expanded archive
functionality). While this can be done using ordinary includes, it is
expensive to do so, because inclusions and transformations on the
“single large file” will re‐happen every time that it is included. What
is actually desired in this case is an intermediate data file, which
has already had all transformations applied, which can then be included
into other files.
This commit establishes a pattern for doing so, where·by certain files
(conventionally, by file extension; by default, `.rdf`) can be
designated as “data files” and built during an initial pass using
includes from a “data directory”, and then themselves be available as
includes for the second stage. Installing installs files from both
stages. Other commands (such as `listout`) currently ignore data files
because they don’t follow common assumptions (they are not built to
`$(BUILDDIR)/stage2/public`, for example); variants or flags to enable
listing these files may be fruitful future work.
Lady [Tue, 20 Aug 2024 06:22:17 +0000 (02:22 -0400)]
Improve <书社:apply-attributes>, @书社:archived-as
- `<书社:apply-attributes>` should not prevent H·T·M·L from wrapping.
Note that the H·T·M·L wrapper is still not
`<书社:apply-attributes>`‐aware; it will _not_ seek into the wrapped
contents to search for attributes to pull upwards to the root
element. This could probably be improved.
- `@书社:archived-as` can now be applied to `<书社:link>` and will be
passed down to any embedded contents.
- `@书社:archived-as` will not be deleted during attribute application
onto the root element; it now ensures there is a nonroot, nonarchive
ancestor. This is required because archive children are processed
into a separate document prior to application.
An alternative approach might be to wrap archive children in a
`<书社:archive>` element before application and then strip it after,
but this is a fair bit of added work for little benefit. It’s a fair
question whether removing invalid `@书社:*` attributes like this is
even a good practice—invalid `<书社:link>` elements are maintained,
in contrast.
Lady [Sat, 3 Aug 2024 18:04:28 +0000 (14:04 -0400)]
Improve dependency tracking
- Add a `.metadata-format-changed-since` file which is a dependency for
metadata generation. The hope is that this file will change when·ever
the metadata format does, forcing a rebuild of stale metadata.
- Add `PARSERLIBS` and `TRANSFORMLIBS` (and `EXTRA⸺` variants) to
enable rebuilds on changes to files that parsers or transforms depend
on.
Lady [Sat, 3 Aug 2024 17:21:55 +0000 (13:21 -0400)]
Add H·T·M·L microdata to archive children
These attributes (`@itemscope` and `@itemtype`) are normally added at
the beginning of expansion to the root node of the document, prior to
it being wrapped. With archives, they should be added to archive
children as part of the processing which happens during application,
just prior to the wrapping which likewise occurs there. Having these
attributes present is important for title microdata processing (which
happens as a part of wrapping) to work correctly.
As part of this work, microdata handling is improved slightly in all
cases.
Note: If the `@itemscope` or `@itemtype` attributes were already
present on the children of the archive element, for example because
the child was the result of an embed, they will not necessicarily be
adjusted. It’s necessary to remove any embed typing during normal
processing if document typing is desired during the application phase.
Lady [Sat, 3 Aug 2024 16:56:59 +0000 (12:56 -0400)]
Fix transform from sometimes expanding twice
The default behaviour for processing expanded replacements of
`<书社:link>` elements was to expand them again, which was wrong,
beccause they have already been expanded once. They should just be
copied instead.
This line was probably copied from the default behaviour for
`<书社:link>` elements which are not expanded or replaced, where it is
the correct behaviour.
Lady [Thu, 4 Jul 2024 19:04:47 +0000 (15:04 -0400)]
Provide source file in metadata to transforms
While I’ve generally resisted doing this, since tranforms _should_
generally always be looking at the parsed form of the file and not the
original, having access to this property is necessary in some cases to
enable embedding the original source file within the tranformation
result (e·g, when the source file is X·M·L, and there are parsers which
preprocess it). When the source file is _not_ X·M·L, this property is
probably use·less, but included never·the·less.
Lady [Wed, 3 Jul 2024 01:42:56 +0000 (21:42 -0400)]
Fix/improve recursive dependency detection
The old method of detecting recursive dependencies was overcomplicated
and only worked in the simple case of A → B → C → A and not
A → B → C → B. This new method works as follows:
- Given a dependency path…
- Get all of the links in the last document in the path.
- If there are no links, return the path.
- If there are links which point to a file in the path, it is a
recursive dependency. Return the path ending at the point of
recursion.
- Otherwise (there are nonrecursive links), process each path which
results from appending each link to the end of the current path and
return all of them.
The algorithm ends with a set of paths to leaf nodes in the dependency
tree, and each nonroot node in this tree (leaf or branch) is a
dependency. This is what the behaviour should have been from the
beginning. (The old method attempted to process the tree in layers,
rather than as a set of paths.)
Lady [Wed, 3 Jul 2024 01:10:31 +0000 (21:10 -0400)]
Allow including entire directories
This commit enables `@xlink:href`s pointing to entire directories
(ending in `/`) in `<书社:link>`s as an alias for providing a link to
each file in the directory individually. This was always planned, but
apparently never actually implemented before now.
Lady [Sat, 22 Jun 2024 21:54:29 +0000 (17:54 -0400)]
Provide the location of parsed files in metadata
Rather than hardcoding parsed file lookup into `expandmetadata.xslt`
and `catalog2transform.xslt`, provide a file U·R·I for the parsed file
as a part of its metadata and use that instead. It _is_ reasonable for
transforms to want to access the original parsed documents of
dependencies. Note, however, that there is no guarantee that the parsed
document actually exists if it _isn’t_ a dependency for the file.
Lady [Sat, 22 Jun 2024 21:43:40 +0000 (17:43 -0400)]
Disable make·file prerequisites when not needed
Specifically, the `help` and `clean` targets don’t require any
compilation of types, parsers, dependencies, or destinations. G·N·U
Make provides the `$(MAKECMDGOALS)` to check which targets were set as
goals on the commandline; when the only goals are `help` and `clean`,
excessive computation can be disabled.
Lady [Sat, 22 Jun 2024 20:06:53 +0000 (16:06 -0400)]
“Simplify” the restart mechanism using $?
Instead of having two GNUmakefile rules which are present under
different conditions (and which could hypothetically both apply), just
have one and check to see which prerequisites are out·of·date in order
to adjust the behaviour.
In order to prevent unnecessary builds of metadata and parsed files
prior to a type update, wrap the recipes in a check to see if
`$(BUILDDIR)/.update-types` was created over the course of the build.
This needs to happen in the shell, not in Make, because older versions
of Make cache the `$(wildcard)` function. The implementation of
`$(unlesstypeswillupdate)` uses an `if` function instead of a `and`
because the latter seems to trim white·space.
It is no longer an error if the type of a file cannot be determined;
this is required to enable recipe expansion when types are not yet
generated now that the test is happening in the shell. Instead, files
are given a default type of `application/octet-stream`.
Lady [Sat, 22 Jun 2024 17:02:24 +0000 (13:02 -0400)]
Generate dependencies & destinations with metadata
This commit obviates the need for separate `metadata2dependencies` and
`metadata2destinations` transforms and simply bundles their
functionality into `expandmetadata`.
Making this work right is a bit tricky because we are outputting the
main document to `stdout` but want the other result documents to be
output to `BUILDDIR`. The best solution would be to just read in the
build directory inside of the transform and use it to determine the
output location, but unfortunately `exsl:document` does not support
dynamic computation of the destination directory. The current solution
is instead to `cd` into the build directory in a subshell before
calling `xsltproc`.
Lady [Sun, 2 Jun 2024 02:11:10 +0000 (22:11 -0400)]
Simplify metadata using new 书社vocab terms
This commit also changes the behaviour of `@书社:destination`:
Formerly, the value of this attribute needed to be a percent·encoded;
now, it must _not_ be percent·encoded.
Lady [Sun, 2 Jun 2024 01:31:55 +0000 (21:31 -0400)]
Generate destinations and dependencies as metadata
The format of this is subject to change. It might actually be desirable
to have the dependency and destination files be side·effects of the
metadata file generated alongside it (in the same `xsltproc` call)
rather than needing to generate them separately.
Lady [Mon, 27 May 2024 21:38:46 +0000 (17:38 -0400)]
Don’t allow xsltproc to output files
…with the exception of the archive extractor, which is
specially constructed to do so. In all other cases, just output to
standard output and pipe to a file as with other commands, for
consistency and security.
Lady [Mon, 27 May 2024 21:16:23 +0000 (17:16 -0400)]
Provide template identifiers as <书社:id>s
This is definitely going to break existing websites, but it’s much more
sensible and straightforward to deal with, in my opinion. Alternatives
included instead providing them as comments or processing instructions,
which would be much harder to process.
Lady [Mon, 27 May 2024 20:16:44 +0000 (16:16 -0400)]
Do not wrap results which contain no H·T·M·L
It’s much more likely that a result which is not H·T·M·L is intended to
remain that way; wrapping it in `<html:body>` can be used as a
work·around when H·T·M·L wrapping is desired.
Lady [Mon, 27 May 2024 19:09:44 +0000 (15:09 -0400)]
Remove variation selectors from sigil
The choice of whether to render a character as emoji style or text
style is properly a font and typesetting decision, not a character
encoding one. Altho Unicode provides variation selectors for indicating
a preference in plain text, these selectors should not be given formal
significance. To be clear that the canonical encoding for the sigil is
`<U+26E9,U+1F4F0>`, remove them across the board.
Lady [Wed, 22 May 2024 06:37:02 +0000 (02:37 -0400)]
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`.
Lady [Wed, 22 May 2024 05:21:45 +0000 (01:21 -0400)]
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.
Lady [Wed, 22 May 2024 04:44:49 +0000 (00:44 -0400)]
Replace source catalog with metadata file
There are two things which this approach should eventally bring :—
1. Availability of various aspects of file metadata for every file
during the parsing and transformation phases. Right now, only
metadata for the file currently being processed is available, and
while loading the catalog is possible in transforms, it’s probably
not really advisable and hasn’t been extensively tested.
2. Cacheing of file metadata for files which have not changed since the
last time Make was run. This comes with the usual Make drawback that
if a file is changed to be older, rather than newer, it won’t be
recognized as having been changed.
Neither of these things are really implemented at this point, but the
metadata file is created and being used and the old catalog has been
removed. Future commits should refine the behaviour.
Lady [Thu, 11 Jul 2024 01:45:26 +0000 (21:45 -0400)]
Give magic file symlinks unique names
Rather than deal with the potential for conflicts in the names of magic
files from different sources, give each file a unique name by taking
the `cksum` of its absolute path.
Lady [Sat, 6 Jul 2024 22:50:57 +0000 (18:50 -0400)]
Support -exec in find
`-print` is only implicitly added to `find` rules which do not contain
an `-exec`. The desired behaviour is that `-print` is called
regardless, with the assumption that `-exec` commands are always
silent.
Lady [Sat, 6 Jul 2024 20:42:47 +0000 (16:42 -0400)]
Actually use FINDINCLUDERULES
Commit d94cfdc987aba3983f4945d59b02cbb062573432 added this variable and
documented it, but strangely it was never actually used in the
appropriate place; `FINDRULES` was used instead for both ordinary
sources and includes.
Lady [Sat, 22 Jun 2024 16:11:04 +0000 (12:11 -0400)]
Use --nonet on xmllint, too
This option was already being supplied for `xsltproc`. Networking
should always be disabled by default; mechanisms for selectively
enabling it may be added later.
Lady [Mon, 27 May 2024 18:41:47 +0000 (14:41 -0400)]
Use --noent when calling xmllint
The X·Path expressions do not correctly match text provided within
entities if the entities are not expanded. Adding `--noent` ensures
that all entities are expanded and X·Path works correctly.
Lady [Sat, 25 May 2024 04:08:01 +0000 (00:08 -0400)]
Improve SRCDIR/INCLUDEDIR handling; allow dot
- Explicitly allow `find` to match `.`, which otherwise would be
excluded as a dotfile.
- Add special handling to drop the leading `./` that results from the
above, and generate the appropriate local paths without needing it.
- Error when trying to perform certain transformations on file·names
and failing, to better aid diagnosis.
- When a file has no destination (because `destinations` has not been
generated yet), use the fake destination `NOTDEF`. (Make will restart
before this destination is used.)
Lady [Fri, 24 May 2024 05:10:58 +0000 (01:10 -0400)]
Mark GNUmakefile as precious
One would hope that Make wouldn’t ever delete the make·file it is
running, but the documentation doesn’t seem to explicitly give that
guarantee, so it’s good to be explicit about it.
Lady [Fri, 24 May 2024 02:39:49 +0000 (22:39 -0400)]
Allow overriding of cd
Altho `cd` is builtin in most shells, it is not a special builtin
utility as defined by Posix, and the use of an alternative
implementation is conceivable.
Lady [Wed, 22 May 2024 04:29:51 +0000 (00:29 -0400)]
FORCE on type updates
When this was originally implemented, I’m not sure `FORCE` was defined,
but it’s needed now for `diffprereqs` so there’s no reason why not to
use it here as well.
Lady [Tue, 21 May 2024 06:06:07 +0000 (02:06 -0400)]
Use diff to get better dates
See the comments for more information, including Macintosh quirks. This
is a great deal better than using `ls` and allows for the dropping of
the latter as a dependency.
Lady [Tue, 21 May 2024 03:19:48 +0000 (23:19 -0400)]
Support +xml suffix for determining X·M·L files
This gets around operating system extensions to `file` which might
identify S·V·G files (for example) as `image/svg+xml` before
attempting magic detection. If not every X·M·L‐based syntax should be
handled as such by ⛩️📰 书社, redefine `XMLTYPES` to exclude the
`+xml`.
Lady [Sun, 19 May 2024 21:16:42 +0000 (17:16 -0400)]
Remove stat dependency
This is, strictly speaking, a downgrade in functionality, with the
upside of reducing reliance on non·Posix programs (namely `stat`). A
better, Posix‐compliant solution is to archive an empty file with the
correct modification time and then list out the time from that archive;
however, as far as I’m aware, it’s not possible to obtain an
implementation of the `pax` utility which actually supports this. macOS
only supports a very limited subset of the `listopt` option, and only
for pax archives (not tarballs); other implementations don’t seem to
support it at all.
Lady [Sun, 19 May 2024 22:09:06 +0000 (18:09 -0400)]
Force removal of existing directories
…prior to processing results or installing. Mostly, this prevents a
failure when an expanded archive is changed to no longer be expanded.
This also simplifies the installation code a bit.
Lady [Sun, 19 May 2024 19:54:20 +0000 (15:54 -0400)]
Remove sed range expressions
These are technically only Posix in the Posix locale and have undefined
meaning otherwise. It’s not the policy of ⛩️📰 书社 to require the
Posix locale, so the safest thing is to just not use range expressions
here.
(Actually, this policy might be worth revisiting for things which
definitely need to be operating on Unicode text.)
Lady [Fri, 3 May 2024 03:48:12 +0000 (23:48 -0400)]
Use compound commands to join strings, not sed
Previously, the script would sometimes use sed to insert text at the
beginning or end of a string, but it is better to just printf as a
separate step instead.
Lady [Tue, 30 Apr 2024 07:53:58 +0000 (03:53 -0400)]
Support pagination
It’s not clear to me that this is actually a good idea, and this
functionality may be reverted later. It adds a lot of complexity
despite still having significant drawbacks, and the alternative pattern
of just generating archives and later expanding them is a much safer
and more versatile solution.
However, the pattern of e·g needing a paginated feed of all the posts
in one’s blog suggests that something along these lines (backed by this
method or archiving~expanding) *should* be supported by default in
⛩️📰 书社. One alternative might be to add (e·g) a `@书社:expand`
attribute to <书社:archive> elements, tho how exactly this would be
tracked on the resulting archives is unclear, and it would be
restricted to producing folders (with exclusively archive contents)
that could not easily be mixed with other files.
Lady [Sun, 28 Apr 2024 04:02:37 +0000 (00:02 -0400)]
Touch important files before making with xsltproc
When there is nothing to output, `xsltproc` does not create files.
However, Make will find itself in an endless restart loop if these
files are never created.
Lady [Sun, 14 Apr 2024 23:38:07 +0000 (19:38 -0400)]
Allow injecting raw output in X·M·L serialization
It’s not possible to serialize things like entities using the normal
X·S·L·T processes. With this commit, one can instead use something like
`<书社:raw-output>&my-entity;</书社:raw-output>` inside of
`<书社:serialize-xml>` elements to get this result.
Lady [Sun, 14 Apr 2024 19:44:22 +0000 (15:44 -0400)]
Add support for manually serializing X·M·L
This commit adds a transform for a new `<书社:serialize-xml>` element,
which is useful in conjunction with `<书社:raw-text>` to produce a more
finely‐controlled X·M·L output, or in other X·M·L‐y situations where an
escaped X·M·L value is required. The algorithm used for serialization
attempts to closely match the DOM Parsing and Serialization spec,
including such behaviours as mandating an undeclared `xml:` prefix for
the X·M·L name·space and dropping the prefix from elements whose
name·space matches the default, but it probably isn’t exactly the same
(due in part to the fact that the underlying data structure is an X·M·L
infoset, not a potentially dynamically‐modified Dom). No special
allowances are made for elements in the H·T·M·L name·space; this is not
(yet) a suitable polyglot serializer (or intended to be one).
Lady [Wed, 10 Apr 2024 19:53:11 +0000 (15:53 -0400)]
Allow creation of tarballs
This is useful when using ⛩️📰 书社 directly as a static site
generator to provide archive downloads (archives are not compressed; it
is assumed that they will be gzipped over the wire). This requires
a recursive call to Make for each archive file, which performs the
following steps :—
- Extracts all of the elements slated for archiving into separate
files.
- Restarts.
- Processes the resulting extracted files and then archives them.
The extraction step in particular is somewhat convoluted; it requires
dynamically generating a transform which has the appropriate
`<exsl:document>` elements for a given source file, and then applying
that transform in a second call to `xsltproc`.
X·M·L outputs are now passed through an extra call to `xmllint` to
remove any unnecessary namespace attributes instead of just symlinked;
the symlinks weren’t compatible with archiving anyway.