Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ jobs:
with:
args: |
--root-dir $PWD/dist
--fallback-extensions html
--exclude-path dist/llms.txt
--exclude-path dist/llms/
--exclude-private
--remap "https://expressjs\.com\/((?:[^\/]+\/)*[^\/\.]+)\/?$ file://$PWD/dist/\$1/index.html"
--remap "https://expressjs\.com\/(.*\.html)$ file://$PWD/dist/\$1"
--remap "^https://expressjs\.com\/ file://$PWD/dist/"
dist/
fail: true
3 changes: 1 addition & 2 deletions .lycheeignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ https://www.npmjs.org/.*
https://github.com/.*

# Exclude 404 pages
dist/.*/404/index.html$
dist/404/index.html$
dist/(.*/)?404(\.html|/)?$

# Exclude Open Collective links
https://opencollective.com/.*
Expand Down
3 changes: 3 additions & 0 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const site = NETLIFY_PREVIEW_SITE || 'https://expressjs.com';
export default defineConfig({
redirects,
site,
build: {
format: 'file',
},
markdown: {
rehypePlugins: [
rehypeSlug,
Expand Down
2 changes: 1 addition & 1 deletion src/components/patterns/Sidebar/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type SubmenuData = {
};

export function normalizePath(path: string): string {
return path.replace(/\/$/, '');
return path.replace(/(?:\/|\.html)$/, '');
}

export function isVersioned(versioned: VersionPrefix[] | undefined, version: string): boolean {
Expand Down
12 changes: 7 additions & 5 deletions src/i18n/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ui, defaultLang, languages } from './locales';

export function getLangFromUrl(url: URL) {
const [, lang] = url.pathname.split('/');
const strippedPathname = url.pathname.replace(/\.html$/, '');
const [, lang] = strippedPathname.split('/');
if (lang in ui) return lang as keyof typeof ui;
return defaultLang;
}
Expand Down Expand Up @@ -34,7 +35,7 @@ export function getLanguageCodes(): string[] {
*/
export function createLanguagePathRegex(): RegExp {
const codes = getLanguageCodes().join('|');
return new RegExp(`^/(${codes})/`);
return new RegExp(`^/(${codes})(?:/|$)`);
}

/**
Expand All @@ -43,9 +44,10 @@ export function createLanguagePathRegex(): RegExp {
export function replaceLanguageInPath(path: string, newLang: string): string {
const langRegex = createLanguagePathRegex();

if (langRegex.test(path)) {
return path.replace(langRegex, `/${newLang}/`);
const strippedPath = path.replace(/\.html$/, '');
if (langRegex.test(strippedPath)) {
return strippedPath.replace(langRegex, `/${newLang}/`);
} else {
return `/${newLang}${path}`;
return `/${newLang}${strippedPath}`;
}
}
4 changes: 2 additions & 2 deletions src/layouts/Layout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ const pageTitle = title
? `${title} · Express.js`
: 'Express.js · Node.js web application framework';

const canonicalUrl = new URL(Astro.url.pathname, Astro.site || Astro.url.origin);
const pathname = Astro.url.pathname.replace(/\.html$/, '');
const canonicalUrl = new URL(pathname, Astro.site || Astro.url.origin);

const pathname = Astro.url.pathname.replace(/\/$/, '');
const segments = pathname.split('/').filter(Boolean);
const langSegment = segments[0] || 'en';
const restSegments = segments.slice(1);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function resolveLabel(t: (key: string) => string, labelKey?: string, segment?: s
* Build breadcrumbs
*/
export function buildBreadcrumbs(pathname: string, t: (key: string) => string): BreadcrumbItem[] {
const segments = pathname.replace(/^\/|\/$/g, '').split('/');
const segments = pathname.replace(/^\/|\/$|\.html$/g, '').split('/');

// Need at least lang + one content segment
if (segments.length < 2) return [];
Expand Down
Loading