#25 Improved way to list results
Merged 3 years ago by jibecfed. Opened 3 years ago by jibecfed.

file modified
+39
@@ -166,6 +166,13 @@ 

  

          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 @@ 

          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))

@@ -0,0 +1,5 @@ 

+ ---

+ title: "Languages for {{ distribution }}"

+ date: {{ now }}

+ layout: "list_languages"

+ --- 

\ No newline at end of file

@@ -0,0 +1,4 @@ 

+ ---

+ title: "Packages for {{ distribution }}"

+ date: {{ now }}

+ --- 

\ No newline at end of file

file modified
+5 -1
@@ -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:

file modified
+4 -1
@@ -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

@@ -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 }}

@@ -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 }}

@@ -0,0 +1,81 @@ 

+ {{ 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" 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>

+           </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>

+ <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

@@ -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>

@@ -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