# 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 :—
#
-# • For files with a location of `sources/index.xml` or `sources/index-*.xml`, the transformed file will be written to `public/%.xhtml` (where `%` is the filename).
+# • 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.xhtml` (where `%` is the filename and subdirectory if applicable).
+# • 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).
# Only one level of subdirectory is supported.
#
# By default, running `make` will do this for all applicable source files.
# 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/.
-XHTMLEXT = xhtml
XSLT = xsltproc
XSLTOPTS =
override prerequisites := transform.xslt $(headers) $(footers)
override indexsources := $(wildcard sources/index.xml sources/index-*.xml)
-override indices := $(patsubst sources/%.xml,public/%.$(XHTMLEXT),$(indexsources))
+override indices := $(patsubst sources/%.xml,public/%.html,$(indexsources))
override pagesources := $(filter-out $(indexsources),$(wildcard sources/*.xml sources/*/*.xml))
-override pages := $(patsubst sources/%.xml,public/%/index.$(XHTMLEXT),$(pagesources))
+override pages := $(patsubst sources/%.xml,public/%/index.html,$(pagesources))
-override makexslt = $(XSLT) --nonet --novalid $(XSLTOPTS) -o $(2) transform.xslt $(1)
+override content := $(indices) $(pages)
-all: $(indices) $(pages) ;
+override makexslt = $(XSLT) --nonet --novalid $(XSLTOPTS) -o $(2) transform.xslt $(1)
-$(indices): public/%.$(XHTMLEXT): sources/%.xml $(prerequisites)
- $(call makexslt,$<,$@)
+all: $(content) ;
-$(pages): public/%/index.$(XHTMLEXT): sources/%.xml $(prerequisites)
- $(call makexslt,$<,$@)
+$(indices): public/%.html: sources/%.xml $(prerequisites)
+ @echo "Generating $@…"
+ @$(call makexslt,$<,$@)
-clean:
- rm -f $(indices) $(pages)
+$(pages): public/%/index.html: sources/%.xml $(prerequisites)
+ @echo "Generating $@…"
+ @$(call makexslt,$<,$@)
-.PHONY: all clean ;
+.PHONY: all ;
## Prerequisites
-These things come preinstalled on many platforms :—
+These things come pre·installed on many platforms :—
-- G·N·U Make (run `make --version` to see if it is installed)
-
-- libxslt (run `xsltproc --version` to see if it is installed)
+- G·N·U `make` (run `make --version` to see if it is installed)
+- `xsltproc` (run `xsltproc --version` to see if it is installed)
You will also need to know how to write X·M·L, and how to navigate to a
directory via the command line and run `make`.
elements will be replaced by the page header, content, and footer,
respectively.
-Finally, just run `make` from this directory, and X·H·T·M·L files
+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).
## Notes
-- The created files have a `.xhtml` extension and *need* to be served
- with a `application/xhtml+xml` (or `application/xml`) media type. Not
- all servers know how to serve `.xhtml` files; if this is you, you may
- have better luck with `make XHTMLEXT=xml` (which will produce `.xml`
- files instead).
-
- - Some free hosting options require that “index” pages have an
- extension of `.html`; these will unfortunately not work. It is
- possible to extend the makefile to generate `index.html` redirects
- to `index.xhtml` with the following code :—
-
- ```make
- override redirects := $(patsubst public/%.$(XHTMLEXT),public/%.html,$(indices) $(pages))
-
- all: $(redirects) # in addition to the previously declared prerequisites
-
- $(redirects):
- # You may want a more involved redirect page than this, but it’s an example…
- echo '<!DOCTYPE html><meta http-equiv="refresh" content="0;url=./index.xhtml">' > $@
- ```
-
- This should be considered a last resort, but it can be used to get
- your site working on e·g Neocities.
+- The created files have a `.html` extension and need to be served
+ with a `text/html` media type.
- Files at `sources/index.xml` and `sources/index-*.xml` will produce
- output at `public/%.xhtml` (where `%` is the filename).
+ output at `public/%.html` (where `%` is the filename).
- All other files at `sources/*.xml` and `sources/*/*.xml` will produce
- output at `public/%/index.xhtml` (where `%` is the filename and
+ output at `public/%/index.html` (where `%` is the filename and
optional subdirectory). Only one level of subdirectory is supported.
- The transformation doesn’t do any rewriting of links. Make sure you
<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
-<meta name="generator" content="https://git.ladys.computer/Shrine-XSLT"/>
-</head>
+<head><meta name="generator" content="https://git.ladys.computer/Shrine-XSLT"/></head>
<body>
<shrine-header/>
+
+<main>
<shrine-content/>
+</main>
+
<shrine-footer/>
</body>
</html>
If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
-->
<xslt:transform
- xmlns="http://www.w3.org/1999/xhtml"
- xmlns:exslt="http://exslt.org/common"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:xslt="http://www.w3.org/1999/XSL/Transform"
version="1.0"
Instead of actually processing the root node, process the template in `template` mode.
-->
<xslt:template match="/">
- <xslt:apply-templates select="exslt:node-set($template)" mode="template"/>
+ <xslt:apply-templates select="$template" mode="template"/>
</xslt:template>
<!--
By default, just copy the element, but remove any `@data-shrine-*` attribuets or `@slot` attributes with a value that begins with `shrine-`.
Some elements may have special treatment.
-->
- <xslt:template match="*|text()" mode="content">
- <xslt:copy>
+ <xslt:template match="*" mode="content">
+ <xslt:element name="{local-name()}">
<xslt:for-each select="@*[not(starts-with(name(), 'data-shrine-')) and not(name()='slot' and starts-with(., 'shrine-'))]">
<xslt:copy/>
</xslt:for-each>
</xslt:otherwise>
</xslt:choose>
</xslt:for-each>
- </xslt:copy>
+ </xslt:element>
+ </xslt:template>
+
+ <!--
+ Process text content; just make a copy.
+ -->
+ <xslt:template match="text()" mode="content">
+ <xslt:copy/>
</xslt:template>
<!--
By default, just copy the element.
This behaviour will be overridden for certain elements to insert the page content.
-->
- <xslt:template match="*|text()" mode="template">
- <xslt:copy>
+ <xslt:template match="*" mode="template">
+ <xslt:element name="{local-name()}">
<xslt:for-each select="@*">
<xslt:copy/>
</xslt:for-each>
<xslt:apply-templates mode="template"/>
- </xslt:copy>
+ </xslt:element>
+ </xslt:template>
+
+ <!--
+ Process template text; just make a copy.
+ -->
+ <xslt:template match="text()" mode="content">
+ <xslt:copy/>
</xslt:template>
<!--
This copies over `@lang` and non‐shrine `@data-*` attributes from the root node.
-->
<xslt:template match="html:html" mode="template">
- <xslt:copy>
- <xslt:for-each select="@*">
+ <html>
+ <xslt:for-each select="@*[not(starts-with(name(), 'xmlns'))]">
<xslt:copy/>
</xslt:for-each>
- <xslt:for-each select="exslt:node-set($source)/*/@*[name()='lang' or name()='xml:lang' or starts-with(name(), 'data-') and not(starts-with(name(), 'data-shrine-'))]">
- <xslt:if test="not(exslt:node-set($template)/*/@*[name()=name(current())])">
+ <xslt:for-each select="$source/*/@*[name()='lang' or starts-with(name(), 'data-') and not(starts-with(name(), 'data-shrine-'))]">
+ <xslt:if test="not($template/*/@*[name()=name(current())])">
<xslt:copy/>
</xslt:if>
</xslt:for-each>
<xslt:apply-templates mode="template"/>
- </xslt:copy>
+ </html>
</xslt:template>
<!--
This inserts appropriate metadata based on the document.
-->
<xslt:template match="html:head" mode="template">
- <xslt:copy>
+ <head>
<xslt:for-each select="@*">
<xslt:copy/>
</xslt:for-each>
- <xslt:if test="not(exslt:node-set($source)//html:title[@slot='shrine-head'])">
- <xslt:text>
</xslt:text>
+ <xslt:if test="not($source//html:title[@slot='shrine-head'])">
<title>
- <xslt:apply-templates select="exslt:node-set($source)//html:h1" mode="text"/>
+ <xslt:apply-templates select="$source//html:h1" mode="text"/>
</title>
</xslt:if>
<xslt:apply-templates mode="template"/>
- <xslt:for-each select="exslt:node-set($source)//*[@slot='shrine-head']">
- <xslt:text>
</xslt:text>
+ <xslt:for-each select="$source//*[@slot='shrine-head']">
<xslt:apply-templates select="." mode="content"/>
</xslt:for-each>
- </xslt:copy>
+ </head>
</xslt:template>
<!--
If no `@data-header` attribute is provided, no header is rendered.
-->
<xslt:template match="html:shrine-header" mode="template">
- <xslt:for-each select="exslt:node-set($source)/*/@data-shrine-header">
+ <xslt:for-each select="$source/*/@data-shrine-header">
<xslt:apply-templates select="document(concat('./', ., '-header.xml'), $template)/*" mode="content"/>
</xslt:for-each>
</xslt:template>
If no `@data-footer` attribute is provided, no footer is rendered.
-->
<xslt:template match="html:shrine-footer" mode="template">
- <xslt:for-each select="exslt:node-set($source)/*/@data-shrine-footer">
+ <xslt:for-each select="$source/*/@data-shrine-footer">
<xslt:apply-templates select="document(concat('./', ., '-footer.xml'), $template)/*" mode="content"/>
</xslt:for-each>
</xslt:template>
Process the content.
-->
<xslt:template match="html:shrine-content" mode="template">
- <xslt:apply-templates select="exslt:node-set($source)/*" mode="content"/>
+ <xslt:apply-templates select="$source/*" mode="content"/>
</xslt:template>
<!--
</xslt:when>
</xslt:choose>
</xslt:template>
+
+ <!--
+ Set the output mode to HTML.
+ -->
+ <xslt:output method="html" charset="UTF-8" doctype-system="about:legacy-compat" indent="no"/>
</xslt:transform>