Skip to content

Commit

Permalink
#595: Fix media metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
estruyf committed Jun 29, 2023
1 parent c1410de commit e6b28ce
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- [#572](https://github.com/estruyf/vscode-front-matter/issues/572): Fix the media snippet placeholder link
- [#577](https://github.com/estruyf/vscode-front-matter/issues/577): Fix in the `dataFile` field where data entries get overwritten
- [#590](https://github.com/estruyf/vscode-front-matter/issues/590): Fix for image fields inside a sub-block
- [#595](https://github.com/estruyf/vscode-front-matter/issues/595): Fix for media metadata now showing up

## [8.4.0] - 2023-04-03 - [Release notes](https://beta.frontmatter.codes/updates/v8.4.0)

Expand Down
34 changes: 18 additions & 16 deletions src/helpers/MediaHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,22 +147,24 @@ export class MediaHelpers {
const total = files.length;

// Get media set
files = files.map((file) => {
try {
const metadata = MediaLibrary.getInstance().get(file.fsPath);
const mimeType = lookup(file.fsPath);

return {
...file,
dimensions:
mimeType && mimeType.startsWith('image/') ? imageSize(file.fsPath) : undefined,
mimeType: lookup(file.fsPath) || '',
...metadata
};
} catch (e) {
return { ...file };
}
});
files = await Promise.all(
files.map(async (file) => {
try {
const metadata = await MediaLibrary.getInstance().get(file.fsPath);
const mimeType = lookup(file.fsPath);

return {
...file,
dimensions:
mimeType && mimeType.startsWith('image/') ? imageSize(file.fsPath) : undefined,
mimeType: lookup(file.fsPath) || '',
...metadata
};
} catch (e) {
return { ...file };
}
})
);
files = files.filter((f) => f.mtime !== undefined);

// Sort the files
Expand Down

0 comments on commit e6b28ce

Please sign in to comment.