Skip to content

Commit

Permalink
Add Python script to write dynamically courses page
Browse files Browse the repository at this point in the history
  • Loading branch information
webrian committed Oct 14, 2023
1 parent dfd024c commit 482437c
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 53 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
_site/
# Ignore dynamically created includes
_includes/courstable-*
.sass-cache/
.jekyll-cache/
.jekyll-metadata
Expand All @@ -7,4 +9,5 @@ _site/
vendor/bundle
Gemfile
Gemfile.lock
scripts/*
# Ignore temporary files from vim
*.swp
2 changes: 2 additions & 0 deletions _data/kurse-cours.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
date;title_de;title_fr;url
15.11.2023;QGIS Kurs OST;Cours QGIS OST;https://ost.ch
105 changes: 54 additions & 51 deletions _includes/navigation-fr.html
Original file line number Diff line number Diff line change
@@ -1,54 +1,57 @@
<nav class="navbar navbar-expand-md navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<img src="/assets/img/logo.png" alt="Q" width="30" height="24">
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="{% link fr/index.md %}">Home</a>
</li>
<li class="nav-item dropdown">
<a class='nav-link {% if page.url contains "verein" %}active{% endif %} dropdown-toggle' href="{% link fr/association/index.md %}" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Association
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="{% link fr/association/index.md %}">À propos de l'association</a></li>
<li><a class="dropdown-item" href="{% link fr/association/assemblees-generales.md %}">Assemblées Générales</a></li>
</ul>
</li>
<li class="nav-item">
<a class='nav-link {% if page.url contains "news" %} active {% endif %}' href="{% link fr/news/index.md %}">News</a>
</li>
<li class="nav-item dropdown">
<a class='nav-link {% if page.url contains "veranstaltungen" %}active{% endif %} dropdown-toggle' href="{% link fr/reunions/index.md %}" id="navbarDropdownVeranstaltungen" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Réunions
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
{% assign sorted_pages = site.pages | sort:"year" | reverse %}
{% for p in sorted_pages %}
{% if p.path contains "reunions" and p.name != "index.md" %}
<li><a class="dropdown-item" href="{{ p.url }}">{{ p.title }}</a></li>
{% endif %}
{% endfor %}
</ul>
</li>
<li class="nav-item">
<a class='nav-link {% if page.url contains "projets-de-soutien" %}active{% endif %}' href="{% link fr/projets-de-soutien/index.md %}">Projets de soutien</a>
</li>
<li class="nav-item">
<a class='nav-link {% if page.url contains "sujets" %}active{% endif %}' href="{% link fr/sujets/index.md %}">Sujets</a>
</li>
</ul>
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
<li class="nav-item ms-auto">
<a class="nav-link" href="/de/">deutsch</a>
</li>
</ul>
</ul>
<div class="container-fluid">
<a class="navbar-brand" href="#">
<img src="/assets/img/logo.png" alt="Q" width="30" height="24">
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="{% link fr/index.md %}">Home</a>
</li>
<li class="nav-item dropdown">
<a class='nav-link {% if page.url contains "verein" %}active{% endif %} dropdown-toggle' href="{% link fr/association/index.md %}" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Association
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="{% link fr/association/index.md %}">À propos de l'association</a></li>
<li><a class="dropdown-item" href="{% link fr/association/assemblees-generales.md %}">Assemblées Générales</a></li>
</ul>
</li>
<li class="nav-item">
<a class='nav-link {% if page.url contains "news" %} active {% endif %}' href="{% link fr/news/index.md %}">News</a>
</li>
<li class="nav-item dropdown">
<a class='nav-link {% if page.url contains "veranstaltungen" %}active{% endif %} dropdown-toggle' href="{% link fr/reunions/index.md %}" id="navbarDropdownVeranstaltungen" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Réunions
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
{% assign sorted_pages = site.pages | sort:"year" | reverse %}
{% for p in sorted_pages %}
{% if p.path contains "reunions" and p.name != "index.md" %}
<li><a class="dropdown-item" href="{{ p.url }}">{{ p.title }}</a></li>
{% endif %}
{% endfor %}
</ul>
</li>
<li class="nav-item">
<a class='nav-link {% if page.url contains "cours" %}active{% endif %}' href="{% link fr/cours/index.md %}">Cours</a>
</li>
<li class="nav-item">
<a class='nav-link {% if page.url contains "projets-de-soutien" %}active{% endif %}' href="{% link fr/projets-de-soutien/index.md %}">Projets de soutien</a>
</li>
<li class="nav-item">
<a class='nav-link {% if page.url contains "sujets" %}active{% endif %}' href="{% link fr/sujets/index.md %}">Sujets</a>
</li>
</ul>
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
<li class="nav-item ms-auto">
<a class="nav-link" href="/de/">deutsch</a>
</li>
</ul>
</ul>
</div>
</div>
</div>
</nav>
3 changes: 2 additions & 1 deletion de/kurse/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ lang: de

# Aktuelle Kurse

# Vergangene Kurse

{% include courstable-de.html %}
11 changes: 11 additions & 0 deletions fr/cours/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---

layout: plain-fr
lang: fr

---

# Cours Actuels


{% include courstable-fr.html %}
12 changes: 12 additions & 0 deletions scripts/template-de.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<table class="table table-striped-columns">
<tbody>
<tr>
<th>Datum</th><th>Kurzbeschrieb</th><th>Link</th>
</tr>
{% for d in data %}
<tr>
<td>{{ d[0] }}</td><td>{{ d[1] }}</td><td><a href="{{ d[2] }}" class="external-link">{{ d[2] }}</a></td>
</tr>
{% endfor %}
</tbody>
</table>
12 changes: 12 additions & 0 deletions scripts/template-fr.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<table class="table table-striped-columns">
<tbody>
<tr>
<th>Date</th><th>Brève description</th><th>Link</th>
</tr>
{% for d in data %}
<tr>
<td>{{ d[0] }}</td><td>{{ d[1] }}</td><td><a href="{{ d[2] }}" class="external-link">{{ d[2] }}</a></td>
</tr>
{% endfor %}
</tbody>
</table>
37 changes: 37 additions & 0 deletions scripts/write-courses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python3


import csv
import sys
from jinja2 import Environment, FileSystemLoader

def run():

environment = Environment(loader=FileSystemLoader("./"))

for lang in ( {"lang": "de", "dir": "kurse"}, {"lang": "fr", "dir": "cours"} ):
data = []

template = environment.get_template("template-%s.md" % lang['lang'])

filename = "../_includes/courstable-%s.html" % (lang['lang'])

with open("../_data/kurse-cours.csv", newline='') as csvfile:
reader = csv.reader(csvfile, delimiter=";")

# Skip header row
next(reader, None)

for row in reader:
data.append((row[0], row[1], row[2]))

content = template.render(
data=data
)

with open(filename, mode="w", encoding="utf-8") as message:
message.write(content)
print(f"... wrote {filename}")

if __name__ == "__main__":
sys.exit(run())

0 comments on commit 482437c

Please sign in to comment.