commit
0264b88069
14 changed files with 188 additions and 66 deletions
@ -1,3 +1,5 @@ |
||||
# Insertion Sort |
||||
|
||||
Insertion sort is a simple sorting algorithm that builds the final sorted array (or list) one item at a time. It's much less efficient on large lists than more advanced algorithms like quicksort, heapsort, or merge sort. Still, it provides several advantages such as it's easy to understand the algorithm, it performs well with small lists or lists that are already partially sorted and it can sort the list as it receives it. The algorithm iterates, consuming one input element each repetition and growing a sorted output list. At each iteration, it removes one element from the input data, finds the location it belongs within the sorted list and inserts it there. It repeats until no input elements remain. |
||||
Insertion sort is a simple sorting algorithm that builds the final sorted array (or list) one item at a time. It's much less efficient on large lists than more advanced algorithms like quicksort, heapsort, or merge sort. Still, it provides several advantages such as it's easy to understand the algorithm, it performs well with small lists or lists that are already partially sorted and it can sort the list as it receives it. The algorithm iterates, consuming one input element each repetition and growing a sorted output list. At each iteration, it removes one element from the input data, finds the location it belongs within the sorted list and inserts it there. It repeats until no input elements remain. |
||||
|
||||
- [Insertion Sort - W3Schools](https://www.w3schools.com/dsa/dsa_algo_insertionsort.php) |
||||
|
@ -0,0 +1,17 @@ |
||||
export async function getRoadCard( |
||||
version: 'tall' | 'wide', |
||||
userId: string, |
||||
variant: 'dark' | 'light', |
||||
roadmaps: string = '', |
||||
) { |
||||
const url = new URL( |
||||
`${import.meta.env.PUBLIC_API_URL}/v1-badge/${version}/${userId}`, |
||||
); |
||||
url.searchParams.set('variant', variant); |
||||
if (roadmaps) { |
||||
url.searchParams.set('roadmaps', roadmaps); |
||||
} |
||||
|
||||
const response = await fetch(url.toString()); |
||||
return response.text(); |
||||
} |
@ -0,0 +1,34 @@ |
||||
import type { APIRoute } from 'astro'; |
||||
import { getDefaultOpenGraphImageBuffer } from '../../../lib/open-graph'; |
||||
import { getRoadCard } from '../../../lib/road-card'; |
||||
|
||||
export const prerender = false; |
||||
|
||||
type Params = { |
||||
version: 'tall' | 'wide'; |
||||
userId: string; |
||||
}; |
||||
|
||||
export const GET: APIRoute<any, Params> = async (context) => { |
||||
const { userId, version } = context.params; |
||||
|
||||
if (!userId || !version) { |
||||
const buffer = await getDefaultOpenGraphImageBuffer(); |
||||
return new Response(buffer, { |
||||
headers: { |
||||
'Content-Type': 'image/png', |
||||
}, |
||||
}); |
||||
} |
||||
|
||||
const searchParams = new URLSearchParams(context.url.searchParams); |
||||
const variant = (searchParams.get('variant') as 'dark' | 'light') || 'dark'; |
||||
const roadmaps = searchParams.get('roadmaps') || ''; |
||||
|
||||
const svg = await getRoadCard(version, userId, variant, roadmaps); |
||||
return new Response(svg, { |
||||
headers: { |
||||
'Content-Type': 'image/svg+xml', |
||||
}, |
||||
}); |
||||
}; |
Loading…
Reference in new issue