diff options
-rw-r--r-- | tools/README | 29 | ||||
-rw-r--r-- | tools/atom-limit.xsl | 27 | ||||
-rw-r--r-- | tools/atom-sort.xsl | 29 | ||||
-rw-r--r-- | tools/html-to-atom-dump.xsl | 110 | ||||
-rwxr-xr-x | tools/html-to-atom.sh | 20 | ||||
-rwxr-xr-x | tools/publish.sh | 40 | ||||
-rw-r--r-- | tools/xml-notes-dump.xsl | 26 | ||||
-rw-r--r-- | tools/xml-notes-limit.xsl | 22 | ||||
-rw-r--r-- | tools/xml-notes-sort.xsl | 32 | ||||
-rw-r--r-- | tools/xml-notes-to-atom.xsl | 73 | ||||
-rwxr-xr-x | tools/xml-to-html.sh | 12 | ||||
-rw-r--r-- | tools/xml-to-html.xsl | 29 |
12 files changed, 236 insertions, 213 deletions
diff --git a/tools/README b/tools/README index 43dfea4..bbd251d 100644 --- a/tools/README +++ b/tools/README @@ -7,8 +7,8 @@ works for now, and is pretty simple. Editing: -- skeleton.xml is the primary skeleton to start with, for *.xhtml - files in ~/homepage/src/. +- skeleton.xml is the primary skeleton to start with, for *.xhtml files + in ~/homepage/src/. This stage is mostly needed to get unified styles, metadata properties, and other bits in case if I'll change them. The same can @@ -19,21 +19,30 @@ Editing is done with the emacs html-mode, with <https://github.com/defanor/html-wysiwyg>. +Indexing: + +- xml-notes-dump.xsl (with some help from publish.sh) is used to + create notes-dump.xml in the build directory. +- xml-notes-sort.xsl sorts that to create + notes-by-publication-date.xml and notes-by-modification-date.xml. +- xml-notes-limit.xsl is used to extract the most recent notes. + + HTML: -- xml-to-html.sh translates source files into actual (X)HTML in - ~/homepage/ by applying xml-to-html.xsl to them. +- xml-to-html.xsl is used to translate source files into actual (X)HTML + in ~/homepage/. + +Indexes can be included into those using the <notes> element (so it +should run after those are built, if they are used). Atom feed: -- html-to-atom-dump.xsl dumps HTML files into a single atom feed. -- atom-sort.xsl sorts those by modification date. -- atom-limit.xsl limits them, taking the newest entries. -- html-to-atom.sh finds source files, and pipes them through the - XSLTs. +- xml-notes-to-atom.xsl translates a dump of notes (such as + notes-by-modification-date.xml) into an atom feed. Publishing: -- publish.sh runs the above two and uploads the files with rsync. +- publish.sh runs all of the above and uploads the files with rsync. diff --git a/tools/atom-limit.xsl b/tools/atom-limit.xsl deleted file mode 100644 index 2b6a285..0000000 --- a/tools/atom-limit.xsl +++ /dev/null @@ -1,27 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" - xmlns:atom="http://www.w3.org/2005/Atom" - xmlns:xhtml="http://www.w3.org/1999/xhtml" - xmlns="http://www.w3.org/2005/Atom" - version="1.0"> - <xsl:output method="xml" indent="yes"/> - - <xsl:template match="/"> - <xsl:apply-templates /> - </xsl:template> - - <xsl:template match="atom:feed"> - <feed> - <xsl:apply-templates select="node()[not(self::atom:entry)]" /> - <!-- Take the top 10 entries. --> - <xsl:apply-templates select="atom:entry[position()<10]" /> - </feed> - </xsl:template> - - <!-- Copy everything else --> - <xsl:template match="node()" priority="0"> - <xsl:copy-of select="." /> - </xsl:template> - -</xsl:stylesheet> diff --git a/tools/atom-sort.xsl b/tools/atom-sort.xsl deleted file mode 100644 index a00b599..0000000 --- a/tools/atom-sort.xsl +++ /dev/null @@ -1,29 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" - xmlns:atom="http://www.w3.org/2005/Atom" - xmlns:xhtml="http://www.w3.org/1999/xhtml" - xmlns="http://www.w3.org/2005/Atom" - version="1.0"> - <xsl:output method="xml" indent="yes"/> - - <xsl:template match="/"> - <xsl:apply-templates /> - </xsl:template> - - <xsl:template match="atom:feed"> - <feed> - <xsl:apply-templates select="node()[not(self::atom:entry)]" /> - <!-- Sort by modification date, descending. --> - <xsl:apply-templates select="atom:entry"> - <xsl:sort select="atom:updated" order="descending"/> - </xsl:apply-templates> - </feed> - </xsl:template> - - <!-- Copy everything else --> - <xsl:template match="node()" priority="0"> - <xsl:copy-of select="." /> - </xsl:template> - -</xsl:stylesheet> diff --git a/tools/html-to-atom-dump.xsl b/tools/html-to-atom-dump.xsl deleted file mode 100644 index fce78a2..0000000 --- a/tools/html-to-atom-dump.xsl +++ /dev/null @@ -1,110 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" - xmlns:atom="http://www.w3.org/2005/Atom" - xmlns:xhtml="http://www.w3.org/1999/xhtml" - xmlns="http://www.w3.org/2005/Atom" - version="1.0"> - <xsl:output method="xml" indent="yes"/> - <xsl:variable name="baseIRI"> - <xsl:text>https://defanor.uberspace.net/</xsl:text> - </xsl:variable> - - <!-- Feed --> - <xsl:template match="/"> - <feed> - <title>defanor's notes</title> - <link rel="self" href="{$baseIRI}atom.xml" /> - <link rel="alternate" href="{$baseIRI}" /> - <id> - <xsl:value-of select="$baseIRI" /> - </id> - <!-- - Setting <updated> statically, since it applies to some - meaningful feed updates. Perhaps should be modified on - metadata changes. - --> - <updated>2018-04-14T10:00:00Z</updated> - <xsl:apply-templates select="/list/entry" /> - </feed> - </xsl:template> - - <!-- Turns index entries into Atom entries --> - <xsl:template match="entry"> - <xsl:variable name="localPath"> - <xsl:text>../</xsl:text> - <xsl:value-of select="@name" /> - </xsl:variable> - <xsl:variable name="doc" select="document($localPath)" /> - <entry> - <link rel="alternate" href="{$baseIRI}{@name}" /> - <id> - <xsl:text>https://defanor.uberspace.net/</xsl:text> - <xsl:value-of select="@name" /> - </id> - <!-- Setting this statically for now. --> - <author> - <name>defanor</name> - </author> - <xsl:apply-templates mode="atom-entry" select="$doc" /> - </entry> - </xsl:template> - - <xsl:template mode="atom-entry" match="/ | xhtml:head | xhtml:html"> - <xsl:apply-templates mode="atom-entry" /> - </xsl:template> - - <!-- Title --> - <xsl:template mode="atom-entry" match="xhtml:title"> - <title> - <xsl:value-of select="." /> - </title> - </xsl:template> - - <!-- Description/summary --> - <xsl:template mode="atom-entry" - match="xhtml:meta[@name='description' or - @property='dc:description schema:description']"> - <summary> - <xsl:value-of select="@content" /> - </summary> - </xsl:template> - - <!-- - Atom is rather strict in its date-time requriements. It's not - always convenient or useful to be that strict in HTML metadata, - so might be better to introduce some check and conversion. - --> - <!-- Publication date --> - <xsl:template mode="atom-entry" - match="xhtml:meta[@property='dc:issued schema:datePublished']"> - <published> - <xsl:value-of select="@content" /> - </published> - </xsl:template> - - <!-- Modification date --> - <xsl:template mode="atom-entry" - match="xhtml:meta[@property='dc:modified schema:dateModified']"> - <updated> - <xsl:value-of select="@content" /> - </updated> - </xsl:template> - - <!-- Body/content --> - <xsl:template mode="atom-entry" match="xhtml:body"> - <content type="xhtml"> - <!-- - "the content of atom:content MUST be a single XHTML div - element" - --> - <xhtml:div> - <xsl:copy-of select="*" /> - </xhtml:div> - </content> - </xsl:template> - - <!-- Skip everything else --> - <xsl:template mode="atom-entry" match="node()" priority="0" /> - -</xsl:stylesheet> diff --git a/tools/html-to-atom.sh b/tools/html-to-atom.sh deleted file mode 100755 index 3bebf45..0000000 --- a/tools/html-to-atom.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh - -# Composes an atom feed out of XHTML files. - -BASEDIR=~/homepage -TOOLS="${BASEDIR}/tools" -SOURCES="${BASEDIR}/src" -ATOM="${BASEDIR}/atom.xml" -NOTES="${BASEDIR}/notes" - -(echo '<?xml version="1.0" encoding="UTF-8"?>' && - echo '<list>' && - find "${NOTES}" -name '*.xhtml' | - # grep -Ev "^(${TOOLS}|${SOURCES}).*" | - sed -e "sS^${BASEDIR}/\(.*\)S<entry name=\"\\1\" />S" && - echo '</list>') | - xsltproc "${TOOLS}/html-to-atom-dump.xsl" - | - xsltproc "${TOOLS}/atom-sort.xsl" - | - xsltproc "${TOOLS}/atom-limit.xsl" - | - xmllint --format --nsclean - > "${ATOM}" diff --git a/tools/publish.sh b/tools/publish.sh index 5a6cbea..c962063 100755 --- a/tools/publish.sh +++ b/tools/publish.sh @@ -1,8 +1,40 @@ #!/bin/sh -TOOLS=~/homepage/tools +BASEDIR=~/homepage +TOOLS="${BASEDIR}/tools" +BUILD="${BASEDIR}/build" +ATOM="${BASEDIR}/atom.xml" +SOURCES="${BASEDIR}/src" +NOTES="${BASEDIR}/notes" -${TOOLS}/xml-to-html.sh -${TOOLS}/html-to-atom.sh -rsync --exclude '.*' --exclude '*.org' --exclude 'src/' --exclude 'tools/' \ + +# dump all the notes into a single file +(echo '<?xml version="1.0" encoding="UTF-8"?>' && + echo '<notes>' && + find "${NOTES}" -name '*.xhtml' | + sed -e "sS^${BASEDIR}/\(.*\)S <note src=\"\\1\" />S" && + echo '</notes>') | + xsltproc -o "${BUILD}/notes-dump.xml" "${TOOLS}/xml-notes-dump.xsl" - + +# sort by publication and modification dates +xsltproc -o "${BUILD}/notes-by-publication-date.xml" \ + "${TOOLS}/xml-notes-sort.xsl" "${BUILD}/notes-dump.xml" +xsltproc -o "${BUILD}/notes-by-modification-date.xml" \ + --stringparam sortBy modified \ + "${TOOLS}/xml-notes-sort.xsl" "${BUILD}/notes-dump.xml" + +# create an atom feed with the most recently modified 10 entries +xsltproc --param number 10 "${TOOLS}/xml-notes-limit.xsl" \ + "${BUILD}/notes-by-modification-date.xml" | + xsltproc -o "${ATOM}" "${TOOLS}/xml-notes-to-atom.xsl" - + +# convert sources into XHTML +find "${SOURCES}" -name '*.xhtml' | + sed -e "sS^${SOURCES}SS" | + xargs -Ifile xsltproc -o "${BASEDIR}/file" \ + "${TOOLS}/xml-to-html.xsl" "${SOURCES}file" + +# upload +rsync --exclude '.*' --exclude '*.org' --exclude 'src/' \ + --exclude 'tools/' --exclude 'build/' \ -avz . uberspace.net:homepage/web/ diff --git a/tools/xml-notes-dump.xsl b/tools/xml-notes-dump.xsl new file mode 100644 index 0000000..79b9606 --- /dev/null +++ b/tools/xml-notes-dump.xsl @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + version="1.0"> + <xsl:output method="xml" indent="yes"/> + + <xsl:template match="note"> + <xsl:variable name="docPath"> + <xsl:text>../src/</xsl:text> + <xsl:value-of select="@src" /> + </xsl:variable> + <xsl:variable name="doc" select="document($docPath)" /> + <xsl:copy> + <xsl:copy-of select="@*" /> + <xsl:copy-of select="$doc" /> + </xsl:copy> + </xsl:template> + + <xsl:template match="node()" priority="0"> + <xsl:copy> + <xsl:copy-of select="@*" /> + <xsl:apply-templates /> + </xsl:copy> + </xsl:template> + +</xsl:stylesheet> diff --git a/tools/xml-notes-limit.xsl b/tools/xml-notes-limit.xsl new file mode 100644 index 0000000..149cbd9 --- /dev/null +++ b/tools/xml-notes-limit.xsl @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + version="1.0"> + <xsl:output method="xml" indent="yes"/> + <xsl:param name="number" /> + + <xsl:template match="notes"> + <xsl:copy> + <xsl:copy-of select="@*" /> + <xsl:apply-templates select="note[position()<=$number]" /> + </xsl:copy> + </xsl:template> + + <xsl:template match="node()" priority="0"> + <xsl:copy> + <xsl:copy-of select="@*" /> + <xsl:apply-templates /> + </xsl:copy> + </xsl:template> + +</xsl:stylesheet> diff --git a/tools/xml-notes-sort.xsl b/tools/xml-notes-sort.xsl new file mode 100644 index 0000000..9d6ac70 --- /dev/null +++ b/tools/xml-notes-sort.xsl @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + version="1.0"> + <xsl:output method="xml" indent="yes"/> + <xsl:param name="sortBy" /> + + <xsl:template match="notes"> + <xsl:copy> + <xsl:copy-of select="@*" /> + <xsl:choose> + <xsl:when test="$sortBy='modified'"> + <xsl:apply-templates select="note"> + <xsl:sort select="document/@modified" order="descending"/> + </xsl:apply-templates> + </xsl:when> + <xsl:otherwise> + <xsl:apply-templates select="note"> + <xsl:sort select="document/@published" order="descending"/> + </xsl:apply-templates> + </xsl:otherwise> + </xsl:choose> + </xsl:copy> + </xsl:template> + + <xsl:template match="node()" priority="0"> + <xsl:copy> + <xsl:copy-of select="@*" /> + <xsl:apply-templates /> + </xsl:copy> + </xsl:template> +</xsl:stylesheet> diff --git a/tools/xml-notes-to-atom.xsl b/tools/xml-notes-to-atom.xsl new file mode 100644 index 0000000..fd18072 --- /dev/null +++ b/tools/xml-notes-to-atom.xsl @@ -0,0 +1,73 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:atom="http://www.w3.org/2005/Atom" + xmlns:xhtml="http://www.w3.org/1999/xhtml" + xmlns="http://www.w3.org/2005/Atom" + version="1.0"> + <xsl:output method="xml" indent="yes"/> + <xsl:variable name="baseIRI"> + <xsl:text>https://defanor.uberspace.net/</xsl:text> + </xsl:variable> + + <xsl:template match="notes"> + <feed> + <title>defanor's notes</title> + <link rel="self" href="{$baseIRI}atom.xml" /> + <link rel="alternate" href="{$baseIRI}" /> + <id> + <xsl:value-of select="$baseIRI" /> + </id> + <!-- + Setting <updated> statically, since it applies to some + meaningful feed updates. Perhaps should be modified on + metadata changes. + --> + <updated>2018-05-01T01:00:00Z</updated> + <xsl:copy-of select="@*" /> + <xsl:apply-templates /> + </feed> + </xsl:template> + + <xsl:template match="note"> + <entry> + <link rel="alternate" href="{$baseIRI}{@src}" /> + <id> + <xsl:text>https://defanor.uberspace.net/</xsl:text> + <xsl:value-of select="@src" /> + </id> + <author> + <name>defanor</name> + </author> + <title> + <xsl:value-of select="document/@title" /> + </title> + <summary> + <xsl:value-of select="document/@description" /> + </summary> + <published> + <xsl:value-of select="document/@published" /> + </published> + <updated> + <xsl:value-of select="document/@modified" /> + </updated> + <content type="xhtml"> + <!-- + "the content of atom:content MUST be a single XHTML div + element" + --> + <xhtml:div xmlns="http://www.w3.org/1999/xhtml"> + <xsl:copy-of select="document/xhtml:body/*" /> + </xhtml:div> + </content> + </entry> + </xsl:template> + + <xsl:template match="node()" priority="0"> + <xsl:copy> + <xsl:copy-of select="@*" /> + <xsl:apply-templates /> + </xsl:copy> + </xsl:template> + +</xsl:stylesheet> diff --git a/tools/xml-to-html.sh b/tools/xml-to-html.sh deleted file mode 100755 index c05d749..0000000 --- a/tools/xml-to-html.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -# Translates simplified documents from src/ - -BASEDIR=~/homepage -TOOLS="${BASEDIR}/tools" -SOURCES="${BASEDIR}/src" - -find "${SOURCES}" -name '*.xhtml' | - sed -e "sS^${SOURCES}SS" | - xargs -Ifile xsltproc -o "${BASEDIR}/file" \ - "${TOOLS}/xml-to-html.xsl" "${SOURCES}file" diff --git a/tools/xml-to-html.xsl b/tools/xml-to-html.xsl index 97e8431..1b92318 100644 --- a/tools/xml-to-html.xsl +++ b/tools/xml-to-html.xsl @@ -77,7 +77,7 @@ href="/xhtml-rdfa-light.css" /> <meta name="robots" content="noarchive" /> </head> - <xsl:copy-of select="xhtml:body" /> + <xsl:apply-templates mode="body" select="xhtml:body" /> </html> </xsl:template> @@ -92,4 +92,31 @@ <xsl:copy-of select="." /> </xsl:template> + <xsl:template mode="body" match="notes"> + <xsl:variable name="notes" select="document(@src)" /> + <xsl:variable name="number" select="@number" /> + <dl> + <xsl:apply-templates mode="note-index" + select="$notes/notes/note[$number=0 or position()<=$number]" /> + </dl> + </xsl:template> + + <xsl:template mode="note-index" match="note"> + <dt> + <a href="{@src}"> + <xsl:value-of select="document/@title" /> + </a> + </dt> + <dd> + <xsl:value-of select="document/@description" /> + </dd> + </xsl:template> + + <xsl:template mode="body" match="node()" priority="0"> + <xsl:copy> + <xsl:copy-of select="@*" /> + <xsl:apply-templates mode="body" /> + </xsl:copy> + </xsl:template> + </xsl:stylesheet> |