From 9a1e08fddcf416ee805447d6ef0c2197bd11d98c Mon Sep 17 00:00:00 2001
From: Jean-Baptiste Holcroft <jean-baptiste@holcroft.fr>
Date: Sep 09 2023 14:31:58 +0000
Subject: [PATCH 1/2] restore translation memories


---

diff --git a/build_website.py b/build_website.py
index ab00ca0..65e39dd 100755
--- a/build_website.py
+++ b/build_website.py
@@ -159,7 +159,7 @@ def main():
             generate_territory_index(package_statistics_file, cldr_territories[code], code, cldr_territories_info.get(code, {}), cldr_version)
 
     log.info("Copy translation memories")
-    """languages = [
+    languages = [
         f for f in os.listdir(tm_folder) if os.path.isfile(os.path.join(tm_folder, f))
     ]
     for lang in languages:
@@ -167,7 +167,7 @@ def main():
             shutil.copyfile(
                 os.path.join(tm_folder, lang), os.path.join(static_tm_folder, lang)
             )
-"""
+    
     log.info("done")
 
 

From 259ad21c8c6d2b8e9762c6e026656749d8114674 Mon Sep 17 00:00:00 2001
From: Jean-Baptiste Holcroft <jean-baptiste@holcroft.fr>
Date: Sep 09 2023 14:34:04 +0000
Subject: [PATCH 2/2] allow to sort all tables


add default sorting un python
use global javascript to do so
add class to all tables
use new hugo >= 0.108 to add a class to a block.
Here we add the sortable class by adding {.sortable} the line after the table

---

diff --git a/Dockerfile b/Dockerfile
index d21d76e..80cb12e 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,6 +1,6 @@
-FROM registry.fedoraproject.org/fedora:38
+FROM registry.fedoraproject.org/fedora:39
 
-RUN dnf install -y lbzip2 unzip xz cpio dnf-plugins-core rsync python3-pip hugo gettext git rubygem-asciidoctor glibc-gconv-extra
+RUN dnf install -y lbzip2 unzip xz cpio dnf-plugins-core rsync python3-pip hugo gettext git glibc-gconv-extra
 COPY requirements.txt /src/requirements.txt
 
 RUN pip install --no-cache -r /src/requirements.txt
diff --git a/README.md b/README.md
index f060db3..c3541c7 100644
--- a/README.md
+++ b/README.md
@@ -20,7 +20,7 @@ Please refer to each Fedora package licenses to get all licenses.
 
 ```bash
 dnf install podman
-./runall.sh 34
+./runall.sh 39
 ````
 
 This takes from 10 to 20 hours to process, you may wish to reduce the number of packages to scan.
@@ -29,5 +29,5 @@ To do that, read the `./runall.sh` comments.
 # Run it anywhere
 
 ```bash
-podman run -it --rm -v ./:/src:z -v ./results:/src/results:z -e DNF_CONF=dnf_${release}.conf -e TMP_DIR=/src/results/f${release}/tmp fedlocstats:34 $script
+podman run -it --rm -v ./:/src:z -v ./results:/src/results:z -e DNF_CONF=dnf_${release}.conf -e TMP_DIR=/src/results/f${release}/tmp fedlocstats:39 $script
 ```
diff --git a/build_website.py b/build_website.py
index 65e39dd..6eb47f3 100755
--- a/build_website.py
+++ b/build_website.py
@@ -195,6 +195,9 @@ def generate_static_pages_langs(results: str, code: str, content: dict, destinat
     if len(territories) > 0:
         data["territories"] = territories
 
+    # sort content
+    data["packages"] = sorted(data["packages"].items(), key=lambda x: x[1]['progress'], reverse=True)
+
     apply_jinja_template(data, destination_file, "language.md")
 
 
@@ -223,6 +226,9 @@ def generate_static_pages_packages(release: str, package: str, statistics: dict,
         path = f"./results/{release}/packages/{package}/"
         data["stats"]["languages"][lang]["filename"] = data["stats"]["languages"][lang]["filename"].replace(path, " ")
 
+    # sort content
+    data["stats"]["languages"] = sorted(data["stats"]["languages"].items(), key=lambda x: x[1]['progress'], reverse=True)
+
     apply_jinja_template(data, destination_file, "package.md")
 
 
diff --git a/templates/language.md b/templates/language.md
index ed449ec..32fb6a0 100644
--- a/templates/language.md
+++ b/templates/language.md
@@ -36,12 +36,13 @@ Packages:
 
 | Name |  Translated words | Total source words | Progress (%) | Language teams |
 |------|------------------:|-------------------:|-------------:|----------------|
-{% for package in packages %}
+{% for package, stats in packages %}
 {%- set output = " | [" ~ package ~ "]({{< ref \"/" ~ results ~ "/package/" ~ package ~ ".md\" >}})" -%}
-{%- set output = output ~ " | " ~ packages[package].translatedsourcewords -%}
-{%- set output = output ~ " | " ~ packages[package].totalsourcewordssum -%}
-{%- set output = output ~ " | " ~ '{:.1f}'.format(packages[package].progress) -%}
-{%- set output = output ~ " | " ~ packages[package].team -%}
+{%- set output = output ~ " | " ~ stats.translatedsourcewords -%}
+{%- set output = output ~ " | " ~ stats.totalsourcewordssum -%}
+{%- set output = output ~ " | " ~ '{:.1f}'.format(stats.progress) -%}
+{%- set output = output ~ " | " ~ stats.team -%}
 {%- set output = output ~ " | " -%}
 {{ output }}
-{% endfor -%}
\ No newline at end of file
+{% endfor -%}
+{.sortable}
\ No newline at end of file
diff --git a/templates/package.md b/templates/package.md
index e589cc3..33ecfb0 100644
--- a/templates/package.md
+++ b/templates/package.md
@@ -12,12 +12,13 @@ The package {{ package }}:
 
 | Language | Translated words | Total source words | Progress (%) | Files |
 |----------|-----------------:|-------------------:|-------------:|-------|
-{% for stat in stats.languages|sort -%}
-{%- set output = " | [" ~ stat ~ "]({{< ref \"/" ~ results ~ "/language/" ~ stat ~ ".md\" >}})" -%}
-{%- set output = output ~ " | " ~ stats.languages[stat].translatedsourcewords -%}
-{%- set output = output ~ " | " ~ stats.languages[stat].totalsourcewordssum -%}
-{%- set output = output ~ " | " ~ '{:.1f}'.format(stats.languages[stat].progress) -%}
-{%- set output = output ~ " | " ~ stats.languages[stat].filename -%}
+{% for lang, stat in stats.languages -%}
+{%- set output = " | [" ~ lang ~ "]({{< ref \"/" ~ results ~ "/language/" ~ lang ~ ".md\" >}})" -%}
+{%- set output = output ~ " | " ~ stat.translatedsourcewords -%}
+{%- set output = output ~ " | " ~ stat.totalsourcewordssum -%}
+{%- set output = output ~ " | " ~ '{:.1f}'.format(stat.progress) -%}
+{%- set output = output ~ " | " ~ stat.filename -%}
 {%- set output = output ~ " | " -%}
 {{ output }}
-{% endfor -%}
\ No newline at end of file
+{% endfor -%}
+{.sortable}
\ No newline at end of file
diff --git a/todo.md b/todo.md
index a300187..e2e843a 100644
--- a/todo.md
+++ b/todo.md
@@ -15,14 +15,9 @@ move error detection (check_lang) into %language%/stats.json and display erros
 move error files into %language%/stats.json and make these accessible via website
 remove terminology (someone who wants it can do it locally)
 
-# build_stats.py
-
-when %package%/stats.json is empty, make sure it is counted as an existing package for which we were not able to extract anything (release stats)
-
 # website
 
 list why we could not deduct error files
-allow sort on all tables
 
 # global
 
diff --git a/website/config.toml b/website/config.toml
index 7f37113..b98b170 100644
--- a/website/config.toml
+++ b/website/config.toml
@@ -12,4 +12,12 @@ since = "2021"
 favicon = "img/favicon.ico"
 
 [taxonomies]
-countries = "territories"
\ No newline at end of file
+countries = "territories"
+
+
+[markup]
+  [markup.goldmark]
+    [markup.goldmark.parser]
+      wrapStandAloneImageWithinParagraph = false
+      [markup.goldmark.parser.attribute]
+        block = true
\ No newline at end of file
diff --git a/website/themes/beautifulhugo/layouts/_default/list_languages.html b/website/themes/beautifulhugo/layouts/_default/list_languages.html
index ec74b82..4e862b4 100644
--- a/website/themes/beautifulhugo/layouts/_default/list_languages.html
+++ b/website/themes/beautifulhugo/layouts/_default/list_languages.html
@@ -6,13 +6,13 @@
   <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
   {{ .Content }}
 
-      <table class="contents" id="languages">
+      <table class="contents sortable" id="languages">
           <caption>Click on columns headers to sort values</caption>
       <tr>
-          <th onclick="sortTable(0)">code</th>
-          <th onclick="sortTable(1)">English name</th>
-          <th onclick="sortTable(2)">Local name</th>
-          <th onclick="sortTable(3)">Progress (%)</th>
+          <th>code</th>
+          <th>English name</th>
+          <th>Local name</th>
+          <th>Progress (%)</th>
       </tr>
       {{ range sort .Pages "Title" "asc" }}
         <tr>
@@ -25,60 +25,4 @@
     </table>
   </div>
 </div>
-<script>
-function sortTable(n) {
-  var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0;
-  table = document.getElementById("languages");
-  switching = true;
-  // Set the sorting direction to ascending:
-  dir = "asc";
-  /* Make a loop that will continue until
-  no switching has been done: */
-  while (switching) {
-    // Start by saying: no switching is done:
-    switching = false;
-    rows = table.rows;
-    /* Loop through all table rows (except the
-    first, which contains table headers): */
-    for (i = 1; i < (rows.length - 1); i++) {
-      // Start by saying there should be no switching:
-      shouldSwitch = false;
-      /* Get the two elements you want to compare,
-      one from current row and one from the next: */
-      x = rows[i].getElementsByTagName("TD")[n];
-      y = rows[i + 1].getElementsByTagName("TD")[n];
-      /* Check if the two rows should switch place,
-      based on the direction, asc or desc: */
-      if (dir == "asc") {
-        if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) {
-          // If so, mark as a switch and break the loop:
-          shouldSwitch = true;
-          break;
-        }
-      } else if (dir == "desc") {
-        if (x.innerHTML.toLowerCase() < y.innerHTML.toLowerCase()) {
-          // If so, mark as a switch and break the loop:
-          shouldSwitch = true;
-          break;
-        }
-      }
-    }
-    if (shouldSwitch) {
-      /* If a switch has been marked, make the switch
-      and mark that a switch has been done: */
-      rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
-      switching = true;
-      // Each time a switch is done, increase this count by 1:
-      switchcount ++;
-    } else {
-      /* If no switching has been done AND the direction is "asc",
-      set the direction to "desc" and run the while loop again. */
-      if (switchcount == 0 && dir == "asc") {
-        dir = "desc";
-        switching = true;
-      }
-    }
-  }
-}
-</script>
 {{ end }}
\ No newline at end of file
diff --git a/website/themes/beautifulhugo/layouts/_default/list_packages.html b/website/themes/beautifulhugo/layouts/_default/list_packages.html
index beb53b5..8276d0f 100644
--- a/website/themes/beautifulhugo/layouts/_default/list_packages.html
+++ b/website/themes/beautifulhugo/layouts/_default/list_packages.html
@@ -13,7 +13,7 @@
             <li>No language: number of translation files for which no language could be deducted</li>
           </ul>
       </p>
-          <table class="contents">
+          <table class="contents sortable">
           <tr>
               <th>Package</th>
               <th>Language</th>
diff --git a/website/themes/beautifulhugo/layouts/partials/head_custom.html b/website/themes/beautifulhugo/layouts/partials/head_custom.html
index 833d64a..f727da0 100644
--- a/website/themes/beautifulhugo/layouts/partials/head_custom.html
+++ b/website/themes/beautifulhugo/layouts/partials/head_custom.html
@@ -4,6 +4,7 @@ Do not put anything in this file - it's only here so that hugo won't throw an er
 -->
 <link href="{{ "css/jqvmap.css" | absURL }}" media="screen" rel="stylesheet" type="text/css">
 
+<script type="text/javascript" src="{{ "js/sorttable.js"  | absURL }}"></script>
 <script type="text/javascript" src="{{ "js/jquery.js"  | absURL }}"></script>
 <script type="text/javascript" src="{{ "js/jquery.vmap.js"  | absURL }}"></script>
 <script type="text/javascript" src="{{ "js/jquery.vmap.world.js"  | absURL }}" charset="utf-8"></script>
diff --git a/website/themes/beautifulhugo/layouts/territories/list.html b/website/themes/beautifulhugo/layouts/territories/list.html
index a99eb32..d82182a 100644
--- a/website/themes/beautifulhugo/layouts/territories/list.html
+++ b/website/themes/beautifulhugo/layouts/territories/list.html
@@ -13,7 +13,7 @@
             <li>First Fedora version: first fedora version with at least a partial coverage of this territory</li>
           </ul>
       </p>
-      <table class="contents">
+      <table class="contents sortable">
           <tr>
               <th>Territory</th>
               <th>First Fedora version</th>

