SPB Git

Repository Public

news.ts 5.4 KB 91 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : ORIX App Universe8 * File             : src/lib/news.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 { db } from "./database/db";44import { listApps } from "./catalog";45import { dict, href, tr, type Locale } from "./i18n";46import { allReleases } from "./releases/store";47import { iconUrl } from "./view";4849export type FeedItem = { key: string; date: string; kind: string; slug: string | null; appName: string | null; icon: string | null; title: string; body: string[]; version: string | null; href: string | null };50export type Announcement = { id: number; kind: string; app_slug: string | null; date: string; publish: "draft" | "published" | "archived"; title_en: string; title_fr: string; body_en: string; body_fr: string; updated_at: string };5152export const announcements = (all = false) => db().prepare(`SELECT * FROM announcements ${all ? "" : "WHERE publish = 'published'"} ORDER BY date DESC, id DESC`).all() as unknown as Announcement[];5354/** One entry per (application, version): a curated note wins over the bare git tag of the same version. */55export type LogEntry = { version: string; build: string | null; date: string; channel: string; notes: string[]; tag: string | null; download: { href: string; size: number | null; sha256: string | null; name: string } | null };5657export function changelog(slug: string, locale: Locale): LogEntry[] {58  const row = listApps({ all: true }).find((r) => r.slug === slug);59  if (!row) return [];60  const out = new Map<string, LogEntry>();61  for (const r of row.app.releases) out.set(r.version, { version: r.version, build: r.build ?? null, date: r.date, channel: r.channel, notes: r.notes.map((n) => tr(n, locale)), tag: null, download: null });62  for (const r of allReleases().filter((x) => x.slug === slug && (x.state === "published" || x.state === "note"))) {63    const v = r.version ?? r.tag, cur = out.get(v);64    const curated = r.notes ? (JSON.parse(r.notes) as { en: string; fr: string })[locale] : "";65    const notes = curated ? curated.split(/\n+/).filter(Boolean) : r.subject ? [r.subject] : [];66    const download = r.state === "published" && r.artifact ? { href: `/download/${slug}/${encodeURIComponent(v)}/${encodeURIComponent(r.asset_name)}`, size: r.asset_size, sha256: r.sha256_computed, name: r.asset_name } : null;67    if (cur) { cur.tag ??= r.tag; cur.download ??= download; if (!cur.notes.length) cur.notes = notes; if (download) cur.channel = "dmg"; }68    else out.set(v, { version: v, build: null, date: (r.tag_date ?? r.discovered_at).slice(0, 10), channel: download ? "dmg" : "git", notes, tag: r.tag, download });69  }70  return [...out.values()].sort((a, b) => b.date.localeCompare(a.date));71}7273/** What's New: real release records of published applications plus published editorial announcements. */74export function feed(locale: Locale): FeedItem[] {75  const t = dict(locale), items: FeedItem[] = [];76  const apps = listApps();77  for (const { slug, app } of apps) {78    for (const e of changelog(slug, locale)) {79      const kind = e.download ? "release" : e.channel.startsWith("testflight") ? "beta" : "tag";80      items.push({ key: `r:${slug}:${e.version}`, date: e.date, kind, slug, appName: app.name, icon: iconUrl(app), version: e.version,81        title: `${app.name} ${e.version}${e.build ? ` (${e.build})` : ""} — ${t.log.channels[e.channel] ?? e.channel}`, body: e.notes, href: href(locale, `/apps/${slug}#changelog`) });82    }83  }84  for (const a of announcements()) {85    const app = a.app_slug ? apps.find((r) => r.slug === a.app_slug)?.app : null;86    items.push({ key: `a:${a.id}`, date: a.date, kind: a.kind, slug: a.app_slug, appName: app?.name ?? null, icon: app ? iconUrl(app) : null, version: null,87      title: locale === "fr" ? a.title_fr : a.title_en, body: (locale === "fr" ? a.body_fr : a.body_en).split(/\n{2,}/).filter(Boolean), href: app ? href(locale, `/apps/${app.slug}`) : null });88  }89  return items.sort((a, b) => b.date.localeCompare(a.date) || a.key.localeCompare(b.key));90}91
Files main
Menu

Theme