Skip to content

Handle image extensions/filetypes when loading thumbnails #393

@ots22

Description

@ots22

Thumbnails for the models/datasources in the frontend are kept here.

Fix

// Load the thumbnail images
//
// require.context returns a webpack object, which is callable.
// Calling it with the name of a resource returns the path to that
// resource. It also has a '.keys()' method, which returns all the
// included resources
const model_thumbnails_ctxt = require.context(
'./data/thumbnails/models', false, /\.jpg$/
);
// From the webpack object, make a dictionary from the resource name
// to its path
//
// Could strip the leading './' and trailing extension (and then handle
// several file types)
const model_thumbnails = model_thumbnails_ctxt.keys().reduce((dict, mod) => {
dict[mod] = model_thumbnails_ctxt(mod);
return dict;
}, {});
to strip the extension and make the lookup work by name (rather than file path - and so support other image formats).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions