(refactor) use sha256 instead of md5 for calendar summary

This commit is contained in:
Valentyne Stigloher 2025-05-01 12:24:28 +02:00
parent 0c444ad1af
commit 96197e3f37
2 changed files with 5 additions and 10 deletions

View File

@ -64,7 +64,7 @@ const run = async (config: Config, baseUrl: string): Promise<void> => {
const prev = fs.existsSync(prevPath) ? JSON.parse(fs.readFileSync(prevPath, 'utf-8')) : {}; const prev = fs.existsSync(prevPath) ? JSON.parse(fs.readFileSync(prevPath, 'utf-8')) : {};
const localEvents = (await import(`../locale/${config.locale}/calendar/events.ts`)).default; const localEvents = (await import(`../locale/${config.locale}/calendar/events.ts`)).default;
const current = buildCalendar(localEvents, process.env.NUXT_PUBLIC_BASE_URL!).buildSummary(); const current = await buildCalendar(localEvents, process.env.NUXT_PUBLIC_BASE_URL!).buildSummary();
const changedYears = new Set(); const changedYears = new Set();
for (const day of Object.keys(current)) { for (const day of Object.keys(current)) {
const year = day.substring(0, 4); const year = day.substring(0, 4);

View File

@ -1,10 +1,8 @@
import type { EventAttributes } from 'ics'; import type { EventAttributes } from 'ics';
import md5 from 'js-md5';
import nepali from 'nepali-calendar-js'; import nepali from 'nepali-calendar-js';
import { v5 as uuid5 } from 'uuid'; import { v5 as uuid5 } from 'uuid';
import { newDate } from '../helpers.ts'; import { newDate, sha256 } from '~/src/helpers.ts';
import type { Translator } from '~/src/translator.ts'; import type { Translator } from '~/src/translator.ts';
export class Day { export class Day {
@ -448,16 +446,13 @@ export class Calendar {
} }
} }
buildSummary(): Record<string, string> { async buildSummary(): Promise<Record<string, string>> {
const summary: Record<string, string> = {}; const summary: Record<string, string> = {};
for (const year of this.getAllYears()) { for (const year of this.getAllYears()) {
for (let month = 1; month <= 12; month++) { for (let month = 1; month <= 12; month++) {
for (const day of iterateMonth(year.year, month)) { for (const day of iterateMonth(year.year, month)) {
const events = []; const events = (year.eventsByDate[day.toString()] || []).map((event) => event.name);
for (const event of year.eventsByDate[day.toString()] || []) { summary[day.toString()] = await sha256(JSON.stringify(events));
events.push(event.name);
}
summary[day.toString()] = md5(JSON.stringify(events));
} }
} }
} }