SPB Git

Repository Public

view.ts 7.0 KB 139 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : ORIX App Universe8 * File             : src/lib/view.ts9 * Module           : lib10 * Repository       : https://git.spboucher.ai/orix-spboucher-ai11 * Project Website  : https://www.orixlab.dev12 * Created          : 2026-11-2113 * Last Modified    : 2026-11-2114 *15 * Author           : Simon-Pierre Boucher16 * Position         : Professor of Finance17 * Institution      : Université du Québec en Outaouais (UQO)18 * Organization     : SP Boucher19 * Website          : https://spboucher.ai20 * Git              : https://git.spboucher.ai21 *22 * Preferred Contact: support@spboucher.ai23 * Development      : dev@spboucher.ai24 * Support          : support@spboucher.ai25 * Security/Admin   : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License          : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243import type { AppDoc } from "@/models/app";44import type { CardApp } from "@/models/filter";45import { listApps, type AppRow } from "./catalog";46import { href, tr, type Locale } from "./i18n";47import { imageSize } from "./images";48import { latestArtifact, type Release } from "./releases/store";49import { betaAccess } from "./testflight";5051export const iconUrl = (a: Pick<AppDoc, "slug" | "icon">) => (!a.icon ? null : a.icon.startsWith("u/") ? `/media/${a.slug}/${a.icon.slice(2)}` : `/apps/${a.slug}/${a.icon}`);52export const shotUrl = (slug: string, file: string) => (file.startsWith("u/") ? `/media/${slug}/${file.slice(2)}` : `/apps/${slug}/${file}`);53export const downloadUrl = (r: Pick<Release, "slug" | "version" | "tag" | "asset_name">) => `/download/${r.slug}/${encodeURIComponent(r.version ?? r.tag)}/${encodeURIComponent(r.asset_name)}`;5455/**56 * The one place that decides what a primary button does. A download exists only for a published, verified57 * image; a TestFlight link only for a public invitation verified as open; everything else leads to the page.58 */59export function primaryAction(app: AppDoc, locale: Locale, artifact: Release | null = latestArtifact(app.slug)): CardApp["action"] {60  if (app.status !== "unavailable") {61    if (artifact && app.platforms.includes("macos")) return { kind: "download", href: downloadUrl(artifact) };62    const beta = betaAccess(app);63    const store = app.distribution.find((d) => d.channel === "appstore-ios" && d.state === "public" && d.url?.startsWith("https://apps.apple.com/"));64    if (store?.url) return { kind: "appstore", href: store.url };65    if (beta.kind === "join") return { kind: "testflight", href: beta.url };66  }67  return { kind: "details", href: href(locale, `/apps/${app.slug}`) };68}6970export function toCard(row: AppRow, locale: Locale): CardApp {71  const a = row.app;72  return {73    slug: a.slug, name: a.name, tagline: tr(a.tagline, locale), summary: tr(a.summary, locale), category: a.category, platforms: a.platforms,74    status: a.status, platformStatus: a.platformStatus ?? {}, version: a.status === "beta" || a.status === "available" ? a.version : null, icon: iconUrl(a), accent: a.accent, order: a.order,75    updatedAt: row.updatedAt, featured: !!a.featured, keywords: a.features.map((f) => tr(f.title, locale)).join(" "),76    action: primaryAction(a, locale),77  };78}7980export const cards = (locale: Locale): CardApp[] => listApps().map((r) => toCard(r, locale));8182/**83 * The line-up as the home page presents it: one list per device family, in the editorial order below.84 * An application listed in both families (ORIX Astra, ORIX Navigator) carries, in each list, the status and85 * the action of that family only.86 */87const MAC_ORDER = ["astra", "clean", "convert", "docs", "sheet", "sonata", "prism", "navigator", "monitor"];88const MOBILE_ORDER = ["alarm", "arcade", "astra", "calc", "camera", "maps", "scan", "audio", "navigator"];89const rank = (order: string[], slug: string) => { const i = order.indexOf(slug); return i < 0 ? order.length : i; };9091function familyAction(app: AppDoc, family: "mac" | "mobile", locale: Locale): CardApp["action"] {92  const status = app.platformStatus?.[family === "mac" ? "macos" : "ios"] ?? app.status;93  if (status !== "unavailable") {94    if (family === "mac") {95      const artifact = latestArtifact(app.slug);96      if (artifact) return { kind: "download", href: downloadUrl(artifact) };97    } else {98      const store = app.distribution.find((d) => d.channel === "appstore-ios" && d.state === "public" && d.url?.startsWith("https://apps.apple.com/"));99      if (store?.url) return { kind: "appstore", href: store.url };100      const beta = betaAccess(app);101      if (beta.kind === "join") return { kind: "testflight", href: beta.url };102    }103  }104  return { kind: "details", href: href(locale, `/apps/${app.slug}`) };105}106107export function lineup(locale: Locale): { mac: CardApp[]; mobile: CardApp[] } {108  const rows = listApps();109  const family = (f: "mac" | "mobile") => {110    const platform = f === "mac" ? "macos" : "ios";111    const order = f === "mac" ? MAC_ORDER : MOBILE_ORDER;112    return rows113      .filter((r) => r.app.platforms.includes(platform) || (f === "mobile" && r.app.platforms.includes("ipados")))114      .map((r) => {115        const card = toCard(r, locale);116        const status = r.app.platformStatus?.[platform] ?? r.app.status;117        return { ...card, status, version: status === "available" || status === "beta" ? card.version : null, platforms: card.platforms.filter((p) => (f === "mac" ? p === "macos" : p !== "macos")), action: familyAction(r.app, f, locale) };118      })119      .sort((a, b) => rank(order, a.slug) - rank(order, b.slug) || a.order - b.order);120  };121  return { mac: family("mac"), mobile: family("mobile") };122}123124/** A released application with a real capture, for the scrolling showcase of the home page. */125export type ShowcaseApp = CardApp & { device: "iphone" | "ipad" | "mac"; shot: { src: string; width: number; height: number; alt: string } };126127export async function showcase(locale: Locale): Promise<ShowcaseApp[]> {128  const out: ShowcaseApp[] = [];129  for (const row of listApps()) {130    const a = row.app;131    if (a.status !== "available") continue;132    const hero = a.screenshots.find((s) => s.hero) ?? a.screenshots[0];133    const size = hero ? await imageSize(a.slug, hero.file) : null;134    if (!hero || !size) continue;135    out.push({ ...toCard(row, locale), device: hero.device, shot: { src: shotUrl(a.slug, hero.file), ...size, alt: tr(hero.caption, locale) } });136  }137  return out;138}139
Files main
Menu

Theme