From: Lady Date: Fri, 23 Dec 2022 21:01:51 +0000 (-0800) Subject: Basic support for Atom feeds X-Git-Tag: 0.3.0^0 X-Git-Url: https://git.ladys.computer/Shrine-XSLT/commitdiff_plain/e56ab0f26f35e32120971057b6db350175672c90?hp=e909485e807eb94a39b384076d52c86cabadc07d Basic support for Atom feeds • Files with an `.atom` extension will be passed through the same X·S·L·T transform as `.xml` files, which now has Atom‐specific rules. • Automatic generation for basic metadata. There is probably more work to do here to automatically pull things like titles and summaries. Other small improvements added as a part of this work :— • The `transform.xslt` file is now specified via a `$(TRANSFORM)` variable in the Makefile and can be overridden. • The `xmlns:html` attribute is manually removed from the root element of outputted H·T·M·L (if it exists). • Subdirectories are now properly created in the `public/` folder when needed. --- diff --git a/GNUmakefile b/GNUmakefile index b8bbd4a..a6b7b4a 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,13 +1,15 @@ SHELL = /bin/sh -# This GNUmakefile searches the `sources/` directory for files with an extension of `.xml` and applies `transform.xslt` to them, outputting the result in one of two locations :— +# This GNUmakefile searches the `sources/` directory for files with an extension of `.atom` or `.xml` and applies `transform.xslt` to them, outputting the result in one of the following locations :— # # • For files with a location of `sources/index.xml` or `sources/index-*.xml`, the transformed file will be written to `public/%.html` (where `%` is the filename). # # • For all other files with a location of `sources/*.xml` or `sources/*/*.xml`, the transformed file will be written to `public/%/index.html` (where `%` is the filename and subdirectory if applicable). -# Other files in the corresponding directory (i·e without the `.xml`) are copied over verbatim. +# Any files in a corresponding sibling directory (i·e without the `.xml`) are copied over verbatim. # Only one level of subdirectory is supported. # +# • For files with a location of `sources/*.atom` or `sources/*/*.atom`, the transformed file will be written to `public/%.atom` (where `%` is the filename and subdirectory if applicable). +# # By default, running `make` will do this for all applicable source files. # # ___ @@ -17,12 +19,15 @@ SHELL = /bin/sh # This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. # If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. +BASEIRI = http://example.com +DATETIME = $(shell date -Iseconds) +TRANSFORM = transform.xslt XSLT = xsltproc XSLTOPTS = headers := $(wildcard *-header.xml) footers := $(wildcard *-footer.xml) -override prerequisites := transform.xslt $(headers) $(footers) +override prerequisites := $(TRANSFORM) $(headers) $(footers) override indexsources := $(wildcard sources/index.xml sources/index-*.xml) override indices := $(patsubst sources/%.xml,public/%.html,$(indexsources)) @@ -33,23 +38,45 @@ override pages := $(patsubst sources/%.xml,public/%/index.html,$(pagesources)) override resourcesources := $(wildcard $(addsuffix /*,$(basename $(pagesources)))) override resources := $(patsubst sources/%,public/%,$(resourcesources)) +override feedsources := $(filter-out $(resourcesources),$(wildcard sources/*.atom sources/*/*.atom)) +override feeds := $(patsubst sources/%.atom,public/%.atom,$(feedsources)) + override content := $(indices) $(pages) -override makexslt = $(XSLT) --nonet --novalid $(XSLTOPTS) -o $(2) transform.xslt $(1) +# This function does the following :— +# +# • Calls `transform.xslt` with the `$(1)`, providing `$(BASEIRI)` and `$(DATETIME) as params and providing `$(2)` (minus the initial `public/`) as the param `OUTPUTPATH`. +# +# • Removes any `xmlns` prefix declarations from output to `.html` files (with `sed`). +# +# • Removes any doctype for root elements other than `html` (with `grep -v`). +# +# • Saves the output to `$(2)`. +override makexslt = $(XSLT) --nonet --novalid $(XSLTOPTS) --stringparam BASEIRI "$(BASEIRI)" --stringparam DATETIME "$(DATETIME)" --stringparam OUTPUTPATH "$(patsubst public/%,/%,$(2))" transform.xslt $(1)\ + $(if $(filter %.html,$(2)),| sed 's/ xmlns:[0-9A-Za-z_-]*="[^"]*"//g',)\ + | grep -v '^]\)'\ + > $(2) -all: $(content) $(resources); +all: $(content) $(resources) $(feeds); $(indices): public/%.html: sources/%.xml $(prerequisites) @echo "Generating $@…" + @mkdir -p $(dir $@) @$(call makexslt,$<,$@) $(pages): public/%/index.html: sources/%.xml $(prerequisites) @echo "Generating $@…" + @mkdir -p $(dir $@) @$(call makexslt,$<,$@) $(resources): public/%: sources/% @echo "Copying over $@…" - @mkdir -p $(dir $<) + @mkdir -p $(dir $@) @cp $< $@ +$(feeds): public/%.atom: sources/%.atom $(TRANSFORM) + @echo "Generating $@…" + @mkdir -p $(dir $@) + @$(call makexslt,$<,$@) + .PHONY: all ; diff --git a/README.markdown b/README.markdown index 3b040d6..0abeeb6 100644 --- a/README.markdown +++ b/README.markdown @@ -50,6 +50,31 @@ Finally, just run `make` from this directory, and H·T·M·L files corresponding to your source files will be created in the `public/` directory (which you can then serve statically from your server). +## Atom Feeds + +Any `.atom` files you provide will automatically be filled out with +``s, `` values, and other necessary information before +being copied to the destination location. If you wish to use this +feature, you will need to provide a `BASEIRI` variable when you run +`make` to allow the X·S·L·T to transform relative links into absolute +ones. + +It is recommended that :— + +- You do *not* provide your own ``s and rely on the generated ones + (which will be an `oai:` URI derived from the file path). + +- You *do* manually provide `` times for individual entries + (although not the feed as a whole); otherwise every entry will be + marked as updated every time the feed is generated. + +- All `` elements in `` elements use a + relative `@href` with a leading slash. This should point to the + *final* location of the entry (within, but not including, `public/`). + +There’s an example `feed.atom` provided so you can see what this + feature might look like in practice. + ## Notes - The created files have a `.html` extension and need to be served diff --git a/sources/blog/1972-12-31.xml b/sources/blog/1972-12-31.xml new file mode 100644 index 0000000..9b28668 --- /dev/null +++ b/sources/blog/1972-12-31.xml @@ -0,0 +1,3 @@ +
+

My Blog Post

+
diff --git a/sources/feed.atom b/sources/feed.atom new file mode 100644 index 0000000..2246fd4 --- /dev/null +++ b/sources/feed.atom @@ -0,0 +1,9 @@ + + My Amazing Shrine + Me + + + My Blog Post + 1972-12-31T00:00:00Z + + diff --git a/transform.xslt b/transform.xslt index 0919121..20fe4c2 100644 --- a/transform.xslt +++ b/transform.xslt @@ -23,10 +23,41 @@ This Source Code Form is subject to the terms of the Mozilla Public License, v. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. --> + + + + + + + + + :// + + + + + + + + + + + + + + + + + + / + + + @@ -34,7 +65,14 @@ If a copy of the MPL was not distributed with this file, You can obtain one at h Instead of actually processing the root node, process the template in `template` mode. --> - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + oai: + + : + + + + / + + + + + + + + Untitled + + + + + Anonymous + + + + + + + + + + + + + + + + + + + shrine-xslt + + + + + + + + + + + + + + + + + + + + + oai: + + : + + + + / + + + + + + + + Untitled + + + + + + + + + + + + + + + + + + + + @@ -173,7 +341,9 @@ If a copy of the MPL was not distributed with this file, You can obtain one at h - +