Co-authored-by: Neverage <vl>
This commit is contained in:
parent
f4e0818b3f
commit
40c882a253
5 changed files with 38 additions and 1 deletions
5
.changeset/funny-beers-knock.md
Normal file
5
.changeset/funny-beers-knock.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': minor
|
||||
---
|
||||
|
||||
Fix url to find page with "index" at the end file name
|
|
@ -91,7 +91,7 @@ export async function buildCollectionPage({ astroConfig, filepath, runtime, site
|
|||
/** Build static page */
|
||||
export async function buildStaticPage({ astroConfig, buildState, filepath, runtime }: PageBuildOptions): Promise<void> {
|
||||
const { pages: pagesRoot } = astroConfig;
|
||||
const url = filepath.pathname.replace(pagesRoot.pathname, '/').replace(/(index)?\.(astro|md)$/, '');
|
||||
const url = filepath.pathname.replace(pagesRoot.pathname, '/').replace(/.(astro|md)$/, '').replace(/\/index$/, '/');
|
||||
const result = await runtime.load(url);
|
||||
if (result.statusCode !== 200) {
|
||||
let err = (result as any).error;
|
||||
|
|
24
packages/astro/test/astro-pages.test.js
Normal file
24
packages/astro/test/astro-pages.test.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
import { suite } from 'uvu';
|
||||
import * as assert from 'uvu/assert';
|
||||
import { doc } from './test-utils.js';
|
||||
import { setup, setupBuild } from './helpers.js';
|
||||
|
||||
const Pages = suite('Pages tests');
|
||||
|
||||
setup(Pages, './fixtures/astro-pages');
|
||||
setupBuild(Pages, './fixtures/astro-pages');
|
||||
|
||||
Pages('Can find page with "index" at the end file name', async ({ build, runtime }) => {
|
||||
await build().catch((err) => {
|
||||
assert.ok(!err, 'Error during the build');
|
||||
});
|
||||
|
||||
const result = await runtime.load('posts/name-with-index');
|
||||
if (result.error) throw new Error(result.error);
|
||||
|
||||
const $ = doc(result.contents);
|
||||
|
||||
assert.equal($('h1').text(), 'Name with index');
|
||||
});
|
||||
|
||||
Pages.run();
|
3
packages/astro/test/fixtures/astro-pages/snowpack.config.json
vendored
Normal file
3
packages/astro/test/fixtures/astro-pages/snowpack.config.json
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"workspaceRoot": "../../../../../"
|
||||
}
|
5
packages/astro/test/fixtures/astro-pages/src/pages/posts/name-with-index.md
vendored
Normal file
5
packages/astro/test/fixtures/astro-pages/src/pages/posts/name-with-index.md
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: 'Name with index'
|
||||
---
|
||||
|
||||
# Name with index
|
Loading…
Reference in a new issue