Fix url to find page with "index" at the end file name (#722) (#736)

Co-authored-by: Neverage <vl>
This commit is contained in:
Vl 2021-07-20 08:41:09 +07:00 committed by GitHub
parent f4e0818b3f
commit 40c882a253
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'astro': minor
---
Fix url to find page with "index" at the end file name

View file

@ -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;

View 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();

View file

@ -0,0 +1,3 @@
{
"workspaceRoot": "../../../../../"
}

View file

@ -0,0 +1,5 @@
---
title: 'Name with index'
---
# Name with index