Skip to content

Commit

Permalink
Add: downloads pages, and links from header/index to them
Browse files Browse the repository at this point in the history
When the docker is build, information is downloaded (via HTTP) from
finger.openttd.org and binaries.openttd.org to figure out what
the available downloads are, and those are added to the collection.
Jekyll after that makes this into static files.

Yes, this does mean we have to rebuild this container every time
we make a new release. But those events are rare.
  • Loading branch information
TrueBrain committed Jan 4, 2019
1 parent 58dfee9 commit be4ee59
Show file tree
Hide file tree
Showing 28 changed files with 527 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.git/**
_downloads/**
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length = 120
inline-quotes = double
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
_site
.sass-cache
.jekyll-metadata
_downloads/**
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# This is a multi-stage Docker build

# Create the downloads collection
FROM python:3.6-alpine as collection

WORKDIR /source/

COPY . /source/
RUN pip install -r requirements.txt
# Validate that what was installed was what was expected
RUN pip freeze 2>/dev/null | grep -v "deployer" > requirements.installed \
&& diff -u requirements.txt requirements.installed 1>&2 \
|| ( echo "!! ERROR !! requirements.txt defined different packages or versions for installation" \
&& exit 1 ) 1>&2
RUN pip install flake8

COPY .flake8 .flake8
RUN flake8 fetch-downloads.py

RUN python fetch-downloads.py

# Build the HTML from the source
FROM alpine as html

Expand All @@ -25,6 +44,7 @@ RUN apk --no-cache add \
ruby-dev

COPY . /source/
COPY --from=collection /source/_downloads /source/_downloads

RUN mkdir /html \
&& jekyll build --strict_front_matter -s /source -d /html
Expand Down
14 changes: 12 additions & 2 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ description: >- # this means to ignore newlines until "baseurl:"
An open source simulator based on the classic game Transport Tycoon Deluxe. It attempts to mimic the original game as closely as possible while extending it with new features.
baseurl: ""
url: ""
timezone: Etc/UTC

markdown: kramdown
plugins:
Expand All @@ -20,6 +21,11 @@ defaults:
path: ""
values:
layout: "default"
- scope:
path: ""
type: "downloads"
values:
layout: "download"
- scope:
path: ""
type: "posts"
Expand All @@ -32,10 +38,14 @@ defaults:
layout: "screenshot"

collections:
posts:
permalink: /news/:year/:month/:day/:title.html
downloads:
output: true
download-meta:
output: false
people:
output: false
posts:
permalink: /news/:year/:month/:day/:title.html
screenshots:
output: true

Expand Down
3 changes: 3 additions & 0 deletions _download-meta/catcodec-releases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
folder: extra/catcodec
---
3 changes: 3 additions & 0 deletions _download-meta/grfcodec-nightlies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
folder: extra/grfcodec-trunk
---
3 changes: 3 additions & 0 deletions _download-meta/grfcodec-releases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
folder: extra/grfcodec
---
3 changes: 3 additions & 0 deletions _download-meta/nosound-releases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
folder: extra/nosound
---
3 changes: 3 additions & 0 deletions _download-meta/opengfx-releases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
folder: extra/opengfx
---
3 changes: 3 additions & 0 deletions _download-meta/openmsx-releases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
folder: extra/openmsx
---
3 changes: 3 additions & 0 deletions _download-meta/opensfx-releases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
folder: extra/opensfx
---
10 changes: 10 additions & 0 deletions _download-meta/openttd-nightlies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
folder: nightlies/trunk
---

For OpenTTD you can use the original Transport Tycoon Deluxe data files (you need to own a Transport Tycoon Deluxe CD).
There are also the free alternatives: [OpenGFX (graphics)](http://dev.openttdcoop.org/projects/opengfx), [OpenSFX (sound)](http://dev.openttdcoop.org/projects/opensfx), and [OpenMSX (music)](http://dev.openttdcoop.org/projects/openmsx).
These can be installed automatically by the Windows and OS/2 installers.
Please refer to the [readme](https://binaries.openttd.org/nightlies/trunk/@@version@@/readme.txt) for more information.

You can download the free alternatives here: [download OpenGFX](../opengfx-releases/), [download OpenSFX](../opensfx-releases/), and [download OpenMSX](../openmsx-releases/).
10 changes: 10 additions & 0 deletions _download-meta/openttd-releases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
folder: releases
---

For OpenTTD you can use the original Transport Tycoon Deluxe data files (you need to own a Transport Tycoon Deluxe CD).
There are also the free alternatives: [OpenGFX (graphics)](http://dev.openttdcoop.org/projects/opengfx), [OpenSFX (sound)](http://dev.openttdcoop.org/projects/opensfx), and [OpenMSX (music)](http://dev.openttdcoop.org/projects/openmsx).
These can be installed automatically by the Windows and OS/2 installers.
Please refer to the [readme](https://binaries.openttd.org/releases/@@version@@/readme.txt) for more information.

You can download the free alternatives here: [download OpenGFX](../opengfx-releases/), [download OpenSFX](../opensfx-releases/), and [download OpenMSX](../openmsx-releases/).
3 changes: 3 additions & 0 deletions _download-meta/openttd-useful.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
folder: extra/openttd-useful
---
3 changes: 3 additions & 0 deletions _download-meta/osie-releases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
folder: extra/osie
---
3 changes: 3 additions & 0 deletions _download-meta/pngcodec-releases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
folder: extra/pngcodec
---
3 changes: 3 additions & 0 deletions _download-meta/strgen-releases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
folder: extra/strgen
---
22 changes: 20 additions & 2 deletions _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,33 @@
<link rel="stylesheet" href="{{ base }}/static/css/base.css" type="text/css" />
<link rel="stylesheet" href="{{ base }}/static/css/page.css" type="text/css" />
<link rel="stylesheet" href="{{ base }}/static/css/index.css" type="text/css" />
{% for filename in layout.css %}
<link rel="stylesheet" href="{{ base }}/static/css/{{ filename }}" type="text/css" />
{% endfor %}
{% for filename in layout.js %}
<script type="text/javascript" src="{{ base }}/static/js/{{ filename }}"></script>
{% endfor %}
<title>OpenTTD {% if layout.section_title != nil %}| {{layout.section_title}}{% endif %} | {{ page.title }}</title>
</head>
<body>
<div id="header">
{% assign latest_stable = site.downloads | where_exp: "download", "download.id contains '/downloads/openttd-releases/'" | where: "name", "stable" | sort: "date" | last %}
{% assign latest_testing = site.downloads | where_exp: "download", "download.id contains '/downloads/openttd-releases/'" | where: "name", "testing" | sort: "date" | last %}
{% assign latest_nightly = site.downloads | where_exp: "download", "download.id contains '/downloads/openttd-nightlies/'" | sort: "date" | last %}

<div id="header-left"></div>
<div id="header-right"></div>

{% if latest_stable.date < latest_testing.date %}
<div id="download-fast-3">
{% else %}
<div id="download-fast-2">
<h5><a href="https://www.openttd.org/en/download-stable">CABBAGE stable (1.8.0)</a></h5>
<h5><a href="https://www.openttd.org/en/download-trunk">CABBAGE nightly (r28004)</a></h5>
{% endif %}
<h5><a href="{{ base }}{{ latest_stable.url }}">Download stable ({{ latest_stable.id | split: "/" | last }})</a></h5>
{% if latest_stable.date < latest_testing.date %}
<h5><a href="{{ base }}{{ latest_testing.url }}">Download testing ({{ latest_testing.id | split: "/" | last }})</a></h5>
{% endif %}
<h5><a href="{{ base }}{{ latest_nightly.url }}">Download nightly ({{ latest_nightly.id | split: "/" | last }})</a></h5>
</div>
<div id="header-logo">
<div id="openttd-logo">
Expand Down
62 changes: 62 additions & 0 deletions _layouts/download.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
layout: default
section_title: Download
css:
- download.css
js:
- download.js
---

{% assign raw_type = page.id | split: "/" | slice: 2 | first %}
{% assign type = raw_type | prepend: "/download-meta/" %}
{% assign meta = site.download-meta | where: "id", type | first %}
{% assign version = page.id | split: "/" | last %}

{% unless meta.id %}
{{ "No download-meta entry found for " | append: raw_type | raise_error }}
{% endunless %}

<div id="section-full">
<div class="section-header">
<div class="section-icon"></div>
<h3>Download</h3>
</div>
<div class="section-item">
<div class="content">
{{ meta.content | markdownify | replace: "@@version@@", version }}
<p>For all binaries officially released by us we publish the MD5, SHA1, and SHA256 checksums. You can use these checksums to check whether the file you downloaded has been modified. All three checksums should match the file you downloaded; if this is not the case it means that either the file didn't come from us or that it got broken during transport. Either way it might possibly contain dangerous modifications and the file should therefore not be trusted!</p>
</div>
</div>
<div class="section-header">
<div class="section-icon"></div>
<h3>Download {{ page.name }}</h3>
</div>
<div class="section-item">
<div class="content">
<p>Latest release in {{ page.name }} is {{ version }}, released on {{ page.date | date: "%Y-%m-%d %H:%M" }} UTC.</p>

<div class="changelog">[ <a href="https://binaries.openttd.org/{{ meta.folder }}/{{ version }}/changelog.txt">Changelog</a> ]</div>
<div id="download-combo">
<input type="hidden" id="download-combo-state" value="" />
<input type="hidden" id="download-base-name" value="{{ page.base }}" />
</div>

<ul id="download-data">
{% for file in page.files %}
<li id="{{ file.id }}">
<div class="filename"><a href="https://binaries.openttd.org/{{ meta.folder }}/{{ version }}/{{ file.id }}">{{ file.name }}</a></div>
<div class="filesize">[ {{ file.size | string_of_size }} ]</div>
<div class="checksums-dropdown" onclick="toggleChecksum(this, 'checksum-{{ file.id }}')">[ <a href="#" onclick="return false;">Checksums</a> ]</div>
<div class="checksums" id="checksum-{{ file.id }}">
md5sum&nbsp;&nbsp;&nbsp;: {{ file.md5sum }}<br />
sha1sum&nbsp;&nbsp;: {{ file.sha1sum }}<br />
sha256sum: {{ file.sha256sum }}<br />
</div>
</li>
{% endfor %}
</ul>
</div>

<script type="text/javascript">updateCombo(document.getElementById("download-data"));</script>
</div>
</div>
34 changes: 34 additions & 0 deletions _plugins/openttd-filters.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module Jekyll
module OpenTTDFilters

# Code taken from (and slightly modified)
# https://github.com/jekyll-octopod/jekyll-octopod/blob/master/lib/jekyll/octopod_filters.rb
# jekyll-octopod is licensed under MIT.
def string_of_size(bytes)
bytes = bytes.to_i.to_f
out = '0'
return out if bytes == 0.0

jedec = %w[b K M G]
[3, 2, 1, 0].each { |i|
if bytes > 1024 ** i
out = "%.1f #{jedec[i]}iB" % (bytes / 1024 ** i)
break
end
}

return out
end

# Code taken from
# http://talk.jekyllrb.com/t/how-to-properly-indicate-an-error-during-site-generation/447
# Unlicensed; appears to be free to use.
def raise_error(msg)
bad_file = @context.registers[:page]['path']
err_msg = "On #{bad_file}: #{msg}"
raise err_msg
end
end
end

Liquid::Template.register_filter(Jekyll::OpenTTDFilters)
3 changes: 2 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ jobs:
- script: |
set -e
VERSION=$(git describe --tags)
echo "${VERSION}"
DATE=$(date +%Y%m%d-%H%M)
echo "${VERSION}-${DATE}"
echo "##vso[build.updatebuildnumber]${VERSION}"
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
displayName: 'Use "git describe" as BuildNumber'
Expand Down
Loading

0 comments on commit be4ee59

Please sign in to comment.