feat: add validated content services and safe legacy import
This commit is contained in:
30
scripts/export-legacy.ts
Normal file
30
scripts/export-legacy.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
// Run only when refreshing the explicit legacy-import fixture, before editing legacy data.
|
||||
import { mkdirSync, writeFileSync } from 'node:fs';
|
||||
import { messagesByLocale } from '../src/i18n/content';
|
||||
import { getProjects } from '../src/data/projects';
|
||||
import { getExperiences } from '../src/data/experience';
|
||||
import { getEducation } from '../src/data/education';
|
||||
import { getMilestones } from '../src/data/milestones';
|
||||
import { filterTabs, skillsByDiscipline } from '../src/data/skills';
|
||||
|
||||
const placeholders: Record<string, string[]> = {
|
||||
ariaLabel: ['progress'], progressLabel: ['progress'], liveProjectLabel: ['title'],
|
||||
openGalleryImage: ['caption'], selectGalleryImage: ['index', 'caption'],
|
||||
imageCounter: ['current', 'total'], logoAlt: ['company'], viewCertificateLabel: ['title'],
|
||||
};
|
||||
const fixture = { messages: messagesByLocale, entries: Object.fromEntries(['en', 'fa'].map(locale => [locale, {
|
||||
projects: getProjects(locale as 'en' | 'fa'), experience: getExperiences(locale as 'en' | 'fa'),
|
||||
education: [{ id: 'education', ...getEducation(locale as 'en' | 'fa') }],
|
||||
milestones: getMilestones(locale as 'en' | 'fa'),
|
||||
skills: filterTabs.map(tab => ({ id: tab.id, label: messagesByLocale[locale as 'en' | 'fa'].skills.filterLabels[tab.id], ...skillsByDiscipline[tab.id] })),
|
||||
}])) };
|
||||
mkdirSync('src/seed', { recursive: true });
|
||||
writeFileSync('src/seed/legacy.json', JSON.stringify(fixture, (key, value) => {
|
||||
if (typeof value !== 'function') return value;
|
||||
const names = placeholders[key];
|
||||
let result = value(...names.map((name, index) => ['progress', 'index', 'current', 'total'].includes(name) ? 98760 + index : `{${name}}`));
|
||||
names.forEach((name, index) => {
|
||||
result = result.replaceAll(String(98760 + index), `{${name}}`).replaceAll(new Intl.NumberFormat('fa-IR', { useGrouping: false }).format(98760 + index), `{${name}}`);
|
||||
});
|
||||
return result;
|
||||
}, 2) + '\n');
|
||||
Reference in New Issue
Block a user