Skip to content
Merged
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
44 changes: 44 additions & 0 deletions apps/marketing/public/nightly-sky.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/marketing/src/assets/icon-nightly.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions apps/marketing/src/layouts/Layout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const canonicalUrl = new URL(Astro.url.pathname, Astro.site);
<span class="nav-brand-name">T3 Code</span>
</a>
<div class="nav-right">
<a class="nav-link" href="/download">Download</a>
<a
class="nav-stars"
href={GITHUB_REPOSITORY_URL}
Expand Down Expand Up @@ -385,6 +386,19 @@ const canonicalUrl = new URL(Astro.url.pathname, Astro.site);
gap: 8px;
}

.nav-link {
padding: 0 10px;
color: var(--fg-muted);
font-size: 13px;
letter-spacing: -0.01em;
white-space: nowrap;
transition: color 0.18s ease;
}

.nav-link:hover {
color: var(--fg);
}

.nav-stars {
display: inline-flex;
align-items: center;
Expand Down
37 changes: 31 additions & 6 deletions apps/marketing/src/lib/releases.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
const REPO = "pingdotgg/t3code";

export const RELEASES_URL = `https://github.com/${REPO}/releases`;
export const NIGHTLY_RELEASES_URL = `${RELEASES_URL}?q=nightly&expanded=true`;

const API_URL = `https://api.github.com/repos/${REPO}/releases/latest`;
const CACHE_KEY = "t3code-latest-release";
const LATEST_API_URL = `https://api.github.com/repos/${REPO}/releases/latest`;
// The `latest` endpoint skips prereleases, so nightly needs the list. GitHub
// returns it newest first and nightlies land several times a day, so the first
// nightly tag in a small page is the current build.
const LIST_API_URL = `https://api.github.com/repos/${REPO}/releases?per_page=10`;

export type ReleaseChannel = "stable" | "nightly";

export interface ReleaseAsset {
name: string;
Expand All @@ -13,17 +19,36 @@ export interface ReleaseAsset {
export interface Release {
tag_name: string;
html_url: string;
published_at: string;
assets: ReleaseAsset[];
}

export async function fetchLatestRelease(): Promise<Release> {
const cached = sessionStorage.getItem(CACHE_KEY);
function cacheKey(channel: ReleaseChannel) {
return `t3code-${channel}-release`;
}

async function fetchStable(): Promise<Release> {
return fetch(LATEST_API_URL).then((r) => r.json());
}

async function fetchNightly(): Promise<Release> {
const list: Release[] = await fetch(LIST_API_URL).then((r) => r.json());
const nightly = Array.isArray(list)
? list.find((release) => release.tag_name?.includes("-nightly."))
: undefined;
if (!nightly) throw new Error("No nightly release in the latest page");
return nightly;
}

export async function fetchLatestRelease(channel: ReleaseChannel = "stable"): Promise<Release> {
const key = cacheKey(channel);
const cached = sessionStorage.getItem(key);
if (cached) return JSON.parse(cached);

const data = await fetch(API_URL).then((r) => r.json());
const data = channel === "nightly" ? await fetchNightly() : await fetchStable();

if (data?.assets) {
sessionStorage.setItem(CACHE_KEY, JSON.stringify(data));
sessionStorage.setItem(key, JSON.stringify(data));
}

return data;
Expand Down
Loading
Loading