-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: refactor wording * feat: add statistic poster * chore: remove log
- Loading branch information
1 parent
9bd1d5b
commit 0b05bee
Showing
17 changed files
with
142 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
18.6.0 | ||
18.12.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
import type { RequestHandler } from '@sveltejs/kit'; | ||
import { error, type RequestHandler } from '@sveltejs/kit'; | ||
import { fetchOgPosterImage } from '$lib/seo/model'; | ||
|
||
export const GET: RequestHandler = async (ctx) => { | ||
if (!ctx.params.id) { | ||
throw error(400, 'Missing package id'); | ||
} | ||
|
||
const imageBuffer = await fetchOgPosterImage('package', ctx.params.id); | ||
|
||
// 1 week. | ||
const cacheThreshold = 60 * 60 * 24 * 7; | ||
|
||
return new Response(imageBuffer, { | ||
headers: { | ||
'Content-Type': 'image/jpeg', | ||
'Cache-Control': 's-maxage=3600, stale-while-revalidate=86400' | ||
'Cache-Control': `s-maxage=${cacheThreshold}, stale-while-revalidate=${cacheThreshold + 60}` | ||
} | ||
}); | ||
}; |
16 changes: 16 additions & 0 deletions
16
web/src/routes/api/statistic/[...rest]/poster.jpeg/+server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { error, type RequestHandler } from '@sveltejs/kit'; | ||
import { fetchOgPosterImage } from '$lib/seo/model'; | ||
|
||
export const GET: RequestHandler = async ({ params }) => { | ||
if (!params.rest) { | ||
throw error(400, 'Missing path fragments'); | ||
} | ||
|
||
const imageBuffer = await fetchOgPosterImage('statistic', ...params.rest.split('/')); | ||
return new Response(imageBuffer, { | ||
headers: { | ||
'Content-Type': 'image/jpeg', | ||
'Cache-Control': 's-maxage=60, stale-while-revalidate=3600' | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
web/src/routes/statistic/github/stars/[range]/poster/+page.server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { githubTrendRanges, fetchReposByStars } from '$lib/statistics/models/github'; | ||
import { error } from '@sveltejs/kit'; | ||
import type { PageServerLoad } from './$types'; | ||
|
||
export const load: PageServerLoad = async ({ params, setHeaders }) => { | ||
setHeaders({ | ||
'Cache-Control': 's-maxage=3600, stale-while-revalidate=7200' | ||
}); | ||
|
||
// @ts-expect-error Range not picked up by type inference. | ||
const range: typeof githubTrendRanges[number] = params.range; | ||
|
||
if (!githubTrendRanges.includes(range)) { | ||
throw error(401, `Invalid range: ${range}`); | ||
} | ||
|
||
const { items } = await fetchReposByStars({ range }); | ||
|
||
return { | ||
items: items.slice(0, 3), | ||
selectedRange: range | ||
}; | ||
}; |
47 changes: 47 additions & 0 deletions
47
web/src/routes/statistic/github/stars/[range]/poster/+page.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<script lang="ts"> | ||
import Iconic from '$lib/blocks/views/Iconic.svelte'; | ||
import OpenGraphImage from '$lib/seo/views/OpenGraphImage.svelte'; | ||
import { mapRangeToLabel } from '$lib/statistics/models/github'; | ||
import type { PageData } from './$types'; | ||
export let data: PageData; | ||
const { items, selectedRange } = data; | ||
const subtitle = | ||
items && items.length | ||
? `By stars within last ${mapRangeToLabel(selectedRange)}` | ||
: `No trend yet available for last ${mapRangeToLabel(selectedRange)}`; | ||
</script> | ||
|
||
<OpenGraphImage | ||
title={`Trending R-code on GitHub`} | ||
{subtitle} | ||
titleSize="md" | ||
textVariant="fit" | ||
theme="gradient-dark-zinc" | ||
> | ||
{#if items && items.length} | ||
<div class="flex items-center space-x-16 text-[clamp(1.2rem,3vw,1.8rem)] opacity-80"> | ||
{#each items as item} | ||
<div class="flex flex-col items-center"> | ||
<div class="flex items-center space-x-1"> | ||
<span> | ||
{item.trend.stargazers_count > 0 ? '+' : ''} | ||
{item.trend.stargazers_count} | ||
</span> | ||
<Iconic name="carbon:star-filled" class="w-6 h-6" /> | ||
</div> | ||
<div class="flex items-center gap-x-2"> | ||
<img | ||
src={item.original.owner.avatar_url} | ||
class="w-7 h-7 rounded-full overflow-hidden" | ||
alt="Github avatar" | ||
loading="eager" | ||
/> | ||
{item.original.name} | ||
</div> | ||
</div> | ||
{/each} | ||
</div> | ||
{/if} | ||
</OpenGraphImage> |