Skip to content

Commit 9248f24

Browse files
committed
feat: enhance CSV exports and page table with streamlined structure
- Add CSV download functionality to page list table - Implement git creation dates in CSV exports using computed data - Add new columns: Layout, Date Modified, Date Created, Content Type - Fix Nunjucks template syntax issues with conditional blocks
1 parent 478e9f1 commit 9248f24

File tree

4 files changed

+233
-5
lines changed

4 files changed

+233
-5
lines changed

.eleventy.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,21 @@ module.exports = function (eleventyConfig) {
239239
return md.render(value);
240240
});
241241

242+
// Add split filter for Nunjucks
243+
eleventyConfig.addNunjucksFilter("split", function (str, separator) {
244+
if (typeof str !== 'string') return [];
245+
return str.split(separator || ' ');
246+
});
247+
248+
// Add wordCount filter for convenience
249+
eleventyConfig.addNunjucksFilter("wordCount", function (content) {
250+
if (!content) return 0;
251+
const text = typeof content === 'string' ? content : String(content);
252+
const stripped = stripHtml(text).result;
253+
const words = stripped.trim().split(/\s+/);
254+
return words.length === 1 && words[0] === '' ? 0 : words.length;
255+
});
256+
242257
let changedFilesMap = new Map();
243258
let changedFilePaths = new Set();
244259
let gitChangedUrls = [];
@@ -370,6 +385,26 @@ module.exports = function (eleventyConfig) {
370385
gitChangedUrls = [];
371386
});
372387

388+
// Add computed data for git creation dates
389+
eleventyConfig.addGlobalData("eleventyComputed", {
390+
gitCreated: (data) => {
391+
if (data.page && data.page.inputPath) {
392+
try {
393+
const gitCommand = `git log --format="%ai" --reverse "${data.page.inputPath}" | head -1`;
394+
const result = execSync(gitCommand, { encoding: 'utf8' }).trim();
395+
396+
if (result) {
397+
return new Date(result);
398+
}
399+
} catch (error) {
400+
// Silently handle errors - some files might not have git history
401+
// console.error(`Error getting git creation date for ${data.page.inputPath}:`, error.message);
402+
}
403+
}
404+
return null;
405+
}
406+
});
407+
373408
return {
374409
dir: {
375410
input: "src",

src/_includes/partials/pageListTable.njk

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@
33
</div>
44
<div class="container-fluid">
55
<p><a href="#full-screen" aria-controls="full-screen" class="overlay-lnk btn btn-primary btn-block" role="button">{{ pageList[locale].definitionButtonText }}</a></p>
6+
7+
<!-- CSV Download Button -->
8+
<div class="mrgn-bttm-md">
9+
<a href="{{ pathPrefix }}/docs/pages-{{ locale }}.csv" download class="btn btn-default">
10+
<i class="fas fa-download" aria-hidden="true"></i>
11+
{% if locale === "en" %}
12+
Download CSV Export
13+
{% else %}
14+
Télécharger l'export CSV
15+
{% endif %}
16+
</a>
17+
</div>
618
<section id="full-screen" class="wb-overlay modal-content overlay-def wb-popup-full">
719
<header class="modal-header">
820
<h2>{{ pageList[locale].definitionButtonText }}</h2>
@@ -73,12 +85,27 @@
7385
</li>
7486
<li class="checkbox">
7587
<label>
76-
<input type="checkbox" name="columns" class="wb-tagfilter-ctrl" value="col_6" checked> {% if locale === "en" %}Description present?{% else %}Description présente ?{% endif %}
88+
<input type="checkbox" name="columns" class="wb-tagfilter-ctrl" value="col_6" checked> {% if locale === "en" %}Layout{% else %}Mise en page{% endif %}
89+
</label>
90+
</li>
91+
<li class="checkbox">
92+
<label>
93+
<input type="checkbox" name="columns" class="wb-tagfilter-ctrl" value="col_7" checked> {% if locale === "en" %}Date Modified{% else %}Date de modification{% endif %}
94+
</label>
95+
</li>
96+
<li class="checkbox">
97+
<label>
98+
<input type="checkbox" name="columns" class="wb-tagfilter-ctrl" value="col_8" checked> {% if locale === "en" %}Date Created{% else %}Date de création{% endif %}
7799
</label>
78100
</li>
79101
<li class="checkbox">
80102
<label>
81-
<input type="checkbox" name="columns" class="wb-tagfilter-ctrl" value="col_7" checked> {% if locale === "en" %}Link to file{% else %}Lien vers le fichier{% endif %}
103+
<input type="checkbox" name="columns" class="wb-tagfilter-ctrl" value="col_9" checked> {% if locale === "en" %}Content Type{% else %}Type de contenu{% endif %}
104+
</label>
105+
</li>
106+
<li class="checkbox">
107+
<label>
108+
<input type="checkbox" name="columns" class="wb-tagfilter-ctrl" value="col_10" checked> {% if locale === "en" %}Link to file{% else %}Lien vers le fichier{% endif %}
82109
</label>
83110
</li>
84111
<li class="checkbox">
@@ -95,15 +122,19 @@
95122
</fieldset>
96123
</div>
97124

98-
<table class="wb-tagfilter-items table table-bordered">
125+
<table class="wb-tagfilter-items table table-bordered wb-tables table-hover filterEmphasis provisional">
99126
<thead>
100127
<tr>
101128
<th data-wb-tags="col_1">{% if locale === "en" %}Title{% else %}Titre{% endif %}</th>
102129
<th data-wb-tags="col_2">{% if locale === "en" %}Other language link{% else %}Lien vers d'autres langues{% endif %}</th>
103130
<th data-wb-tags="col_3">{{ pageList[locale].tagsText }}</th>
104131
<th data-wb-tags="col_4">{{ pageList[locale].subjectsText }}</th>
105132
<th data-wb-tags="col_5">{% if locale === "en" %}Role{% else %}Rôle{% endif %}</th>
106-
<th data-wb-tags="col_7">{% if locale === "en" %}Link to file{% else %}Lien vers le fichier{% endif %}</th>
133+
<th data-wb-tags="col_6">{% if locale === "en" %}Layout{% else %}Mise en page{% endif %}</th>
134+
<th data-wb-tags="col_7">{% if locale === "en" %}Date Modified{% else %}Date de modification{% endif %}</th>
135+
<th data-wb-tags="col_8">{% if locale === "en" %}Date Created{% else %}Date de création{% endif %}</th>
136+
<th data-wb-tags="col_9">{% if locale === "en" %}Content Type{% else %}Type de contenu{% endif %}</th>
137+
<th data-wb-tags="col_10">{% if locale === "en" %}Link to file{% else %}Lien vers le fichier{% endif %}</th>
107138
</tr>
108139
</thead>
109140
<tbody>
@@ -117,8 +148,34 @@
117148
{% else %}
118149
{% set missingToggle = "Version anglais manquante" %}
119150
{% endif %}
151+
{% if '/main/' in entry.inputPath %}
152+
{% if locale === "en" %}
153+
{% set contentType = "Landing Page" %}
154+
{% else %}
155+
{% set contentType = "Page d'atterrissage" %}
156+
{% endif %}
157+
{% elif '/pages/' in entry.inputPath %}
158+
{% if locale === "en" %}
159+
{% set contentType = "Content Page" %}
160+
{% else %}
161+
{% set contentType = "Page de contenu" %}
162+
{% endif %}
163+
{% elif '/links/' in entry.inputPath %}
164+
{% if locale === "en" %}
165+
{% set contentType = "Link" %}
166+
{% else %}
167+
{% set contentType = "Lien" %}
168+
{% endif %}
169+
{% else %}
170+
{% if locale === "en" %}
171+
{% set contentType = "Page" %}
172+
{% else %}
173+
{% set contentType = "Page" %}
174+
{% endif %}
175+
{% endif %}
120176
{% if entry.data.locale == locale %}
121177
{% if entry.data.redirect %}
178+
{% elif entry.inputPath.endsWith('.csv.njk') %}
122179
{% else %}
123180
<tr{% for items in isLanding[6] %}{% if items === "m" %} class="success" data-wb-tags="isLanding"{% else %} data-wb-tags="isPage"{% endif %}{% endfor %}>
124181
<td data-wb-tags="col_1">
@@ -144,7 +201,11 @@
144201
{% endfor %}
145202
{% endif %}
146203
</td>
147-
<td data-wb-tags="col_7"><code><a href="https://github.com/gc-da11yn/gc-da11yn.github.io/tree/{{ branch }}{{ newPath }}">{{ newPath }}</a></code></td>
204+
<td data-wb-tags="col_6">{{ entry.data.layout or "" }}</td>
205+
<td data-wb-tags="col_7">{{ entry.date | postDate if entry.date else "" }}</td>
206+
<td data-wb-tags="col_8">{{ entry.data.gitCreated | postDate if entry.data.gitCreated else "" }}</td>
207+
<td data-wb-tags="col_9">{{ contentType }}</td>
208+
<td data-wb-tags="col_10"><code><a href="https://github.com/gc-da11yn/gc-da11yn.github.io/tree/{{ branch }}{{ newPath }}">{{ newPath }}</a></code></td>
148209
</tr>
149210
{% endif %}
150211
{% endif %}

src/main/en/pages.csv.njk

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
permalink: "/docs/pages-en.csv"
3+
layout: false
4+
eleventyExcludeFromCollections: true
5+
date: "git Last Modified"
6+
---
7+
{% set roles_data = roles %}
8+
{% macro csv(val) -%}
9+
"{{ (val | default('') | string | replace('"', '""')) }}"
10+
{%- endmacro -%}
11+
12+
{%- macro listify(val) -%}
13+
{%- if val is defined and val is not none -%}
14+
{%- if val is string -%}
15+
{{ val }}
16+
{%- elif val is iterable -%}
17+
{{ val | join('; ') }}
18+
{%- endif -%}
19+
{%- endif -%}
20+
{%- endmacro -%}
21+
22+
{%- macro roleLabels(val, locale) -%}
23+
{%- if val is defined and val is not none -%}
24+
{%- if val is string -%}
25+
{{ roles_data.labels[locale][val] or val }}
26+
{%- elif val is iterable -%}
27+
{%- set labelList = "" -%}
28+
{%- for item in val -%}
29+
{%- set label = roles_data.labels[locale][item] or item -%}
30+
{%- if loop.first -%}
31+
{%- set labelList = label -%}
32+
{%- else -%}
33+
{%- set labelList = labelList + "; " + label -%}
34+
{%- endif -%}
35+
{%- endfor -%}
36+
{{ labelList }}
37+
{%- endif -%}
38+
{%- endif -%}
39+
{%- endmacro -%}
40+
41+
{%- macro getContentType(inputPath) -%}
42+
{%- if '/main/' in inputPath -%}
43+
Landing Page
44+
{%- elif '/pages/' in inputPath -%}
45+
Content Page
46+
{%- elif '/links/' in inputPath -%}
47+
Link
48+
{%- else -%}
49+
Page
50+
{%- endif -%}
51+
{%- endmacro -%}
52+
53+
Title,URL,Roles (keys),Subjects,Tags,Toggle,Layout,Date Modified,Date Created,Content Type,Source
54+
{% for item in (collections.all | localeMatch('en')) %}
55+
{%- if item.data.permalink != false and not item.data.redirect and not item.inputPath.endsWith('.csv.njk') -%}
56+
{%- set roleVal = item.data.role -%}
57+
{%- set subjectsVal = item.data.subjects or item.data.subject -%}
58+
{%- set tagsVal = item.data.tags -%}
59+
{%- set toggleVal = item.data.toggle -%}
60+
{%- set urlVal = item.url -%}
61+
{%- set layoutVal = item.data.layout -%}
62+
{%- set modifiedVal = item.date | postDate -%}
63+
{%- set createdVal = item.data.gitCreated | postDate if item.data.gitCreated else settings.dateCreated -%}
64+
{{ csv(item.data.title | striptags) }},{{ csv(urlVal) }},{{ csv(listify(roleVal)) }},{{ csv(listify(subjectsVal)) }},{{ csv(listify(tagsVal)) }},{{ csv(toggleVal) }},{{ csv(layoutVal) }},{{ csv(modifiedVal) }},{{ csv(createdVal) }},{{ csv(getContentType(item.inputPath)) }},{{ csv(item.inputPath) }}
65+
{% endif -%}
66+
{%- endfor %}

src/main/fr/pages.csv.njk

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
permalink: "/docs/pages-fr.csv"
3+
layout: false
4+
eleventyExcludeFromCollections: true
5+
date: "git Last Modified"
6+
---
7+
{% set roles_data = roles %}
8+
{% macro csv(val) -%}
9+
"{{ (val | default('') | string | replace('"', '""')) }}"
10+
{%- endmacro -%}
11+
12+
{%- macro listify(val) -%}
13+
{%- if val is defined and val is not none -%}
14+
{%- if val is string -%}
15+
{{ val }}
16+
{%- elif val is iterable -%}
17+
{{ val | join('; ') }}
18+
{%- endif -%}
19+
{%- endif -%}
20+
{%- endmacro -%}
21+
22+
{%- macro roleLabels(val, locale) -%}
23+
{%- if val is defined and val is not none -%}
24+
{%- if val is string -%}
25+
{{ roles_data.labels[locale][val] or val }}
26+
{%- elif val is iterable -%}
27+
{%- set labelList = "" -%}
28+
{%- for item in val -%}
29+
{%- set label = roles_data.labels[locale][item] or item -%}
30+
{%- if loop.first -%}
31+
{%- set labelList = label -%}
32+
{%- else -%}
33+
{%- set labelList = labelList + "; " + label -%}
34+
{%- endif -%}
35+
{%- endfor -%}
36+
{{ labelList }}
37+
{%- endif -%}
38+
{%- endif -%}
39+
{%- endmacro -%}
40+
41+
{%- macro getContentType(inputPath) -%}
42+
{%- if '/main/' in inputPath -%}
43+
Landing Page
44+
{%- elif '/pages/' in inputPath -%}
45+
Content Page
46+
{%- elif '/links/' in inputPath -%}
47+
Link
48+
{%- else -%}
49+
Page
50+
{%- endif -%}
51+
{%- endmacro -%}
52+
53+
Titre,URL,Rôles (clés),Sujets,Étiquettes,Basculer,Mise en page,Date de modification,Date de création,Type de contenu,Source
54+
{% for item in (collections.all | localeMatch('fr')) %}
55+
{%- if item.data.permalink != false and not item.data.redirect and not item.inputPath.endsWith('.csv.njk') -%}
56+
{%- set roleVal = item.data.role -%}
57+
{%- set subjectsVal = item.data.subjects or item.data.subject -%}
58+
{%- set tagsVal = item.data.tags -%}
59+
{%- set toggleVal = item.data.toggle -%}
60+
{%- set urlVal = item.url -%}
61+
{%- set layoutVal = item.data.layout -%}
62+
{%- set modifiedVal = item.date | postDate -%}
63+
{%- set createdVal = item.data.gitCreated | postDate if item.data.gitCreated else settings.dateCreated -%}
64+
{{ csv(item.data.title | striptags) }},{{ csv(urlVal) }},{{ csv(listify(roleVal)) }},{{ csv(listify(subjectsVal)) }},{{ csv(listify(tagsVal)) }},{{ csv(toggleVal) }},{{ csv(layoutVal) }},{{ csv(modifiedVal) }},{{ csv(createdVal) }},{{ csv(getContentType(item.inputPath)) }},{{ csv(item.inputPath) }}
65+
{% endif -%}
66+
{%- endfor %}

0 commit comments

Comments
 (0)