All files / service-web-theme/src footer.ts

100% Statements 19/19
100% Branches 8/8
100% Functions 2/2
100% Lines 16/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92        42x         42x               42x   42x   42x               42x   42x   42x                                                                             176x 176x 175x 649x   152x 131x         165x 165x              
import type { BuildInfo } from './build-info.ts';
import type { Locale } from './locale.ts';
 
/** Dashboard, Accounts, Play, then Leaderboard. Donate is not in this row. */
export const SERVICE_NAMES = ['dashboard', 'accounts', 'play', 'leaderboard'] as const;
 
export type ServiceName = (typeof SERVICE_NAMES)[number];
 
/** Public names. Accounts is the site title (`Be-Music Accounts`), not the signed-in person's account. */
export const SERVICE_LABELS: Record<ServiceName, string> = {
  dashboard: 'Dashboard',
  accounts: 'Accounts',
  play: 'Play',
  leaderboard: 'Leaderboard',
};
 
/** The footer frame used on Accounts and Dashboard, with room for the four regions. */
export const SERVICE_FOOTER_CLASS = 'text-muted-foreground mx-auto max-w-5xl space-y-2 border-t px-4 pt-4 pb-8 text-xs';
 
export const SERVICE_FOOTER_NAV_CLASS = 'flex flex-wrap items-center gap-x-4 gap-y-1';
 
export const SERVICE_FOOTER_LINK_CLASS = 'underline underline-offset-4 hover:text-foreground';
 
/** Holder and licence of the Be-Music repository (LICENSE), as on the Leaderboard. */
/**
 * The full-width, three-column footer: build line on the left, service links in the centre, copyright on the right.
 * Stacks centred on a narrow screen.
 */
export const SERVICE_FOOTER_COLUMNS_CLASS =
  'text-muted-foreground grid w-full grid-cols-1 items-center justify-items-center gap-x-4 gap-y-1 border-t px-4 py-3 text-xs sm:grid-cols-[1fr_auto_1fr]';
 
export const SERVICE_COPYRIGHT = '© 2026 nulltask · MIT License';
 
const SERVICE_PREFIXES = ['accounts', 'play', 'leaderboard', 'donate'] as const;
 
export interface ServiceFooterInput {
  /** The service this page is. Omit it on Donate, which is not in the link row. */
  current?: ServiceName;
  /**
   * Host of the page. Preview hosts link to preview siblings. An unknown host, including local development, uses
   * production, as the Player and Leaderboard already do.
   */
  hostname?: string;
  /** Replaces the origin derived from `hostname` for that service. Keeps an env binding when one is already set. */
  origins?: Partial<Record<ServiceName, string>>;
  /** Escaped HTML that belongs only to this site. The caller escapes text and attributes. */
  siteHTML?: string;
  copyright?: string;
  buildInfo?: BuildInfo;
  /** Accessible name of the service list. */
  navLabel?: string;
  /** Extra class on the footer element, for a site that positions it. */
  className?: string;
  /**
   * Language of the Public Beta line. `both` includes English and Japanese, for the player, which keeps both on the
   * page. Omitted means English.
   */
  locale?: Locale | 'both';
  /**
   * `columns` lays the footer out in one full-width row: the build line, the service links, then this site's content
   * and the copyright. Omitted means the stacked footer.
   */
  layout?: 'stacked' | 'columns';
  /** False leaves the Public Beta line out, for a site that states it elsewhere on the page. */
  publicBeta?: boolean;
}
 
/**
 * The environment site (`be-music.app` or `preview.be-music.app`) for a public host. Dashboard is that site. The other
 * services are one label in front of it. A branch Preview URL of the preview Player uses the preview site.
 */
export function serviceSite(hostname: string): string {
  const host = hostname.toLowerCase();
  if (host.endsWith('-play-preview.be-music.workers.dev')) return 'preview.be-music.app';
  for (const prefix of SERVICE_PREFIXES) {
    if (host.startsWith(`${prefix}.`)) return host.slice(prefix.length + 1);
  }
  if (host === 'be-music.app' || host === 'preview.be-music.app') return host;
  return 'be-music.app';
}
 
/** Absolute origins of the four services next to `hostname`, each with a trailing slash. */
export function serviceOrigins(hostname: string): Record<ServiceName, string> {
  const site = serviceSite(hostname);
  return {
    dashboard: `https://${site}/`,
    accounts: `https://${site}/account`,
    play: `https://play.${site}/`,
    leaderboard: `https://leaderboard.${site}/`,
  };
}