Skip to content

Commit

Permalink
Fixes photos in the feed.
Browse files Browse the repository at this point in the history
  • Loading branch information
qubyte committed May 11, 2024
1 parent 0bd4be4 commit 519cb26
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions lib/load-note-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class NotePage extends Page {
* @param {string} options.timezone
* @param {string} options.spoiler
* @param {any[]} options.photos,
* @param {{value: String, alt: String}}[]} options.photoObjects,
* @param {string} options.title
*/
constructor({
Expand All @@ -24,6 +25,7 @@ class NotePage extends Page {
timezone,
spoiler,
photos,
photoObjects,
title
}) {
const timestamp = date.getTime();
Expand All @@ -41,6 +43,7 @@ class NotePage extends Page {
this.type = 'note';
this.spoiler = spoiler;
this.photos = photos;
this.photoObjects = photoObjects;
this.image = photos.length ? photos[0] : null;
this.title = title;
this.feedItem = content;
Expand All @@ -52,11 +55,16 @@ export default async function loadNoteFiles({ baseUrl, dir, imagesDimensions })
const notes = await Promise.all(filenames.filter(fn => fn.endsWith('.json')).map(async (filename, index) => {
const note = JSON.parse(await readFile(new URL(filename, dir), 'utf8'));
const content = render(note.content);
const photos = [];
const photoObjects = [];

const photos = await Promise.all((note.photo ? [].concat(note.photo) : []).map(p => {
await Promise.all((note.photo ? [].concat(note.photo) : []).map(p => {
const { value, url, alt } = typeof p === 'string' ? { value: p, alt: note.content } : { ...p };
const val = value || url;

return composePicture(value || url, null, alt, imagesDimensions);
photos.push(composePicture(val, null, alt, imagesDimensions));
photoObjects.push({ value: val, alt });
return null;
}));

return new NotePage({
Expand All @@ -67,6 +75,7 @@ export default async function loadNoteFiles({ baseUrl, dir, imagesDimensions })
timezone: getTimezone(note.location?.latitude, note.location?.longitude),
spoiler: note.spoiler,
photos,
photoObjects,
title: `Note ${index}`
});
}));
Expand Down
2 changes: 1 addition & 1 deletion src/templates/documents/atom.xml.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<p>⚠︎ {{spoiler}} ⚠︎</p><p>Follow the link to reveal.</p>
{{else}}
{{#if feedItem}}{{feedItem}}{{else}}{{content}}{{/if}}
{{#photos}}<img src="https://qubyte.codes{{value}}" alt="{{alt}}">{{/photos}}
{{#photoObjects}}<img src="https://qubyte.codes{{value}}" alt="{{alt}}">{{/photoObjects}}
{{/if}}
</content>
</entry>
Expand Down

0 comments on commit 519cb26

Please sign in to comment.