Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested asset imports #364

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/images/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const DEFAULT_IMAGE_PROPS = {
// alt: ''
};

const images = sortFiles(import.meta.glob('./*.{png,jpg,jpeg,gif}', { eager: true })).reduce(
const images = sortFiles(import.meta.glob('./**/*.{png,jpg,jpeg,gif,svg}', { eager: true })).reduce(
(acc, [k, v]) => {
const [, name, count, size] =
k.match(/\/([-_\w]+)\.([0-9]+)?\.?([SMLX]+)?\.?(png|jpe?g|gif)$/) || [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to note - this regex will only extract the file name (not the path). If you want to be able to reference images like image: myfolder/myimage.jpg in the ArchieML doc (or images['myfolder/myimage'] in the code), we should add a forward slash / to the character list in the first group.

On the other hand, we could definitely leave it as is — but we'd have to guarantee all filenames are unique across the folders.

Expand Down
4 changes: 2 additions & 2 deletions assets/videos/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ const DEFAULT_IMAGE_PROPS = {
// Add any other story-default video still props here
};

const videos = sortFiles(import.meta.glob('./*.mp4*', { eager: true })).reduce(
const videos = sortFiles(import.meta.glob('./**/*.mp4*', { eager: true })).reduce(
(dict, [file, src]) => {
const [, name, size, isStill] = file.match(
/\/([-_\w]+)\.?([A-Z]+)?\.mp4(\.jpe?g|\.png|\.gif)?$/
);

const fields = dict[name] || DEFAULT_VIDEO_PROPS;
const fields = dict[name] || { ...DEFAULT_VIDEO_PROPS };

if (isStill) {
// ".mp4.jpg" files are the first frame stills
Expand Down