Files
afilmory/scripts/photo-loader.ts
Innei ae4f15e3ea refactor: update photo data handling and types
- Changed the PhotoManifest type to PhotoManifestItem across various components and services for consistency.
- Removed the views property from the PhotoInfo interface to streamline photo data.
- Updated rules in color.mdc and project.mdc to adjust glob patterns and application behavior.
- Enhanced the feed-sitemap plugin to utilize the new PhotoManifestItem type for better data management.

Signed-off-by: Innei <tukon479@gmail.com>
2025-06-26 00:48:04 +08:00

38 lines
1.0 KiB
TypeScript

import { readFileSync } from 'node:fs'
import { join } from 'node:path'
import { workdir } from '../packages/builder/src/path.js'
import type { PhotoManifestItem } from '../packages/builder/src/types/photo.js'
class BuildTimePhotoLoader {
private photos: PhotoManifestItem[] = []
private photoMap: Record<string, PhotoManifestItem> = {}
constructor() {
try {
const manifestPath = join(workdir, 'src/data/photos-manifest.json')
const manifestContent = readFileSync(manifestPath, 'utf-8')
this.photos = JSON.parse(manifestContent).data as PhotoManifestItem[]
this.photos.forEach((photo) => {
this.photoMap[photo.id] = photo
})
console.info(`📚 Loaded ${this.photos.length} photos from manifest`)
} catch (error) {
console.error('❌ Failed to load photos manifest:', error)
this.photos = []
}
}
getPhotos() {
return this.photos
}
getPhoto(id: string) {
return this.photoMap[id]
}
}
export const buildTimePhotoLoader = new BuildTimePhotoLoader()