-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Markdoc] Support automatic image optimization with `experimental.ass…
…ets` (#6630) * wip: scrappy implementation. It works! 🥳 * chore: add code comments on inline utils * fix: code cleanup, run on experimental.assets * feat: support ~/assets alias * fix: spoof `astro:assets` when outside experimental * test: image paths in dev and prod * feat: support any vite alias with ctx.resolve * fix: avoid trying to process absolute paths * fix: raise helpful error for invalid vite paths * refactor: revert URL support on emitAsset * chore: lint * refactor: expose emitESMImage from assets base * wip: why doesn't assets exist * scary chore: make @astrojs/markdoc truly depend on astro * fix: import emitESMImage straight from dist * chore: remove type def from assets package * chore: screw it, just ts ignore * deps: rollup types * refactor: optimize images during parse step * chore: remove unneeded `.flat()` * fix: use file-based relative paths * fix: add back helpful error * chore: changeset * deps: move astro back to dev dep * fix: put emit assets behind flag * chore: change to markdoc patch
- Loading branch information
1 parent
dfbd09b
commit cfcf2e2
Showing
18 changed files
with
368 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
'@astrojs/markdoc': patch | ||
'astro': patch | ||
--- | ||
|
||
Support automatic image optimization for Markdoc images when using `experimental.assets`. You can [follow our Assets guide](https://docs.astro.build/en/guides/assets/#enabling-assets-in-your-project) to enable this feature in your project. Then, start using relative or aliased image sources in your Markdoc files for automatic optimization: | ||
|
||
```md | ||
<!--Relative paths--> | ||
![The Milky Way Galaxy](../assets/galaxy.jpg) | ||
<!--Or configured aliases--> | ||
![Houston smiling and looking cute](~/assets/houston-smiling.jpg) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
packages/integrations/markdoc/test/fixtures/image-assets/astro.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { defineConfig } from 'astro/config'; | ||
import markdoc from '@astrojs/markdoc'; | ||
|
||
// https://astro.build/config | ||
export default defineConfig({ | ||
experimental: { | ||
assets: true, | ||
}, | ||
integrations: [markdoc()], | ||
}); |
9 changes: 9 additions & 0 deletions
9
packages/integrations/markdoc/test/fixtures/image-assets/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "@test/image-assets", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"@astrojs/markdoc": "workspace:*", | ||
"astro": "workspace:*" | ||
} | ||
} |
Binary file added
BIN
+20.9 KB
.../integrations/markdoc/test/fixtures/image-assets/src/assets/alias/cityscape.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+17.2 KB
...ges/integrations/markdoc/test/fixtures/image-assets/src/assets/relative/oar.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions
7
packages/integrations/markdoc/test/fixtures/image-assets/src/content/docs/intro.mdoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Image assets | ||
|
||
![Favicon](/favicon.svg) {% #public %} | ||
|
||
![Oar](../../assets/relative/oar.jpg) {% #relative %} | ||
|
||
![Gray cityscape arial view](~/assets/alias/cityscape.jpg) {% #alias %} |
Oops, something went wrong.