Skip to content

Commit 03e00e5

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent c1b6e57 commit 03e00e5

File tree

2 files changed

+55
-51
lines changed

2 files changed

+55
-51
lines changed

src/scripts/fetchData.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// src/scripts/fetchEuroPythonData.js
2-
import fs from 'fs';
3-
import path from 'path';
4-
import { fileURLToPath } from 'url';
2+
import fs from "fs";
3+
import path from "path";
4+
import { fileURLToPath } from "url";
55

66
const __dirname = path.dirname(fileURLToPath(import.meta.url));
77

@@ -11,25 +11,27 @@ const SPEAKERS_URL = "https://programapi24.europython.eu/2024/speakers.json";
1111
const SCHEDULE_URL = "https://programapi24.europython.eu/2024/schedule.json";
1212

1313
// Define output directory and file paths
14-
const DATA_DIR = path.join(__dirname, '../src/data');
15-
const SESSIONS_FILE = path.join(DATA_DIR, 'sessions.json');
16-
const SPEAKERS_FILE = path.join(DATA_DIR, 'speakers.json');
17-
const SCHEDULE_FILE = path.join(DATA_DIR, 'schedule.json');
14+
const DATA_DIR = path.join(__dirname, "../src/data");
15+
const SESSIONS_FILE = path.join(DATA_DIR, "sessions.json");
16+
const SPEAKERS_FILE = path.join(DATA_DIR, "speakers.json");
17+
const SCHEDULE_FILE = path.join(DATA_DIR, "schedule.json");
1818

1919
// Ensure data directory exists
2020
fs.mkdirSync(DATA_DIR, { recursive: true });
2121

2222
// Function to fetch and save data
2323
async function fetchAndSaveData(url, filePath) {
2424
console.log(`Fetching data from ${url}`);
25-
25+
2626
try {
2727
const response = await fetch(url);
28-
28+
2929
if (!response.ok) {
30-
throw new Error(`Failed to fetch data: ${response.status} ${response.statusText}`);
30+
throw new Error(
31+
`Failed to fetch data: ${response.status} ${response.statusText}`
32+
);
3133
}
32-
34+
3335
const data = await response.json();
3436
fs.writeFileSync(filePath, JSON.stringify(data, null, 2));
3537
console.log(`Successfully saved data to ${filePath}`);
@@ -46,16 +48,16 @@ async function fetchAllData() {
4648
// Fetch and save all three data files
4749
const sessions = await fetchAndSaveData(SESSIONS_URL, SESSIONS_FILE);
4850
console.log(`Fetched ${Object.keys(sessions).length} sessions`);
49-
51+
5052
const speakers = await fetchAndSaveData(SPEAKERS_URL, SPEAKERS_FILE);
5153
console.log(`Fetched ${Object.keys(speakers).length} speakers`);
52-
54+
5355
const schedule = await fetchAndSaveData(SCHEDULE_URL, SCHEDULE_FILE);
5456
console.log(`Fetched schedule data`);
55-
56-
console.log('All data fetched and saved successfully!');
57+
58+
console.log("All data fetched and saved successfully!");
5759
} catch (error) {
58-
console.error('Failed to fetch all data:', error);
60+
console.error("Failed to fetch all data:", error);
5961
process.exit(1);
6062
}
6163
}

src/scripts/generateContent.js

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// src/scripts/generateContent.js
2-
import fs from 'fs';
3-
import path from 'path';
4-
import yaml from 'js-yaml';
2+
import fs from "fs";
3+
import path from "path";
4+
import yaml from "js-yaml";
55

66
const ROOT_DIR = path.resolve(process.cwd());
77

@@ -21,23 +21,23 @@ function writeMdx(data, outputDir, contentKey) {
2121
for (const [key, value] of Object.entries(data)) {
2222
const filename = `${key}.mdx`;
2323
const filepath = path.join(outputDir, filename);
24-
24+
2525
// Extract content and remove it from frontmatter
2626
const content = value[contentKey] || "";
2727
const valueCopy = { ...value };
2828
delete valueCopy[contentKey];
29-
29+
3030
// Replace <3 with heart emoji
3131
const processedContent = content.replace(/<3/g, "❤️");
32-
32+
3333
// Generate frontmatter
3434
const frontmatter = yaml.dump(valueCopy, { sortKeys: true });
35-
35+
3636
// Write the file
3737
fs.writeFileSync(
38-
filepath,
39-
`---\n${frontmatter}---\n\n${processedContent}`,
40-
'utf-8'
38+
filepath,
39+
`---\n${frontmatter}---\n\n${processedContent}`,
40+
"utf-8"
4141
);
4242
}
4343
}
@@ -48,61 +48,63 @@ function writeMdx(data, outputDir, contentKey) {
4848
* @param {string} directory - The directory containing the file
4949
* @returns {Object} The parsed JSON data
5050
*/
51-
function loadJsonData(filename, directory = 'src/data') {
51+
function loadJsonData(filename, directory = "src/data") {
5252
const filePath = path.join(directory, `${filename}.json`);
53-
53+
5454
if (!fs.existsSync(filePath)) {
5555
throw new Error(`File ${filename}.json not found in ${directory}`);
5656
}
57-
57+
5858
console.log(`Load ${filename}.json from ${directory}`);
59-
return JSON.parse(fs.readFileSync(filePath, 'utf-8'));
59+
return JSON.parse(fs.readFileSync(filePath, "utf-8"));
6060
}
6161

6262
/**
6363
* Generate content from JSON data
6464
*/
6565
function generateContent() {
66-
const files = ['speakers', 'sessions', 'schedule'];
67-
66+
const files = ["speakers", "sessions", "schedule"];
67+
6868
// Check if any required files are missing
69-
if (files.some(file => !fs.existsSync(path.join('src/data', `${file}.json`)))) {
69+
if (
70+
files.some((file) => !fs.existsSync(path.join("src/data", `${file}.json`)))
71+
) {
7072
console.log("Nothing to generate. Missing data.");
7173
return;
7274
}
73-
75+
7476
// Load data
75-
const speakers = loadJsonData('speakers');
76-
const sessions = loadJsonData('sessions');
77-
const schedule = loadJsonData('schedule');
78-
77+
const speakers = loadJsonData("speakers");
78+
const sessions = loadJsonData("sessions");
79+
const schedule = loadJsonData("schedule");
80+
7981
// Process sessions to include speaker slugs
8082
for (const session of Object.values(sessions)) {
81-
session.speakers = (session.speakers || []).map(
82-
speakerId => speakers[speakerId]?.slug
83-
).filter(Boolean);
83+
session.speakers = (session.speakers || [])
84+
.map((speakerId) => speakers[speakerId]?.slug)
85+
.filter(Boolean);
8486
}
85-
87+
8688
// Process speakers to include submission slugs
8789
for (const speaker of Object.values(speakers)) {
8890
speaker.submissions = (speaker.submissions || [])
89-
.filter(sessionId => sessionId in sessions)
90-
.map(sessionId => sessions[sessionId].slug);
91+
.filter((sessionId) => sessionId in sessions)
92+
.map((sessionId) => sessions[sessionId].slug);
9193
}
92-
94+
9395
// Write MDX files
94-
writeMdx(sessions, path.join(ROOT_DIR, 'src/content/sessions'), 'abstract');
95-
writeMdx(speakers, path.join(ROOT_DIR, 'src/content/speakers'), 'biography');
96-
96+
writeMdx(sessions, path.join(ROOT_DIR, "src/content/sessions"), "abstract");
97+
writeMdx(speakers, path.join(ROOT_DIR, "src/content/speakers"), "biography");
98+
9799
// Write schedule data
98100
for (const [day, data] of Object.entries(schedule.days || {})) {
99101
const dayPath = path.join(ROOT_DIR, `src/content/days/${day}.json`);
100-
102+
101103
// Ensure directory exists
102104
fs.mkdirSync(path.dirname(dayPath), { recursive: true });
103-
105+
104106
// Write the file
105-
fs.writeFileSync(dayPath, JSON.stringify(data, null, 2), 'utf-8');
107+
fs.writeFileSync(dayPath, JSON.stringify(data, null, 2), "utf-8");
106108
}
107109
}
108110

0 commit comments

Comments
 (0)