diff options
-rw-r--r-- | pkgs/BuildXSLT.nix | 23 | ||||
-rw-r--r-- | pkgs/InputXSLT.nix | 20 | ||||
-rw-r--r-- | pkgs/StaticXSLT.nix | 23 | ||||
-rw-r--r-- | pkgs/generate.nix | 12 | ||||
-rw-r--r-- | pkgs/preview.nix | 10 | ||||
-rw-r--r-- | shell.nix | 19 | ||||
-rw-r--r-- | source/00_content/meta.xml | 2 | ||||
-rw-r--r-- | utility/date-time.xsl | 243 |
8 files changed, 351 insertions, 1 deletions
diff --git a/pkgs/BuildXSLT.nix b/pkgs/BuildXSLT.nix new file mode 100644 index 0000000..4e5dcb6 --- /dev/null +++ b/pkgs/BuildXSLT.nix @@ -0,0 +1,23 @@ +{ stdenv, fetchFromGitHub }: + +stdenv.mkDerivation rec { + name = "BuildXSLT"; + + src = fetchFromGitHub { + owner = "KnairdA"; + repo = "BuildXSLT"; + rev = "master"; + sha256 = "09kxhvhzn0r62l39zgj1kc21rb565fnc1y3sg48p4gi4v15xjmc6"; + }; + + installPhase = '' + mkdir $out + cp -r * $out/ + ''; + + meta = with stdenv.lib; { + description = "BuildXSLT"; + homepage = https://github.com/KnairdA/BuildXSLT/; + license = stdenv.lib.licenses.mit; + }; +} diff --git a/pkgs/InputXSLT.nix b/pkgs/InputXSLT.nix new file mode 100644 index 0000000..a85bc37 --- /dev/null +++ b/pkgs/InputXSLT.nix @@ -0,0 +1,20 @@ +{ stdenv, fetchFromGitHub, cmake, boost, xalanc, xercesc, discount }: + +stdenv.mkDerivation rec { + name = "InputXSLT"; + + src = fetchFromGitHub { + owner = "KnairdA"; + repo = "InputXSLT"; + rev = "master"; + sha256 = "1j9fld3sh1jyscnsx6ab9jn5x6q67rjh9p3bgsh5na1qrs40dql0"; + }; + + buildInputs = [ cmake boost xalanc xercesc discount ]; + + meta = with stdenv.lib; { + description = "InputXSLT"; + homepage = https://github.com/KnairdA/InputXSLT/; + license = stdenv.lib.licenses.asl20; + }; +} diff --git a/pkgs/StaticXSLT.nix b/pkgs/StaticXSLT.nix new file mode 100644 index 0000000..3caee06 --- /dev/null +++ b/pkgs/StaticXSLT.nix @@ -0,0 +1,23 @@ +{ stdenv, fetchFromGitHub }: + +stdenv.mkDerivation rec { + name = "StaticXSLT"; + + src = fetchFromGitHub { + owner = "KnairdA"; + repo = "StaticXSLT"; + rev = "master"; + sha256 = "17gd181cw9yyc4h1fn7fikcgm8g7fdwm7d7fxwib4aynm18kwqad"; + }; + + installPhase = '' + mkdir $out + cp -r * $out/ + ''; + + meta = with stdenv.lib; { + description = "StaticXSLT"; + homepage = https://github.com/KnairdA/StaticXSLT/; + license = stdenv.lib.licenses.mit; + }; +} diff --git a/pkgs/generate.nix b/pkgs/generate.nix new file mode 100644 index 0000000..25f1ca1 --- /dev/null +++ b/pkgs/generate.nix @@ -0,0 +1,12 @@ +{ pkgs, ... }: + +let + InputXSLT = pkgs.callPackage ./InputXSLT.nix {}; + StaticXSLT = pkgs.callPackage ./StaticXSLT.nix {}; + BuildXSLT = pkgs.callPackage ./BuildXSLT.nix {}; +in pkgs.writeScriptBin + "generate" + '' + #!/bin/sh + ${InputXSLT}/bin/ixslt --input make.xml --transformation ${BuildXSLT}/build.xsl --include ${StaticXSLT}/ + '' diff --git a/pkgs/preview.nix b/pkgs/preview.nix new file mode 100644 index 0000000..352de43 --- /dev/null +++ b/pkgs/preview.nix @@ -0,0 +1,10 @@ +{ pkgs, ... }: + +pkgs.writeScriptBin + "preview" + '' + #!/bin/sh + pushd target/99_result + ${pkgs.python3}/bin/python -m http.server 8080 + popd + '' diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..6f297a7 --- /dev/null +++ b/shell.nix @@ -0,0 +1,19 @@ +with import <nixpkgs> {}; + +stdenv.mkDerivation rec { + name = "env"; + env = buildEnv { name = name; paths = buildInputs; }; + + buildInputs = let + InputXSLT = pkgs.callPackage ./pkgs/InputXSLT.nix {}; + generate = pkgs.callPackage ./pkgs/generate.nix {}; + preview = pkgs.callPackage ./pkgs/preview.nix {}; + in [ + generate + preview + InputXSLT + wget + pandoc + highlight + ]; +} diff --git a/source/00_content/meta.xml b/source/00_content/meta.xml index 3a30727..265d30d 100644 --- a/source/00_content/meta.xml +++ b/source/00_content/meta.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <datasource> <title>kummerlaender.eu</title> - <url>http://localhost:8000</url> + <url>http://localhost:8080</url> <timeline> <commit_count>32</commit_count> </timeline> diff --git a/utility/date-time.xsl b/utility/date-time.xsl new file mode 100644 index 0000000..ed51869 --- /dev/null +++ b/utility/date-time.xsl @@ -0,0 +1,243 @@ +<?xml version="1.0" encoding="utf-8"?> +<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> + +<!-- + +Source: https://www.getsymphony.com/download/xslt-utilities/view/20506/ + +Description: + +This is a date formatting utility. The named template "format-date" takes 2 parameters: + +1. date - [required] takes an ISO date (2005-12-01) +2. format - [optional] takes a format string. + +Format options: + +Y - year in 4 digits e.g. 1981, 1992, 2008 +y - year in 2 digits e.g. 81, 92, 08 +M - month as a full word e.g. January, March, September +m - month in 3 letters e.g. Jan, Mar, Sep +N - month in digits without leading zero +n - month in digits with leading zero +D - day with suffix and no leading zero e.g. 1st, 23rd +d - day in digits with leading zero e.g. 01, 09, 12, 25 +x - day in digits with no leading zero e.g. 1, 9, 12, 25 +T - time in 24-hours e.g. 18:30 +t - time in 12-hours e.g. 6:30pm +W - weekday as a full word e.g. Monday, Tuesday +w - weekday in 3 letters e.g. Mon, Tue, Wed + +Examples: + +M => January +d M => 21 September +m D, y => Sep 21st, 81 +n-d-y => 09-21-81 +d/n/y => 21/09/81 +d/n/y t => 21/09/81 6:30pm + +--> + +<xsl:template name="format-date"> + <xsl:param name="date"/> + <xsl:param name="format" select="'D M, Y'"/> + <xsl:choose> + <xsl:when test="string-length($format) <= 10"> + <xsl:call-template name="date-controller"> + <xsl:with-param name="date" select="$date"/> + <xsl:with-param name="format" select="$format"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise> + <xsl:text>Error: format parameter is not correctly set. You have: </xsl:text> + <xsl:value-of select="string-length($format)"/> + <xsl:text>.</xsl:text> + </xsl:otherwise> + </xsl:choose> +</xsl:template> + +<xsl:template name="date-controller"> + <xsl:param name="date"/> + <xsl:param name="format"/> + <xsl:param name="letter" select="substring($format,1,1)"/> + <xsl:param name="tletter" select="translate($letter,'DMNYTW','dmnytw')"/> + <xsl:choose> + <xsl:when test="$tletter = 'y'"> + <xsl:call-template name="format-year"> + <xsl:with-param name="date" select="$date"/> + <xsl:with-param name="format" select="$letter"/> + </xsl:call-template> + </xsl:when> + <xsl:when test="$tletter = 'm'"> + <xsl:call-template name="format-month"> + <xsl:with-param name="date" select="$date"/> + <xsl:with-param name="format" select="$letter"/> + </xsl:call-template> + </xsl:when> + <xsl:when test="$tletter = 'n'"> + <xsl:call-template name="format-month"> + <xsl:with-param name="date" select="$date"/> + <xsl:with-param name="format" select="$letter"/> + </xsl:call-template> + </xsl:when> + <xsl:when test="$tletter = 'd'"> + <xsl:call-template name="format-day"> + <xsl:with-param name="date" select="$date"/> + <xsl:with-param name="format" select="$letter"/> + </xsl:call-template> + </xsl:when> + <xsl:when test="$tletter = 'x'"> + <xsl:call-template name="format-day"> + <xsl:with-param name="date" select="$date"/> + <xsl:with-param name="format" select="$letter"/> + </xsl:call-template> + </xsl:when> + <xsl:when test="$tletter = 't'"> + <xsl:call-template name="format-time"> + <xsl:with-param name="time" select="$date/@time"/> + <xsl:with-param name="format" select="$letter"/> + </xsl:call-template> + </xsl:when> + <xsl:when test="$tletter = 'w'"> + <xsl:call-template name="format-weekday"> + <xsl:with-param name="weekday" select="$date/@weekday"/> + <xsl:with-param name="format" select="$letter"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="$letter"/> + </xsl:otherwise> + </xsl:choose> + <xsl:if test="$letter = not('')"> + <xsl:call-template name="date-controller"> + <xsl:with-param name="date" select="$date"/> + <xsl:with-param name="format" select="substring($format,2)"/> + </xsl:call-template> + </xsl:if> +</xsl:template> + +<xsl:template name="format-year"> + <xsl:param name="date"/> + <xsl:param name="year" select="substring($date,1,4)"/> + <xsl:param name="format" select="'y'"/> + <xsl:choose> + <xsl:when test="$format = 'y'"> + <xsl:value-of select="substring($year,3)"/> + </xsl:when> + <xsl:when test="$format = 'Y'"> + <xsl:value-of select="$year"/> + </xsl:when> + </xsl:choose> +</xsl:template> + +<xsl:template name="format-month"> + <xsl:param name="date"/> + <xsl:param name="month" select="format-number(substring($date,6,2), '##')"/> + <xsl:param name="format" select="'m'"/> + <xsl:param name="month-word"> + <xsl:choose> + <xsl:when test="$month = 01">January</xsl:when> + <xsl:when test="$month = 02">February</xsl:when> + <xsl:when test="$month = 03">March</xsl:when> + <xsl:when test="$month = 04">April</xsl:when> + <xsl:when test="$month = 05">May</xsl:when> + <xsl:when test="$month = 06">June</xsl:when> + <xsl:when test="$month = 07">July</xsl:when> + <xsl:when test="$month = 08">August</xsl:when> + <xsl:when test="$month = 09">September</xsl:when> + <xsl:when test="$month = 10">October</xsl:when> + <xsl:when test="$month = 11">November</xsl:when> + <xsl:when test="$month = 12">December</xsl:when> + </xsl:choose> + </xsl:param> + <xsl:choose> + <xsl:when test="$format = 'm'"> + <xsl:value-of select="substring($month-word, 1,3)"/> + </xsl:when> + <xsl:when test="$format = 'M'"> + <xsl:value-of select="$month-word"/> + </xsl:when> + <xsl:when test="$format = 'n'"> + <xsl:value-of select="format-number($month, '00')"/> + </xsl:when> + <xsl:when test="$format = 'N'"> + <xsl:value-of select="format-number($month, '0')"/> + </xsl:when> + </xsl:choose> +</xsl:template> + +<xsl:template name="format-day"> + <xsl:param name="date"/> + <xsl:param name="day" select="format-number(substring($date,9,2),'00')"/> + <xsl:param name="format" select="'d'"/> + <xsl:param name="suffix"> + <xsl:choose> + <xsl:when test="(substring($day,2) = 1) and not(substring($day,1,1) = 1)">st</xsl:when> + <xsl:when test="(substring($day,2) = 2) and not(substring($day,1,1) = 1)">nd</xsl:when> + <xsl:when test="(substring($day,2) = 3) and not(substring($day,1,1) = 1)">rd</xsl:when> + <xsl:otherwise>th</xsl:otherwise> + </xsl:choose> + </xsl:param> + <xsl:choose> + <xsl:when test="$format = 'd'"> + <xsl:value-of select="$day"/> + </xsl:when> + <xsl:when test="$format = 'x'"> + <xsl:value-of select="format-number($day,'0')"/> + </xsl:when> + <xsl:when test="$format = 'D'"> + <xsl:value-of select="format-number($day,'0')"/> + <xsl:value-of select="$suffix"/> + </xsl:when> + </xsl:choose> +</xsl:template> + +<xsl:template name="format-time"> + <xsl:param name="time"/> + <xsl:param name="hour" select="substring-before($time, ':')"/> + <xsl:param name="minute" select="substring-after($time, ':')"/> + <xsl:param name="format" select="'T'"/> + <xsl:choose> + <xsl:when test="$format = 'T'"> + <xsl:value-of select="$time"/> + </xsl:when> + <xsl:when test="$format = 't'"> + <xsl:choose> + <xsl:when test="$hour mod 12 = 0">12</xsl:when> + <xsl:otherwise><xsl:value-of select="($hour mod 12)"/></xsl:otherwise> + </xsl:choose> + <xsl:value-of select="concat(':',$minute)"/> + <xsl:choose> + <xsl:when test="$hour < 12">am</xsl:when> + <xsl:otherwise>pm</xsl:otherwise> + </xsl:choose> + </xsl:when> + </xsl:choose> +</xsl:template> + +<xsl:template name="format-weekday"> + <xsl:param name="weekday"/> + <xsl:param name="format" select="'w'"/> + <xsl:param name="result"> + <xsl:choose> + <xsl:when test="$weekday = 1">Monday</xsl:when> + <xsl:when test="$weekday = 2">Tuesday</xsl:when> + <xsl:when test="$weekday = 3">Wednesday</xsl:when> + <xsl:when test="$weekday = 4">Thursday</xsl:when> + <xsl:when test="$weekday = 5">Friday</xsl:when> + <xsl:when test="$weekday = 6">Saturday</xsl:when> + <xsl:when test="$weekday = 7">Sunday</xsl:when> + </xsl:choose> + </xsl:param> + <xsl:choose> + <xsl:when test="$format = 'W'"> + <xsl:value-of select="$result"/> + </xsl:when> + <xsl:when test="$format = 'w'"> + <xsl:value-of select="substring($result,1,3)"/> + </xsl:when> + </xsl:choose> +</xsl:template> + +</xsl:stylesheet> |