-
-
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.
* add: Astro.resolve * Add docs and tests for Astro.resolve * Add warnings when using string literals * Prevent windows errors * Adds a changeset * Use the astro logger to log the warning * Use the .js extension * Dont warn for data urls * Rename nonRelative and better match Co-authored-by: Jonathan Neal <jonathantneal@hotmail.com>
- Loading branch information
Showing
10 changed files
with
155 additions
and
17 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,20 @@ | ||
--- | ||
'docs': patch | ||
'astro': patch | ||
--- | ||
|
||
Adds support for Astro.resolve | ||
|
||
`Astro.resolve()` helps with creating URLs relative to the current Astro file, allowing you to reference files within your `src/` folder. | ||
|
||
Astro *does not* resolve relative links within HTML, such as images: | ||
|
||
```html | ||
<img src="../images/penguin.png" /> | ||
``` | ||
|
||
The above will be sent to the browser as-is and the browser will resolve it relative to the current __page__. If you want it to be resolved relative to the .astro file you are working in, use `Astro.resolve`: | ||
|
||
```astro | ||
<img src={Astro.resolve('../images/penguin.png')} /> | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { Expression, TemplateNode } from '@astrojs/parser'; | ||
|
||
export interface Attribute { | ||
start: number; | ||
end: number; | ||
type: 'Attribute' | 'Spread'; | ||
name: string; | ||
value: TemplateNode[] | boolean; | ||
expression?: Expression; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { suite } from 'uvu'; | ||
import * as assert from 'uvu/assert'; | ||
import { doc } from './test-utils.js'; | ||
import { setup } from './helpers.js'; | ||
|
||
const GlobalBuild = suite('Astro.* built'); | ||
|
||
setup(GlobalBuild, './fixtures/astro-global', { | ||
runtimeOptions: { | ||
mode: 'production' | ||
} | ||
}); | ||
|
||
GlobalBuild('Astro.resolve in the build', async (context) => { | ||
const result = await context.runtime.load('/resolve'); | ||
assert.ok(!result.error, `build error: ${result.error}`); | ||
|
||
const html = result.contents; | ||
const $ = doc(html); | ||
assert.equal($('img').attr('src'), '/blog/_astro/src/images/penguin.png'); | ||
}); | ||
|
||
GlobalBuild.run(); |
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
5 changes: 5 additions & 0 deletions
5
packages/astro/test/fixtures/astro-global/src/components/ChildResolve.astro
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 @@ | ||
--- | ||
const penguinUrl = Astro.resolve('../images/penguin.png'); | ||
--- | ||
<img src={penguinUrl} /> | ||
<img src="../images/penguin.png" /> |
12 changes: 12 additions & 0 deletions
12
packages/astro/test/fixtures/astro-global/src/pages/resolve.astro
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 @@ | ||
--- | ||
import Child from '../components/ChildResolve.astro'; | ||
--- | ||
|
||
<html> | ||
<head> | ||
<title>Testing</title> | ||
</head> | ||
<body> | ||
<Child /> | ||
</body> | ||
</html> |