ansible/roles/mirror/base/files/mirror.xslt

83 lines
3 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:str="http://exslt.org/strings">
<xsl:strip-space elements="*" />
<xsl:template name="size">
<!-- transform a size in bytes into a human readable representation -->
<xsl:param name="bytes"/>
<xsl:choose>
<xsl:when test="$bytes &lt; 1000"><xsl:value-of select="$bytes" />B</xsl:when>
<xsl:when test="$bytes &lt; 1048576"><xsl:value-of select="format-number($bytes div 1024, '0.0')" />K</xsl:when>
<xsl:when test="$bytes &lt; 1073741824"><xsl:value-of select="format-number($bytes div 1048576, '0.0')" />M</xsl:when>
<xsl:otherwise><xsl:value-of select="format-number(($bytes div 1073741824), '0.00')" />G</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="timestamp">
<!-- transform an ISO 8601 timestamp into a human readable representation -->
<xsl:param name="iso-timestamp" />
<xsl:value-of select="concat(substring($iso-timestamp, 0, 11), ' ', substring($iso-timestamp, 12, 5))" />
</xsl:template>
<xsl:template match="directory">
<tr>
<td><a href="{str:encode-uri(current(),true())}/"><xsl:value-of select="."/></a>/</td>
<td><xsl:call-template name="timestamp"><xsl:with-param name="iso-timestamp" select="@mtime" /></xsl:call-template></td>
<td>-</td>
<td>Directory</td>
</tr>
</xsl:template>
<xsl:template match="file">
<tr>
<td><a href="{str:encode-uri(current(),true())}"><xsl:value-of select="." /></a></td>
<td><xsl:call-template name="timestamp"><xsl:with-param name="iso-timestamp" select="@mtime" /></xsl:call-template></td>
<td><xsl:call-template name="size"><xsl:with-param name="bytes" select="@size" /></xsl:call-template></td>
<td>File</td>
</tr>
</xsl:template>
<xsl:template match="/">
<html>
<head>
<title>mirrors.foo.sh - <xsl:value-of select="$path" /></title>
<link rel="stylesheet" type="text/css" href="/static/mirror.css" />
<link rel="stylesheet" type="text/css" href="/static/icons.css" />
</head>
<body>
<div id="navbar">
<div id="logo">
<a href="https://www.foo.sh/"><img src="/static/logo.png" alt="foo.sh" /></a>
</div>
<div class="mirrorlist">
<button class="mirrorlist-button">Select mirror</button>
<div class="mirrorlist-content">
<a href="/fedora/">Fedora</a><span class="hide"> - </span>
<a href="/fedora-epel/">Fedora EPEL</a><span class="hide"> - </span>
<a href="/openbsd/">OpenBSD</a>
</div>
</div>
</div>
<div id="content">
<h1>Index of <xsl:value-of select="$path" /></h1>
<table>
<tr>
<th>Name</th>
<th>Last Modified</th>
<th>Size</th>
<th>Type</th>
</tr>
<tr>
<td colspan="4"><a href="../">Parent Directory</a></td>
</tr>
<xsl:apply-templates />
</table>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>