Skip to content

Switch from directory to file format in Astro#2356

Open
krzysdz wants to merge 8 commits into
expressjs:mainfrom
krzysdz:file-based-structure
Open

Switch from directory to file format in Astro#2356
krzysdz wants to merge 8 commits into
expressjs:mainfrom
krzysdz:file-based-structure

Conversation

@krzysdz

@krzysdz krzysdz commented May 28, 2026

Copy link
Copy Markdown
Contributor

The "file" format generates name.html files instead of default name/index.html. This would make old links work, even without redirects on Cloudflare level, while still allowing the current link format with no extension. The only observable difference between current version and this PR is that the URLs no longer end with a / (GitHub/Netlify serve a 301).

References:

@netlify

netlify Bot commented May 28, 2026

Copy link
Copy Markdown

Deploy Preview for expressjscom-preview ready!

Name Link
🔨 Latest commit dfb0206
🔍 Latest deploy log https://app.netlify.com/projects/expressjscom-preview/deploys/6a31da259d80c50008fb3e55
😎 Deploy Preview https://deploy-preview-2356--expressjscom-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 100 (🟢 up 3 from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@krzysdz krzysdz force-pushed the file-based-structure branch 2 times, most recently from 951bd1f to 598b82a Compare May 29, 2026 01:12
@krzysdz krzysdz marked this pull request as ready for review May 29, 2026 01:17
@krzysdz krzysdz requested a review from a team as a code owner May 29, 2026 01:17
@krzysdz

krzysdz commented May 29, 2026

Copy link
Copy Markdown
Contributor Author

EDIT: Fixed by #2390

Original comment about /index in search results

This breaks search results for API pages, which for some reason end with /index. I'm not sure if this will fix itself (after sync) or if slightly changing source file structure is necessary (krzysdz/expressjs.com@64ecc18 krzysdz/expressjs.com@981a172). I think that the current search behaviour is unexpected and should be changed whether this PR is merged or not.

@bjohansebas is there any reason why API docs live as index.mdx in separate directories instead of just name.mdx like other pages?

EDIT: Either API docs files must be moved and renamed or the code responsible for uploading pages to Orama must be changed to strip /index:

export const getDocs = async (lang) => {
const baseDir = join(CONTENT_DIR, `docs/${lang}/5x`);
const mdFiles = await collectMdFiles(baseDir);
return Promise.all(
mdFiles.map(async (file) => {
const fullPath = join(baseDir, file);
const raw = await readFile(fullPath, 'utf-8');
const { data, content } = matter(raw);
const pathSegment = relative(baseDir, fullPath).replace(/\.mdx?$/, '');
return {
title: data.title ?? basename(file).replace(/\.mdx?$/, ''),
description: data.description ?? '',
content: mdToText(content),
path: `/${lang}/${pathSegment}`,
category: 'menu.main.docs',
};
})
);
};

What should work instead of renaming files (krzysdz/expressjs.com@f1151f6 krzysdz/expressjs.com@4b1e61b):

diff --git a/scripts/orama-documents.mjs b/scripts/orama-documents.mjs
index 0b9a9668..5dd9831a 100644
--- a/scripts/orama-documents.mjs
+++ b/scripts/orama-documents.mjs
@@ -106,7 +106,7 @@ export const getApi = async (lang) => {
           const fullPath = join(baseDir, file);
           const raw = await readFile(fullPath, 'utf-8');
           const { data, content } = matter(raw);
-          const pathSegment = relative(baseDir, fullPath).replace(/\.mdx?$/, '');
+          const pathSegment = relative(baseDir, fullPath).replace(/(\/index)?\.mdx?$/, '');

           return {
             title: data.title ?? basename(file).replace(/\.mdx?$/, ''),

EDIT 2: This applies also to /resources/index.mdx and /resources/middleware/index.mdx, so doing it while uploading docs to Orama seems like a safer solution.

krzysdz added 6 commits June 17, 2026 01:01
The "file" format generates "name.html" files instead of default "name/index.html". This would make old links work, even without redirects on Cloudflare level, while still allowing the current link format with no extension.

https://docs.astro.build/en/reference/configuration-reference/#buildformat
@krzysdz krzysdz force-pushed the file-based-structure branch from d4111a0 to 9cb245c Compare June 16, 2026 23:04
@krzysdz

krzysdz commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

As a bonus, with the changes from this PR we can just enable --include-fragments and the results won't be full of false positives.

In fact using lychee with --include-fragments on this PR is how I found #2363 and #2387.

Comment thread astro.config.mjs
Comment on lines +26 to 29
build: {
format: 'file',
},
markdown: {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, quite a bit of time has passed. Other than the .html extensions, have we run into any additional issues?

To be honest, I feel like we should move forward with the current approach, especially considering the redirects that have already been put in place (which I don't have the ability to remove anyway).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, quite a bit of time has passed. Other than the .html extensions, have we run into any additional issues?

I don't think so. The thing that I found after creating this PR is that it just works with --include-fragments in lychee, which I think that we should enable. Fragment checking should also work with the current directory based version with more remapping.

To be honest, I feel like we should move forward with the current approach, especially considering the redirects that have already been put in place (which I don't have the ability to remove anyway).

The file format works with and without redirects (/page and /page.html just work, /page/ receives a 301 redirect to /page).

I initially wrote that this also lets us avoid 301s that add /, but while most links in menu don't have a trailing / (/api/express/ is the only one ending with /), links in content now have / appended since #2193 was merged (2 days ago).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

discuss enhancement maintenance Issues/PRs related to making the website maintainable

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants