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

Ignore assets in src/pages/ to suppress warning "unsupported file type" #13319

Closed
wants to merge 2 commits into from

Conversation

aymkx
Copy link

@aymkx aymkx commented Feb 26, 2025

Changes

  • Add assetExtensions: string[] to AstroSettings
    • The default value derives from VALID_INPUT_FORMATS.
  • Add addAssetExtension to astro:config:setup hook for customizing (dynamically and silently in the same way as addPageExtension)
  • Add a condition to suppress warning "unsupported file type" in src/pages/ while constructing static routes
Motivation

Astro regards .astro, .md, .mdx and etc. files in src/pages/ directory as pages and builds static routes to them.

By the way, image files to be optimized should be specified and inserted by relative path from the document: ![](./path/to/image) or import somethingImage from "./path/to/image"; <Image src={somethingImage} />. It seems to be recommended to locate such assets in src/assets/ directory, but I feel it irrational especially when there are many documents and assets in deep directory; tbh, we should locate referred assets in the same directory of the document.

In this way, the problem emerges: noisily warned that "unsupported file type" is found in src/pages/ directory for EACH asset file (by #9105).

The initial change which introduced this (#6851) looks good and I think, respecting the PR, we should not take a quick solution: removing the warning or degrading it to debug level.

In addition, configurable structured logging may solve this, but it seems to be a hard job. So, this is a kind of workarounds.

Testing

There is no unit tests because the changed behavior is only warning.
Locating png file in src/pages/ and inserting it in MDX, I tried building example/with-mdx and it ran as expected.

Docs

There is no change to be documented.

Copy link

changeset-bot bot commented Feb 26, 2025

🦋 Changeset detected

Latest commit: 4cb2076

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Feb 26, 2025
Copy link

codspeed-hq bot commented Feb 26, 2025

CodSpeed Performance Report

Merging #13319 will not alter performance

Comparing aymkx:ignore-assets-in-pages (4cb2076) with main (5f72a58)

Summary

✅ 6 untouched benchmarks

@github-actions github-actions bot added the semver: minor Change triggers a `minor` release label Feb 27, 2025
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

This PR is blocked because it contains a minor changeset. A reviewer will merge this at the next release if approved.

@ematipico
Copy link
Member

ematipico commented Feb 27, 2025

pages/ is a known folder to Astro, and it assumes that all files in that folder are pages that can be parsed in a certain why, and emitted as .html/.js files at the build (static or SSR).

but I feel it irrational especially when there are many documents and assets in deep directory

You can use aliases

I suggest you to create a discussion first in https://github.com/withastro/roadmap, and see if the proposal gain traction

@ematipico ematipico closed this Feb 27, 2025
@aymkx
Copy link
Author

aymkx commented Feb 27, 2025

I know about alias, but even if to be used, it is still irrational when there is a deep directory in src/assets/, and the same goes for arranging all assets flat.
Anyway, I'm not against the convention itself. I want to stop the annoying warning. It just means what is commented in #6851 actually happened.
Thanks for your response.

@aymkx aymkx deleted the ignore-assets-in-pages branch February 27, 2025 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope) semver: minor Change triggers a `minor` release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants