From d2a0bc487e27367df9a8a9174be0f0beebbe9c20 Mon Sep 17 00:00:00 2001
From: Jean-Baptiste Holcroft <jean-baptiste@holcroft.fr>
Date: Feb 22 2021 22:55:31 +0000
Subject: [PATCH 1/2] website: simple display of language list


---

diff --git a/build_website.py b/build_website.py
index 464928a..e2d0af3 100755
--- a/build_website.py
+++ b/build_website.py
@@ -166,6 +166,13 @@ def main():
 
         generate_static_pages_packages(args.results, code, content, dest_file)
 
+    log.info("Generating indexes")
+    dest_file = os.path.join(static_langs_folder, "_index.md")
+    generate_language_index(args.results, dest_file)
+
+    dest_file = os.path.join(static_pkgs_folder, "_index.md")
+    generate_package_index(args.results, dest_file)
+
     log.info("Copy translation memories")
     languages = [
         f for f in os.listdir(tm_folder) if os.path.isfile(os.path.join(tm_folder, f))
@@ -383,6 +390,38 @@ def generate_static_pages_packages(results, code, content, dest_file):
         write_out.write(outputText)
 
 
+def generate_language_index(distribution, dest_file):
+    log = logging.getLogger("buildWebsite.generate_language_index")
+    data = dict()
+    data["distribution"] = distribution
+    data["now"] = datetime.datetime.utcnow()
+
+    templateLoader = jinja2.FileSystemLoader(searchpath="./templates/")
+    templateEnv = jinja2.Environment(loader=templateLoader, undefined=jinja2.Undefined)
+    TEMPLATE_FILE = "_index.language.md"
+    template = templateEnv.get_template(TEMPLATE_FILE)
+    outputText = template.render(data)
+
+    with open(dest_file, "w") as write_out:
+        write_out.write(outputText)
+
+
+def generate_package_index(distribution, dest_file):
+    log = logging.getLogger("buildWebsite.generate_package_index")
+    data = dict()
+    data["distribution"] = distribution
+    data["now"] = datetime.datetime.utcnow()
+
+    templateLoader = jinja2.FileSystemLoader(searchpath="./templates/")
+    templateEnv = jinja2.Environment(loader=templateLoader, undefined=jinja2.Undefined)
+    TEMPLATE_FILE = "_index.package.md"
+    template = templateEnv.get_template(TEMPLATE_FILE)
+    outputText = template.render(data)
+
+    with open(dest_file, "w") as write_out:
+        write_out.write(outputText)
+
+
 def store_json_file(content, dest_file):
     with open(dest_file, "w") as f:
         f.write(json.dumps(content, indent=2))
diff --git a/templates/_index.language.md b/templates/_index.language.md
new file mode 100644
index 0000000..bb7141a
--- /dev/null
+++ b/templates/_index.language.md
@@ -0,0 +1,5 @@
+---
+title: "Languages for {{ distribution }}"
+date: {{ now }}
+layout: "list_languages"
+---
\ No newline at end of file
diff --git a/templates/_index.package.md b/templates/_index.package.md
new file mode 100644
index 0000000..a973b26
--- /dev/null
+++ b/templates/_index.package.md
@@ -0,0 +1,4 @@
+---
+title: "Packages for {{ distribution }}"
+date: {{ now }}
+---
\ No newline at end of file
diff --git a/templates/language.md b/templates/language.md
index 9ac40af..622d9d8 100644
--- a/templates/language.md
+++ b/templates/language.md
@@ -1,6 +1,10 @@
 ---
-title: "{{ lang_name_en }} ({{ lang_name_local }})"
+title: "{{ lang_code }}-{{ lang_name_en }} ({{ lang_name_local }})"
 date: {{ now }}
+code: {{ lang_code }}
+name_english: {{ lang_name_en }}
+name_local: {{ lang_name_local }}
+progress_d: {{ progress_d }}
 ---
 
 Language progress for {{ lang_name_en }} ({{ lang_code }}) in Fedora {{ results }} is:
diff --git a/website/config.toml b/website/config.toml
index c777f70..9beb5cf 100644
--- a/website/config.toml
+++ b/website/config.toml
@@ -1,5 +1,8 @@
 baseURL = "https://jibecfed.fedorapeople.org/partage/fedora-localization-statistics/"
 languageCode = "en-us"
-title = "Temporary demo"
+title = "Fedora localization statistics"
 theme = "beautifulhugo"
 staticDir = "static"
+
+[markup.goldmark.renderer]
+unsafe= true
\ No newline at end of file
diff --git a/website/themes/beautifulhugo/layouts/_default/f33.html b/website/themes/beautifulhugo/layouts/_default/f33.html
new file mode 100644
index 0000000..1a00bdc
--- /dev/null
+++ b/website/themes/beautifulhugo/layouts/_default/f33.html
@@ -0,0 +1,12 @@
+{{ define "main" }}
+  <div class="container" role="main">
+      <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
+      {{ .Content }}
+      <ul class="contents">
+          {{ range sort .Pages }}
+              <li><a href="{{ .Permalink }}">{{ .Title }}</a></li>
+          {{ end }}
+          </ul>
+      </div>
+  </div>
+{{ end }}
diff --git a/website/themes/beautifulhugo/layouts/_default/list.html b/website/themes/beautifulhugo/layouts/_default/list.html
index e08da36..5f7bf09 100644
--- a/website/themes/beautifulhugo/layouts/_default/list.html
+++ b/website/themes/beautifulhugo/layouts/_default/list.html
@@ -7,11 +7,6 @@
             {{.}}
           </div>
         {{ end }}
-        <div class="posts-list">
-          {{ range .Paginator.Pages }}
-            {{ partial "post_preview.html" .}}
-          {{ end }}
-        </div>
         {{ if or (.Paginator.HasPrev) (.Paginator.HasNext) }}
           <ul class="pager main-pager">
             {{ if .Paginator.HasPrev }}
diff --git a/website/themes/beautifulhugo/layouts/_default/list_languages.html b/website/themes/beautifulhugo/layouts/_default/list_languages.html
new file mode 100644
index 0000000..42b9620
--- /dev/null
+++ b/website/themes/beautifulhugo/layouts/_default/list_languages.html
@@ -0,0 +1,24 @@
+{{ define "main" }}
+  <div class="container" role="main">
+      <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
+      {{ .Content }}
+
+      <table class="contents">
+          <tr>
+              <th>code</th>
+              <th>English name</th>
+              <th>Local name</th>
+              <th>Progress</th>
+          </tr>
+          {{ range sort .Pages "Title" "asc" }}
+            <tr>
+                <td><a href="{{ .Permalink }}">{{ .Params.code }}</a></td>
+                <td>{{ .Params.name_english }}</td>
+                <td>{{ .Params.name_local }}</td>
+                <td>{{ .Params.progress_d }}</td>
+            </tr>
+          {{ end }}
+      </table>
+      </div>
+  </div>
+{{ end }}
\ No newline at end of file
diff --git a/website/themes/beautifulhugo/layouts/index.html b/website/themes/beautifulhugo/layouts/index.html
index cc15000..bfd14e7 100644
--- a/website/themes/beautifulhugo/layouts/index.html
+++ b/website/themes/beautifulhugo/layouts/index.html
@@ -7,28 +7,11 @@
             {{.}}
           </div>
         {{ end }}
-
-        <div class="posts-list">
-          {{ $pag := .Paginate (where site.RegularPages "Type" "in" site.Params.mainSections) }}
-          {{ range $pag.Pages }}
-            {{ partial "post_preview" . }}
+        <ul class="">
+          {{ range .Site.Sections }}
+            <li><a href="{{ .Permalink }}">{{ .Title }}</a></li>
           {{ end }}
-        </div>
-
-        {{ if or (.Paginator.HasPrev) (.Paginator.HasNext) }}
-          <ul class="pager main-pager">
-            {{ if .Paginator.HasPrev }}
-              <li class="previous">
-                <a href="{{ .Permalink }}page/{{ .Paginator.Prev.PageNumber }}/">&larr; {{ i18n "newerPosts" }}</a>
-              </li>
-            {{ end }}
-            {{ if .Paginator.HasNext }}
-              <li class="next">
-                <a href="{{ .Permalink }}page/{{ .Paginator.Next.PageNumber }}/">{{ i18n "olderPosts" }} &rarr;</a>
-              </li>
-            {{ end }}
-          </ul>
-        {{ end }}
+        </ul>
       </div>
     </div>
   </div>
diff --git a/website/themes/beautifulhugo/layouts/partials/breadcrumb.html b/website/themes/beautifulhugo/layouts/partials/breadcrumb.html
new file mode 100644
index 0000000..62f1b66
--- /dev/null
+++ b/website/themes/beautifulhugo/layouts/partials/breadcrumb.html
@@ -0,0 +1,13 @@
+<ol  class="nav navbar-nav">
+  {{ template "breadcrumbnav" (dict "p1" . "p2" .) }}
+</ol>
+{{ define "breadcrumbnav" }}
+{{ if .p1.Parent }}
+{{ template "breadcrumbnav" (dict "p1" .p1.Parent "p2" .p2 )  }}
+{{ else if not .p1.IsHome }}
+{{ template "breadcrumbnav" (dict "p1" .p1.Site.Home "p2" .p2 )  }}
+{{ end }}
+<li{{ if eq .p1 .p2 }} class="active"{{ end }}>
+  <a href="{{ .p1.Permalink }}">{{ .p1.Title }}</a>
+</li>
+{{ end }}
\ No newline at end of file

From af7f4791cfebf1e0d9833dac954dbc979850528c Mon Sep 17 00:00:00 2001
From: Jean-Baptiste Holcroft <jean-baptiste@holcroft.fr>
Date: Feb 22 2021 23:03:10 +0000
Subject: [PATCH 2/2] website: allow to sort language table


---

diff --git a/website/themes/beautifulhugo/layouts/_default/list_languages.html b/website/themes/beautifulhugo/layouts/_default/list_languages.html
index 42b9620..d108de7 100644
--- a/website/themes/beautifulhugo/layouts/_default/list_languages.html
+++ b/website/themes/beautifulhugo/layouts/_default/list_languages.html
@@ -3,12 +3,13 @@
       <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
       {{ .Content }}
 
-      <table class="contents">
+          <table class="contents" id="languages">
+              <caption>Click on columns headers to sort values</caption>
           <tr>
-              <th>code</th>
-              <th>English name</th>
-              <th>Local name</th>
-              <th>Progress</th>
+              <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>
           </tr>
           {{ range sort .Pages "Title" "asc" }}
             <tr>
@@ -21,4 +22,60 @@
       </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

