]> Lady’s Gitweb - Shrine-XSLT/commitdiff
Change output mode to H·T·M·L
authorLady <redacted>
Sat, 10 Dec 2022 03:29:30 +0000 (19:29 -0800)
committerLady <redacted>
Sat, 29 Apr 2023 03:04:17 +0000 (20:04 -0700)
GNUmakefile
README.markdown
template.xml
transform.xslt

index fa30f687cb69cdac54028375b125ff20b20bddfe..ecf9f9d6399e5c51cd38ef2f96133aff25bcf433 100644 (file)
@@ -2,9 +2,9 @@ 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 :—
 #
-# • 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.
@@ -16,7 +16,6 @@ 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/.
 
-XHTMLEXT = xhtml
 XSLT = xsltproc
 XSLTOPTS =
 
@@ -25,22 +24,23 @@ footers := $(wildcard *-footer.xml)
 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 ;
index 216d4d87e4f8141c1811a6bed5b4917024bbe18e..c7b84ae3cd306f5e925b176dc4470d1dbe3068af 100644 (file)
@@ -12,11 +12,10 @@ substantially changing the authoring flow.
 
 ## 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`.
@@ -48,41 +47,20 @@ page. The `<shrine-header>`, `<shrine-content>`, and `<shrine-footer>`
 elements will be replaced by the page header, content, and footer,
 respectively.
 
-Finally, just run `make` from this directory, and 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
index 01683e859d690039098ae535bbcb2fb77f139b3e..113ff65254603fd8908576b527a5fb8fbfcd6f7b 100644 (file)
@@ -1,10 +1,12 @@
 <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>
index 2e3c7bd3e45f51b41d7dcfe128ac3e7354d2b74e..0919121f56192ea1934cd58726d8f19c7db478df 100644 (file)
@@ -23,8 +23,6 @@ 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/.
 -->
 <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"
@@ -36,7 +34,7 @@ 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.
        -->
        <xslt:template match="/">
-               <xslt:apply-templates select="exslt:node-set($template)" mode="template"/>
+               <xslt:apply-templates select="$template" mode="template"/>
        </xslt:template>
 
        <!--
@@ -44,8 +42,8 @@ If a copy of the MPL was not distributed with this file, You can obtain one at h
                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>
@@ -61,7 +59,14 @@ If a copy of the MPL was not distributed with this file, You can obtain one at h
                                        </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>
 
        <!--
@@ -69,13 +74,20 @@ If a copy of the MPL was not distributed with this file, You can obtain one at h
                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>
 
        <!--
@@ -83,17 +95,17 @@ If a copy of the MPL was not distributed with this file, You can obtain one at h
                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>
 
        <!--
@@ -101,22 +113,20 @@ If a copy of the MPL was not distributed with this file, You can obtain one at h
                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>&#x0A;</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>&#x0A;</xslt:text>
+                       <xslt:for-each select="$source//*[@slot='shrine-head']">
                                <xslt:apply-templates select="." mode="content"/>
                        </xslt:for-each>
-               </xslt:copy>
+               </head>
        </xslt:template>
 
        <!--
@@ -125,7 +135,7 @@ If a copy of the MPL was not distributed with this file, You can obtain one at h
                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>
@@ -136,7 +146,7 @@ If a copy of the MPL was not distributed with this file, You can obtain one at h
                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>
@@ -145,7 +155,7 @@ If a copy of the MPL was not distributed with this file, You can obtain one at h
                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>
 
        <!--
@@ -161,4 +171,9 @@ If a copy of the MPL was not distributed with this file, You can obtain one at h
                        </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>
This page took 0.039653 seconds and 4 git commands to generate.