Skip to content

Commit 0d2f545

Browse files
committed
feat: allow comments in volunteer data
1 parent 0ef3e86 commit 0d2f545

3 files changed

Lines changed: 48 additions & 11 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ arquivos estáticos, incluindo GitHub Pages.
1818
Os arquivos abaixo são copiados para o site sem transformação. Não é preciso
1919
editar HTML, CSS ou JavaScript para alterar as listas:
2020

21-
- `data/members.json` — pessoas voluntárias, atuais e ex-voluntárias;
21+
- `data/members.jsonc` — pessoas voluntárias, atuais e ex-voluntárias. Aceita
22+
comentários com `//`;
2223
- `data/posts.json` — posts do blog (opcional);
2324
- `data/projects.json` — projetos da comunidade (opcional);
2425
- `data/site.json` — textos institucionais, links e código de conduta.
2526

26-
Depois de mudar um JSON, valide a sintaxe:
27+
Depois de mudar um arquivo JSON puro, valide a sintaxe:
2728

2829
```sh
29-
python3 -m json.tool data/members.json >/dev/null
3030
python3 -m json.tool data/projects.json >/dev/null
3131
```
3232

assets/js/site.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,12 +344,12 @@
344344
}
345345

346346
async function load() {
347-
const files = ['site.json', 'members.json', 'events.json', 'projects.json', 'posts.json'];
347+
const files = ['site.json', 'members.jsonc', 'events.json', 'projects.json', 'posts.json'];
348348
try {
349349
const results = await Promise.all(files.map(async (file) => {
350350
const response = await fetch(`data/${file}`);
351351
if (!response.ok) throw new Error(`${file}: ${response.status}`);
352-
return response.json();
352+
return parseJsonc(await response.text());
353353
}));
354354
[state.site, state.members, state.events, state.projects, state.posts] = results;
355355
state.members = Array.isArray(state.members) ? state.members : [];
@@ -364,6 +364,41 @@
364364
}
365365
}
366366

367+
function parseJsonc(content) {
368+
let output = '';
369+
let inString = false;
370+
let escaped = false;
371+
372+
for (let index = 0; index < content.length; index += 1) {
373+
const character = content[index];
374+
const nextCharacter = content[index + 1];
375+
376+
if (inString) {
377+
output += character;
378+
if (escaped) escaped = false;
379+
else if (character === '\\') escaped = true;
380+
else if (character === '"') inString = false;
381+
continue;
382+
}
383+
384+
if (character === '"') {
385+
inString = true;
386+
output += character;
387+
} else if (character === '/' && nextCharacter === '/') {
388+
while (index < content.length && content[index] !== '\n') index += 1;
389+
output += '\n';
390+
} else if (character === '/' && nextCharacter === '*') {
391+
index += 2;
392+
while (index < content.length && !(content[index] === '*' && content[index + 1] === '/')) index += 1;
393+
index += 1;
394+
} else {
395+
output += character;
396+
}
397+
}
398+
399+
return JSON.parse(output);
400+
}
401+
367402
byId('language-toggle').addEventListener('click', () => { lang = lang === 'pt' ? 'en' : 'pt'; render(); });
368403
load();
369404
})();
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Use comentários para registrar contexto sobre a lista, mas mantenha cada voluntário
2+
// como um objeto JSON válido.
13
[
24
{
35
"name": "Alessandra Cioletti",
@@ -8,7 +10,7 @@
810
"linkedin": "https://www.linkedin.com/in/allanadcardoso/"
911
},
1012
{
11-
"name": "Anna S.",
13+
"name": "Anna Luiza",
1214
"linkedin": "https://www.linkedin.com/in/anna-s-b0680b2b3/"
1315
},
1416
{
@@ -19,27 +21,27 @@
1921
"name": "Cássio Botaro",
2022
"github": "cassiobotaro",
2123
"twitter": "@cassiobotaro",
22-
"email": "cassiobotaro@gmail.com",
24+
// "email": "cassiobotaro@gmail.com",
2325
"site": { "nome": "Import None", "href": "https://cassiobotaro.github.io" }
2426
},
2527
{
26-
"name": "Daniel Canesso Bicalho",
28+
"name": "Daniel Bicalho",
2729
"linkedin": "https://www.linkedin.com/in/daniel-canesso/"
2830
},
2931
{
3032
"name": "Débora Thomaz",
3133
"linkedin": "https://www.linkedin.com/in/dmthomaz/"
3234
},
3335
{
34-
"name": "Diego Ascanio Santos",
36+
"name": "Diego Ascanio",
3537
"linkedin": "https://www.linkedin.com/in/diego-ascanio-santos-02b674210/"
3638
},
3739
{
38-
"name": "Iago P. Ferreira",
40+
"name": "Iago Ferreira",
3941
"linkedin": "https://www.linkedin.com/in/iago-p-ferreira/"
4042
},
4143
{
42-
"name": "Jean",
44+
"name": "Jean Oliveira",
4345
"linkedin": "https://www.linkedin.com/in/jean3/"
4446
},
4547
{

0 commit comments

Comments
 (0)