diff options
author | Nguyễn Gia Phong <mcsinyx@disroot.org> | 2023-01-26 00:30:53 +0900 |
---|---|---|
committer | Nguyễn Gia Phong <mcsinyx@disroot.org> | 2023-01-26 00:54:55 +0900 |
commit | f7720b2207b33fd60ef945662c261c1468e377f7 (patch) | |
tree | b9a05fccca9e8a8a1e5a0fd2d519d0d83f0aa20f | |
parent | 3f8a9cadb778c7a9aa6e4a396cbb3c5ec34ff409 (diff) | |
download | px-f7720b2207b33fd60ef945662c261c1468e377f7.tar.gz |
Add feed and build recipe
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | Makefile | 38 | ||||
-rw-r--r-- | atom.xslt | 59 | ||||
-rw-r--r-- | default.nix | 13 |
4 files changed, 114 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..936e539 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.small.jpg +*/index.xhtml +atom.xml +result diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..dcbd345 --- /dev/null +++ b/Makefile @@ -0,0 +1,38 @@ +# Makefile for px.cnx.gdn +# Copyright (C) 2023 Nguyễn Gia Phong +# +# This program is licensed under CC BY-SA 4.0. + +SHELL = /bin/sh +PREFIX ?= /tmp/px.cnx.gdn + +PICTURES := $(filter-out %.small.jpg $(PREFIX)/%.jpg, $(wildcard */*.jpg)) +THUMBNAILS := $(patsubst %.jpg,%.small.jpg,$(PICTURES)) +DATA := $(wildcard */index.xml) +PAGES := $(patsubst %.xml,%.xhtml,$(DATA)) +OUTPUTS := $(THUMBNAILS) $(PAGES) atom.xml +ALL := $(OUTPUTS) $(PICTURES) index.xhtml favicon.png style.css + +all: $(OUTPUTS) + +%.small.jpg: %.jpg + epeg -w 1024 -p -q 80 $< $@ + +%.xhtml: %.xml page.xslt + xsltproc page.xslt $< > $@ + +atom.xml: atom.xslt $(DATA) $(wildcard *.svg) + xsltproc atom.xslt > atom.xml + +clean: + rm -f atom.xml */{index.xhtml,*.small.jpg} + +$(PREFIX)/%: % + install -Dm644 $< $@ + +install: all $(addprefix $(PREFIX)/,$(ALL)) + +uninstall: + rm -fr $(PREFIX) + +.PHONY: all clean install uninstall diff --git a/atom.xslt b/atom.xslt new file mode 100644 index 0000000..1bb4ecd --- /dev/null +++ b/atom.xslt @@ -0,0 +1,59 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?xml-stylesheet type="text/xsl" href="atom.xslt"?> +<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns="http://www.w3.org/2005/Atom"> + <xsl:output method="xml" indent="yes" encoding="UTF-8"/> + <xsl:variable name="root">https://px.cnx.gdn/</xsl:variable> + <xsl:template match="page"> + <xsl:variable name="base"> + <xsl:value-of select="$root"/> + <xsl:value-of select="@curr"/> + <xsl:text>/</xsl:text> + </xsl:variable> + <xsl:for-each select="post"> + <xsl:variable name="url"> + <xsl:value-of select="$base"/> + <xsl:text>#</xsl:text> + <xsl:value-of select="@id"/> + </xsl:variable> + <entry> + <link rel="alternate" type="application/xhtml+xml" href="{$url}"/> + <id><xsl:value-of select="$url"/></id> + <title><xsl:value-of select="translate(@id, '-', ' ')"/></title> + <content type="xhtml"> + <div xmlns="http://www.w3.org/1999/xhtml"> + <xsl:for-each select="picture"> + <img alt="{@desc}" title="{@desc}" + src="{$base}{@filename}.jpg"/> + </xsl:for-each> + </div> + </content> + <updated><xsl:value-of select="time"/></updated> + </entry> + </xsl:for-each> + </xsl:template> + + <xsl:template match="/"> + <feed xmlns="http://www.w3.org/2005/Atom"> + <link href="{$root}atom.xml" rel="self"/> + <link href="{$root}"/> + <id><xsl:value-of select="$root"/></id> + <icon><xsl:value-of select="$root"/>favicon.png</icon> + + <title>pix by cnx</title> + <author> + <name>Nguyễn Gia Phong</name> + <uri>https://cnx.gdn/</uri> + <email>mcsinyx@disroot.org</email> + </author> + <rights>CC BY-SA 4.0</rights> + <xsl:apply-templates select="document('00/index.xml')/page"> + </xsl:apply-templates> + <xsl:apply-templates select="document('01/index.xml')/page"> + </xsl:apply-templates> + <xsl:apply-templates select="document('02/index.xml')/page"> + </xsl:apply-templates> + <updated>2023-01-25T10:50:00Z</updated> + </feed> + </xsl:template> +</xsl:stylesheet> diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..aba6cf9 --- /dev/null +++ b/default.nix @@ -0,0 +1,13 @@ +{ epeg, lib, libxslt, nix-gitignore, stdenvNoCC }: +stdenvNoCC.mkDerivation rec { + pname = "px.cnx.gdn"; + version = "latest"; + src = nix-gitignore.gitignoreSource [ ] ./.; + makeFlags = [ "PREFIX=$(out)" ]; + buildInputs = [ epeg libxslt ]; + enableParallelBuilding = true; + meta = { + homepage = "https://px.cnx.gdn"; + license = lib.licenses.cc-by-sa-40; + }; +} |