-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* rearrange plugins and add props to Image component * add tests and update lockfile * add changeset * re-rearrange plugin order, gfm/smartypants then user defined then image related then shiki/prism * make more generic * add more/better tests * remove unused logger --------- Co-authored-by: Erika <[email protected]>
- Loading branch information
1 parent
2e58904
commit df37366
Showing
10 changed files
with
157 additions
and
3 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,5 @@ | ||
--- | ||
"@astrojs/mdx": minor | ||
--- | ||
|
||
Allows remark plugins to pass options specifying how images in .mdx files will be optimized |
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
8 changes: 8 additions & 0 deletions
8
packages/integrations/mdx/test/fixtures/image-remark-imgattr/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,8 @@ | ||
import { defineConfig } from 'astro/config'; | ||
import mdx from '@astrojs/mdx'; | ||
import plugin from "./remarkPlugin" | ||
|
||
// https://astro.build/config | ||
export default defineConfig({ | ||
integrations: [mdx({remarkPlugins:[plugin]})], | ||
}); |
12 changes: 12 additions & 0 deletions
12
packages/integrations/mdx/test/fixtures/image-remark-imgattr/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,12 @@ | ||
{ | ||
"name": "@test/image-remark-imgattr", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"@astrojs/mdx": "workspace:*", | ||
"astro": "workspace:*" | ||
}, | ||
"scripts": { | ||
"dev": "astro dev" | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
packages/integrations/mdx/test/fixtures/image-remark-imgattr/remarkPlugin.js
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,22 @@ | ||
export default function plugin() { | ||
return transformer; | ||
|
||
function transformer(tree) { | ||
function traverse(node) { | ||
if (node.type === "image") { | ||
node.data = node.data || {}; | ||
node.data.hProperties = node.data.hProperties || {}; | ||
node.data.hProperties.id = "test"; | ||
node.data.hProperties.width = "300"; | ||
node.data.hProperties.widths = [300,600]; | ||
node.data.hProperties.sizes = "(min-width: 600px) 600w, 300w"; | ||
} | ||
|
||
if (node.children) { | ||
node.children.forEach(traverse); | ||
} | ||
} | ||
|
||
traverse(tree); | ||
} | ||
} |
Binary file added
BIN
+11.4 KB
...ges/integrations/mdx/test/fixtures/image-remark-imgattr/src/assets/penguin2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
packages/integrations/mdx/test/fixtures/image-remark-imgattr/src/pages/index.mdx
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 @@ | ||
![alt](../assets/penguin2.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { expect } from 'chai'; | ||
import * as cheerio from 'cheerio'; | ||
import { loadFixture } from '../../../astro/test/test-utils.js'; | ||
|
||
const FIXTURE_ROOT = new URL('./fixtures/image-remark-imgattr/', import.meta.url); | ||
|
||
describe('Testing remark plugins for image processing', () => { | ||
/** @type {import('./test-utils').Fixture} */ | ||
let fixture; | ||
|
||
describe('start dev server', () => { | ||
/** @type {import('./test-utils').DevServer} */ | ||
let devServer; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: FIXTURE_ROOT, | ||
}); | ||
|
||
devServer = await fixture.startDevServer(); | ||
}); | ||
|
||
after(async () => { | ||
await devServer.stop(); | ||
}); | ||
|
||
describe('Test image attributes can be added by remark plugins', () => { | ||
let $; | ||
before(async () => { | ||
let res = await fixture.fetch('/'); | ||
let html = await res.text(); | ||
$ = cheerio.load(html); | ||
}); | ||
|
||
it('<img> has correct attributes', async () => { | ||
let $img = $('img'); | ||
expect($img.attr('id')).to.equal('test'); | ||
expect($img.attr('sizes')).to.equal('(min-width: 600px) 600w, 300w'); | ||
expect($img.attr('srcset')).to.not.be.empty; | ||
}); | ||
|
||
it('<img> was processed properly', async () => { | ||
let $img = $('img'); | ||
expect(new URL($img.attr('src'), 'http://example.com').searchParams.get('w')).to.equal( | ||
'300' | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.