Skip to content

Commit

Permalink
fix(middleware): fix stable redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiralite committed Jan 10, 2025
1 parent 741b021 commit ad965c9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
7 changes: 5 additions & 2 deletions apps/website/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ async function fetchLatestVersion(packageName: string): Promise<string> {
}

try {
const { rows } = await sql`select version from documentation where name = ${packageName} order by version desc`;
const { rows } = await sql<{ version: string }>`with ordered_versions as (
select version from documentation where name = ${packageName} and version != 'main' order by string_to_array(version, '.')::int[] desc
)
select version from ordered_versions limit 1`;

return rows.map((row) => row.version).at(1) ?? 'main';
return rows[0]?.version ?? 'main';
} catch {
return '';
}
Expand Down
16 changes: 0 additions & 16 deletions apps/website/src/util/fetchLatestVersion.ts

This file was deleted.

0 comments on commit ad965c9

Please sign in to comment.