-
-
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.
fix(markdown): file.url fixes (#3198)
* fix(markdown): file.url fixes * Added tests * Changed the default of `base` from `./` to `/` * Make the url work with subpath * Changeset * Forgot to change this comparison
- Loading branch information
Showing
11 changed files
with
149 additions
and
10 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 | ||
--- | ||
|
||
Markdown file.url now respects `trailingSlash` and `base` |
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,100 @@ | ||
import { expect } from 'chai'; | ||
import cheerio from 'cheerio'; | ||
import { loadFixture } from './test-utils.js'; | ||
|
||
describe('Astro Markdown URL', () => { | ||
describe('With subpath', () => { | ||
const baseUrl = `/my-cool-base/docs/pages/how-to-make-a-page`; | ||
|
||
it('trailingSlash: always', async () => { | ||
let fixture = await loadFixture({ | ||
root: './fixtures/astro-markdown-url/', | ||
outDir: new URL('./fixtures/astro-markdown-url/with-subpath-always/', import.meta.url), | ||
base: '/my-cool-base', | ||
trailingSlash: 'always', | ||
}); | ||
await fixture.build(); | ||
|
||
const html = await fixture.readFile('/index.html'); | ||
const $ = cheerio.load(html); | ||
|
||
expect($('#url').attr('href')).to.equal(baseUrl + '/'); | ||
}); | ||
|
||
it('trailingSlash: never', async () => { | ||
let fixture = await loadFixture({ | ||
root: './fixtures/astro-markdown-url/', | ||
outDir: new URL('./fixtures/astro-markdown-url/with-subpath-never/', import.meta.url), | ||
base: '/my-cool-base', | ||
trailingSlash: 'never', | ||
}); | ||
await fixture.build(); | ||
|
||
const html = await fixture.readFile('/index.html'); | ||
const $ = cheerio.load(html); | ||
|
||
expect($('#url').attr('href')).to.equal(baseUrl); | ||
}); | ||
|
||
it('trailingSlash: ignore', async () => { | ||
let fixture = await loadFixture({ | ||
root: './fixtures/astro-markdown-url/', | ||
outDir: new URL('./fixtures/astro-markdown-url/with-subpath-ignore/', import.meta.url), | ||
base: '/my-cool-base', | ||
trailingSlash: 'ignore', | ||
}); | ||
await fixture.build(); | ||
|
||
const html = await fixture.readFile('/index.html'); | ||
const $ = cheerio.load(html); | ||
|
||
expect($('#url').attr('href')).to.equal(baseUrl); | ||
}); | ||
}); | ||
|
||
describe('Without subpath', () => { | ||
const baseUrl = `/docs/pages/how-to-make-a-page`; | ||
|
||
it('trailingSlash: always', async () => { | ||
let fixture = await loadFixture({ | ||
root: './fixtures/astro-markdown-url/', | ||
outDir: new URL('./fixtures/astro-markdown-url/without-subpath-always/', import.meta.url), | ||
trailingSlash: 'always', | ||
}); | ||
await fixture.build(); | ||
|
||
const html = await fixture.readFile('/index.html'); | ||
const $ = cheerio.load(html); | ||
|
||
expect($('#url').attr('href')).to.equal(baseUrl + '/'); | ||
}); | ||
|
||
it('trailingSlash: never', async () => { | ||
let fixture = await loadFixture({ | ||
root: './fixtures/astro-markdown-url/', | ||
outDir: new URL('./fixtures/astro-markdown-url/without-subpath-never/', import.meta.url), | ||
trailingSlash: 'never', | ||
}); | ||
await fixture.build(); | ||
|
||
const html = await fixture.readFile('/index.html'); | ||
const $ = cheerio.load(html); | ||
|
||
expect($('#url').attr('href')).to.equal(baseUrl); | ||
}); | ||
|
||
it('trailingSlash: ignore', async () => { | ||
let fixture = await loadFixture({ | ||
root: './fixtures/astro-markdown-url/', | ||
outDir: new URL('./fixtures/astro-markdown-url/without-subpath-ignore/', import.meta.url), | ||
trailingSlash: 'ignore', | ||
}); | ||
await fixture.build(); | ||
|
||
const html = await fixture.readFile('/index.html'); | ||
const $ = cheerio.load(html); | ||
|
||
expect($('#url').attr('href')).to.equal(baseUrl); | ||
}); | ||
}); | ||
}); |
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,6 @@ | ||
with-subpath-always/ | ||
with-subpath-never/ | ||
with-subpath-ignore/ | ||
without-subpath-always/ | ||
without-subpath-never/ | ||
without-subpath-ignore/ |
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 @@ | ||
{ | ||
"name": "@test/astro-markdown-url", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"astro": "workspace:*" | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...tro/test/fixtures/astro-markdown-url/src/pages/docs/pages/how-to-make-a-page.md
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 @@ | ||
--- | ||
title: How to make a page | ||
--- | ||
|
||
Test |
5 changes: 5 additions & 0 deletions
5
packages/astro/test/fixtures/astro-markdown-url/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,5 @@ | ||
--- | ||
import * as page from './docs/pages/how-to-make-a-page.md' | ||
--- | ||
|
||
<a id="url" href={page.url}>{page.frontmatter.title}</a> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.