Skip to content

Switch from directory to file format in Astro#2356

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

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

Conversation

@krzysdz
Copy link
Copy Markdown
Contributor

@krzysdz krzysdz commented May 28, 2026

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; currently most links don't include the trailing slash, so most internal navigation goes through a redirect - removing this redirect is a small unintentional improvement).

References:

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
@netlify
Copy link
Copy Markdown

netlify Bot commented May 28, 2026

Deploy Preview for expressjscom-preview ready!

Name Link
🔨 Latest commit b81b00c
🔍 Latest deploy log https://app.netlify.com/projects/expressjscom-preview/deploys/6a1a02e7493ad50008cdb341
😎 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: 99 (🟢 up 2 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 from c6870f9 to 951bd1f Compare May 29, 2026 00:52
@krzysdz krzysdz force-pushed the file-based-structure branch 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
Copy link
Copy Markdown
Contributor Author

krzysdz commented May 29, 2026

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). 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):

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?$/, ''),

@krzysdz krzysdz added enhancement discuss maintenance Issues/PRs related to making the website maintainable labels May 29, 2026
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.

1 participant