Commit 202f5ce9 authored by Carl Schwan's avatar Carl Schwan 🚴

Add information about artifacts in release

parent 3926df67
Pipeline #26259 passed with stage
in 4 minutes and 23 seconds
<?php
/**
* SPDX-FileCopyrightText: 2020 David Barchiesi <david@barchie.si>
* SPDX-FileCopyrightText: 2020 Carl Schwan <carl@carlschwan.eu>
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
......@@ -15,20 +16,26 @@ class Release
/** @var ReleaseType */
private $type;
private $timestamp = null;
private $artifacts = [];
private $url;
public function __construct(string $version, int $type, string $timestamp)
public function __construct(string $version, int $type, string $timestamp, string $url = null, array $artifacts = [])
{
$this->version = $version;
$this->type = $type;
$this->timestamp = $timestamp;
$this->url = $url;
$this->artifacts = $artifacts;
}
public static function fromData(array $release): ?Release
{
$url = isset($release['url']) && isset($release['url']['details']) ? $release['url']['details'] : null;
$artifacts = isset($release['artifacts']) ? $release['artifacts'] : [];
if ($release['type'] === 'stable') {
return new Release($release['version'], ReleaseType::Stable, $release['unix-timestamp']);
return new Release($release['version'], ReleaseType::Stable, $release['unix-timestamp'],$url, $artifacts);
} else if ($release['type'] === 'development') {
return new Release($release['version'], ReleaseType::Development, $release['unix-timestamp']);
return new Release($release['version'], ReleaseType::Development, $release['unix-timestamp'], $url, $artifacts);
} else {
return null;
}
......@@ -58,4 +65,19 @@ class Release
return $this->timestamp;
}
/**
* @return array
*/
public function getArtifacts(): array
{
return $this->artifacts;
}
/**
* @return string|null
*/
public function getUrl(): ?string
{
return $this->url;
}
}
......@@ -17,7 +17,8 @@ class AppTransExtension extends AbstractExtension
public function getFilters()
{
return [
new TwigFilter('l10n', [$this, 'l10n'])
new TwigFilter('l10n', [$this, 'l10n']),
new TwigFilter('size', [$this, 'size']),
];
}
......@@ -48,4 +49,23 @@ class AppTransExtension extends AbstractExtension
}
return $array['C'];
}
/**
* @param int $bytes
* @param int $precision
* @return string
* @throws Error
*/
public function size(int $bytes, int $precision = 2): string
{
$units = array('B', 'KB', 'MB', 'GB', 'TB');
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
$bytes /= pow(1024, $pow);
return round($bytes, $precision) . ' ' . $units[$pow];
}
}
......@@ -102,6 +102,52 @@ SPDX-License-Identifier: AGPL-3.0-or-later
<div>
{{ application.description | l10n(locale) | raw }}
</div>
{% if application.releases | length > 0 %}
<h2>{% trans %}Releases{% endtrans %}</h2>
{% endif %}
{% for release in application.releases %}
<div class="release {% if not loop.first %}d-none{% endif %}">
<h3>{{ release.version }} <small>{{ release.timestamp | format_date('long', locale=locale) }}</small></h3>
{% if release.url %}
<div><a href="{{ release.url}}">Learn more...</a></div>
{% endif %}
{% if release.artifacts | length > 0 %}
{% for artifact in release.artifacts %}
<div class="mb-2 ">
{% set size = "" %}
{% if artifact.size is defined and artifact.size.download %}
{% set size = " (" ~ artifact.size.download | size ~ ")" %}
{% endif %}
{% if artifact.type == "binary" %}
<h4 class="mb-0">
{% if artifact.platform == "x86_64-appimage" or artifact.platform == "x86_64-linux-gnu" %}
{% trans %}AppImage{% endtrans %} - <small>x86_64 {{ size }}</small>
{% elseif artifact.platform == "macOS" %}
{% trans %}macOS{% endtrans %} - <small>x86_64 {{ size }}</small>
{% elseif artifact.platform == "win64" %}
{% trans %}Windows{% endtrans %} - <small>win64 {{ size }}</small>
{% elseif artifact.platform == "win32" %}
{% trans %}Windows{% endtrans %} - <small>win32 {{ size }}</small>
{% endif %}
</h4>
<div><a href="{{ artifact.locations[0] }}">{{ artifact.locations[0] }}</a></div>
{% for algo, checksum in artifact.checksum %}
<div><strong>{{ algo }}:</strong> {{ checksum }}</div>
{% endfor %}
{% else %}
<h4 class="mb-0">Source</h4>
<div><a href="{{ artifact.locations[0] }}">{{ artifact.locations[0] }}</a></div>
{% for algo, checksum in artifact.checksum %}
<strong>{{ algo }}:</strong> {{ checksum }}
{% endfor %}
{% endif %}
</div>
{% endfor %}
{% endif %}
</div>
{% endfor %}
<a class="show-more-release" href="#">Show more releases...</a>
</section>
<aside class="details col-12 col-md-4 col-lg-3">
<h3>{% trans %}Details for %name%{% endtrans %}</h3>
......@@ -266,6 +312,16 @@ AppStream application stores. You can also use your distribution's package manag
</div>
</div>
</main>
<script>
document.querySelector('.show-more-release').addEventListener('click', function(e) {
event.preventDefault();
console.log(event.target);
event.target.classList.add('d-none');
document.querySelectorAll('.release').forEach(function(release) {
release.classList.remove('d-none');
});
});
</script>
{% endblock %}
{% block donation %}#{{ name }}{% endblock %}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment