-
-
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.
Use base rather than site to create subpath for links/scripts (#5371)
* Use base rather than site to create subpath for links/scripts * Adding a changeset * Warn when the site has a pathname but not using base * fix asset test * fix asset inlining behavior
- Loading branch information
Showing
14 changed files
with
206 additions
and
62 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 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Prefer the `base` config rather than site config for creating URLs for links and scripts. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { expect } from 'chai'; | ||
import * as cheerio from 'cheerio'; | ||
import { loadFixture } from './test-utils.js'; | ||
|
||
describe('Asset URL resolution in build', () => { | ||
/** @type {import('./test-utils').Fixture} */ | ||
let fixture; | ||
|
||
describe('With site and base', async () => { | ||
describe('with site', () => { | ||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: './fixtures/asset-url-base/', | ||
site: 'http://example.com/sub/path/' | ||
}); | ||
await fixture.build(); | ||
}); | ||
|
||
it('does not include the site\'s subpath', async () => { | ||
const html = await fixture.readFile('/index.html'); | ||
const $ = cheerio.load(html); | ||
const href = $('link[rel=stylesheet]').attr('href'); | ||
expect(href.startsWith('/sub/path/')).to.equal(false); | ||
}); | ||
}); | ||
|
||
describe('with site and base', () => { | ||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: './fixtures/asset-url-base/', | ||
site: 'http://example.com/sub/path/', | ||
base: '/another/base/' | ||
}); | ||
await fixture.build(); | ||
}); | ||
|
||
it('does not include the site\'s subpath', async () => { | ||
const html = await fixture.readFile('/index.html'); | ||
const $ = cheerio.load(html); | ||
const href = $('link[rel=stylesheet]').attr('href'); | ||
expect(href.startsWith('/sub/path/')).to.equal(false); | ||
}); | ||
|
||
it('does include the base subpath', async () => { | ||
const html = await fixture.readFile('/index.html'); | ||
const $ = cheerio.load(html); | ||
const href = $('link[rel=stylesheet]').attr('href'); | ||
expect(href.startsWith('/another/base/')).to.equal(true); | ||
}); | ||
}); | ||
}); | ||
}); |
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,11 @@ | ||
{ | ||
"name": "@test/asset-url-base", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"astro": "workspace:*" | ||
}, | ||
"scripts": { | ||
"dev": "astro dev" | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
packages/astro/test/fixtures/asset-url-base/src/pages/index.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,13 @@ | ||
<html> | ||
<head> | ||
<title>Testing</title> | ||
<style> | ||
body { | ||
background: blue; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h1>Testing</h1> | ||
</body> | ||
</html> |
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
Oops, something went wrong.