Skip to content

Commit 66236b0

Browse files
committed
Fix CSV formatting and encoding issues
- Remove blank lines at top of CSV files using Nunjucks whitespace control - Add UTF-8 BOM transform for proper French accent encoding in Excel - Translate content type values in French CSV from English to French: - 'Landing Page' → 'Page d'atterrissage' - 'Content Page' → 'Page de contenu' - 'Link' → 'Lien' This ensures both English and French CSV exports work correctly with proper encoding and localized content.
1 parent 9248f24 commit 66236b0

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

.eleventy.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ module.exports = function (eleventyConfig) {
104104
return content;
105105
});
106106

107+
// Add UTF-8 BOM to CSV files for proper Excel encoding
108+
eleventyConfig.addTransform("csvUtf8Bom", function (content, outputPath) {
109+
if (outputPath && outputPath.endsWith(".csv")) {
110+
// For Excel compatibility, we need to ensure the content is properly encoded
111+
// Try a different approach with UTF-8 BOM and ensure content is UTF-8
112+
const utf8Bom = '\uFEFF'; // Use Unicode BOM character instead of bytes
113+
return utf8Bom + content;
114+
}
115+
return content;
116+
});
117+
107118
eleventyConfig.addFilter("localeMatch", function (collection) {
108119
const { locale } = this.ctx; // avoid retrieving it for each item
109120
return collection.filter((item) => item.data.locale === locale);

src/main/en/pages.csv.njk

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ layout: false
44
eleventyExcludeFromCollections: true
55
date: "git Last Modified"
66
---
7-
{% set roles_data = roles %}
8-
{% macro csv(val) -%}
7+
{%- set roles_data = roles -%}
8+
{%- macro csv(val) -%}
99
"{{ (val | default('') | string | replace('"', '""')) }}"
1010
{%- endmacro -%}
11-
1211
{%- macro listify(val) -%}
1312
{%- if val is defined and val is not none -%}
1413
{%- if val is string -%}
@@ -49,7 +48,6 @@ date: "git Last Modified"
4948
Page
5049
{%- endif -%}
5150
{%- endmacro -%}
52-
5351
Title,URL,Roles (keys),Subjects,Tags,Toggle,Layout,Date Modified,Date Created,Content Type,Source
5452
{% for item in (collections.all | localeMatch('en')) %}
5553
{%- if item.data.permalink != false and not item.data.redirect and not item.inputPath.endsWith('.csv.njk') -%}

src/main/fr/pages.csv.njk

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ layout: false
44
eleventyExcludeFromCollections: true
55
date: "git Last Modified"
66
---
7-
{% set roles_data = roles %}
8-
{% macro csv(val) -%}
7+
{%- set roles_data = roles -%}
8+
{%- macro csv(val) -%}
99
"{{ (val | default('') | string | replace('"', '""')) }}"
1010
{%- endmacro -%}
11-
1211
{%- macro listify(val) -%}
1312
{%- if val is defined and val is not none -%}
1413
{%- if val is string -%}
@@ -40,16 +39,15 @@ date: "git Last Modified"
4039

4140
{%- macro getContentType(inputPath) -%}
4241
{%- if '/main/' in inputPath -%}
43-
Landing Page
42+
Page d'atterrissage
4443
{%- elif '/pages/' in inputPath -%}
45-
Content Page
44+
Page de contenu
4645
{%- elif '/links/' in inputPath -%}
47-
Link
46+
Lien
4847
{%- else -%}
4948
Page
5049
{%- endif -%}
5150
{%- endmacro -%}
52-
5351
Titre,URL,Rôles (clés),Sujets,Étiquettes,Basculer,Mise en page,Date de modification,Date de création,Type de contenu,Source
5452
{% for item in (collections.all | localeMatch('fr')) %}
5553
{%- if item.data.permalink != false and not item.data.redirect and not item.inputPath.endsWith('.csv.njk') -%}

0 commit comments

Comments
 (0)