Skip to content

Commit 6405591

Browse files
committed
fix: map flightaware airline codes
1 parent 3caae3a commit 6405591

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/pages/posts/[slug].astro

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,20 @@ const dateGroups = Object.entries(groupedByDate);
5555
5656
const flights = (post.data.flights || []).map(resolveFlightSchedule);
5757
const normalizeFlightNo = (flightNo: string) => flightNo.replace(/[^a-zA-Z0-9]/g, '').toUpperCase();
58+
const flightAwareAirlineCodes: Record<string, string> = {
59+
KE: 'KAL',
60+
LJ: 'JNA',
61+
};
62+
const getFlightAwareFlightNo = (flightNo: string) => {
63+
const normalizedFlightNo = normalizeFlightNo(flightNo);
64+
const match = normalizedFlightNo.match(/^([A-Z]+)(\d.*)$/);
65+
if (!match) return normalizedFlightNo;
66+
67+
const [, airlineCode, flightNumber] = match;
68+
return `${flightAwareAirlineCodes[airlineCode] || airlineCode}${flightNumber}`;
69+
};
5870
const getFlightAwareUrl = (flightNo: string) => (
59-
`https://www.flightaware.com/live/flight/${normalizeFlightNo(flightNo)}`
71+
`https://www.flightaware.com/live/flight/${getFlightAwareFlightNo(flightNo)}`
6072
);
6173
const getFlightSearchUrl = (flight: typeof flights[number]) => {
6274
const query = [

0 commit comments

Comments
 (0)