summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/funny-beers-knock.md5
-rw-r--r--packages/astro/src/build/page.ts2
-rw-r--r--packages/astro/test/astro-pages.test.js24
-rw-r--r--packages/astro/test/fixtures/astro-pages/snowpack.config.json3
-rw-r--r--packages/astro/test/fixtures/astro-pages/src/pages/posts/name-with-index.md5
5 files changed, 38 insertions, 1 deletions
diff --git a/.changeset/funny-beers-knock.md b/.changeset/funny-beers-knock.md
new file mode 100644
index 000000000..4d60a99a1
--- /dev/null
+++ b/.changeset/funny-beers-knock.md
@@ -0,0 +1,5 @@
+---
+'astro': minor
+---
+
+Fix url to find page with "index" at the end file name
diff --git a/packages/astro/src/build/page.ts b/packages/astro/src/build/page.ts
index d7e8e276c..a03fee5de 100644
--- a/packages/astro/src/build/page.ts
+++ b/packages/astro/src/build/page.ts
@@ -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;
diff --git a/packages/astro/test/astro-pages.test.js b/packages/astro/test/astro-pages.test.js
new file mode 100644
index 000000000..729f17513
--- /dev/null
+++ b/packages/astro/test/astro-pages.test.js
@@ -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();
diff --git a/packages/astro/test/fixtures/astro-pages/snowpack.config.json b/packages/astro/test/fixtures/astro-pages/snowpack.config.json
new file mode 100644
index 000000000..8f034781d
--- /dev/null
+++ b/packages/astro/test/fixtures/astro-pages/snowpack.config.json
@@ -0,0 +1,3 @@
+{
+ "workspaceRoot": "../../../../../"
+}
diff --git a/packages/astro/test/fixtures/astro-pages/src/pages/posts/name-with-index.md b/packages/astro/test/fixtures/astro-pages/src/pages/posts/name-with-index.md
new file mode 100644
index 000000000..77d59f028
--- /dev/null
+++ b/packages/astro/test/fixtures/astro-pages/src/pages/posts/name-with-index.md
@@ -0,0 +1,5 @@
+---
+title: 'Name with index'
+---
+
+# Name with index