fix: Kiku field grouping, frequency particles, sidebar media, Yomitan popup visibility (#91)

This commit is contained in:
2026-05-27 01:40:48 -07:00
committed by GitHub
parent efe50ed1e4
commit 1dcfed86ab
52 changed files with 1695 additions and 368 deletions
+27
View File
@@ -11,6 +11,7 @@ type LogCandidate = {
mtimeMs: number;
mtimeDateKey: string;
fileDateKey: string | null;
fileWeekKey: string | null;
};
export type ExportLogsResult = {
@@ -38,10 +39,21 @@ function localDateKey(date: Date): string {
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
}
function localWeekKey(date: Date): string {
const startOfYear = new Date(date.getFullYear(), 0, 1);
const dayOfYear =
Math.floor((date.getTime() - startOfYear.getTime()) / (24 * 60 * 60 * 1000)) + 1;
return `${date.getFullYear()}-W${pad(Math.max(1, Math.ceil(dayOfYear / 7)))}`;
}
function filenameDateKey(fileName: string): string | null {
return fileName.match(/\d{4}-\d{2}-\d{2}/)?.[0] ?? null;
}
function filenameWeekKey(fileName: string): string | null {
return fileName.match(/\d{4}-W\d{2}/)?.[0] ?? null;
}
function fileKind(fileName: string): string {
const match = fileName.match(/^([A-Za-z0-9_-]+)-/);
return match?.[1] ?? fileName;
@@ -84,6 +96,7 @@ function buildCandidate(logsDir: string, entry: string): LogCandidate | null {
mtimeMs: stats.mtimeMs,
mtimeDateKey: localDateKey(stats.mtime),
fileDateKey: filenameDateKey(entry),
fileWeekKey: filenameWeekKey(entry),
};
}
@@ -117,6 +130,14 @@ function candidateFreshnessMs(candidate: LogCandidate): number {
if (candidate.fileDateKey) {
return Date.parse(`${candidate.fileDateKey}T23:59:59.999Z`);
}
if (candidate.fileWeekKey) {
const match = candidate.fileWeekKey.match(/^(\d{4})-W(\d{2})$/);
if (match) {
const year = Number(match[1]);
const week = Number(match[2]);
return Date.UTC(year, 0, week * 7, 23, 59, 59, 999);
}
}
return candidate.mtimeMs;
}
@@ -130,6 +151,12 @@ function selectLogCandidates(
return { mode: 'current-day', selected: currentDated };
}
const currentWeek = localWeekKey(now);
const currentWeekly = candidates.filter((candidate) => candidate.fileWeekKey === currentWeek);
if (currentWeekly.length > 0) {
return { mode: 'current-day', selected: currentWeekly };
}
const currentUndated = candidates.filter(
(candidate) => candidate.fileDateKey === null && candidate.mtimeDateKey === today,
);