OOKNET                             [ /  search the index  ]  
──────────────────────────────────────────────────────────────────────────────────────
══════════════════════════════════════════════════════════════════════════════════════
OOKNET   [ /  search  ]  
────────────────────────────────────────────────
════════════════════════════════════════════════
 
 
master @ 52 LINES
 
[ HISTORY ]  [ UP ]
 

// Register block under the title: plain kv rows plus a linked tag row.
// One home for metadata - nothing here repeats elsewhere on the page.
import { checkGrid, len, pad } from "../../lib/ascii";
import { badgeWidth } from "../Badge/Badge";

export interface MetaEntry {
  key: string;
  value: string;
  /** Renders the value as a link. */
  href?: string;
}

export interface Props {
  entries: MetaEntry[];
  tags?: string[];
}

export const META_KEY_W = 12;
export const TAG_GAP = 2;

/** Entries with values truncated (...) to fit after the key column. */
export function layoutMeta(entries: MetaEntry[], width: number): MetaEntry[] {
  const avail = Math.max(1, width - META_KEY_W);
  return entries.map((e) => {
    const value =
      len(e.value) > avail ? [...e.value].slice(0, avail - 3).join("") + "..." : e
.value;
    checkGrid(pad(e.key, META_KEY_W) + value, width, "meta row");
    return { ...e, value };
  });
}

/** Tag badges wrapped into rows that fit after the key column. */
export function layoutMetaTags(tags: string[], width: number): string[][] {
  const avail = width - META_KEY_W;
  const rows: string[][] = [];
  let row: string[] = [];
  let used = 0;
  for (const tag of tags) {
    const w = badgeWidth(tag) + (row.length ? TAG_GAP : 0);
    if (row.length && used + w > avail) {
      rows.push(row);
      row = [tag];
      used = badgeWidth(tag);
    } else {
      row.push(tag);
      used += w;
    }
  }
  if (row.length) rows.push(row);
  return rows;
}

// Register block under the title: plain kv 
rows plus a linked tag row.
// One home for metadata - nothing here repe
ats elsewhere on the page.
import { checkGrid, len, pad } from "../../l
ib/ascii";
import { badgeWidth } from "../Badge/Badge";

export interface MetaEntry {
  key: string;
  value: string;
  /** Renders the value as a link. */
  href?: string;
}

export interface Props {
  entries: MetaEntry[];
  tags?: string[];
}

export const META_KEY_W = 12;
export const TAG_GAP = 2;

/** Entries with values truncated (...) to f
it after the key column. */
export function layoutMeta(entries: MetaEntr
y[], width: number): MetaEntry[] {
  const avail = Math.max(1, width - META_KEY
_W);
  return entries.map((e) => {
    const value =
      len(e.value) > avail ? [...e.value].sl
ice(0, avail - 3).join("") + "..." : e.value
;
    checkGrid(pad(e.key, META_KEY_W) + value
, width, "meta row");
    return { ...e, value };
  });
}

/** Tag badges wrapped into rows that fit af
ter the key column. */
export function layoutMetaTags(tags: string[
], width: number): string[][] {
  const avail = width - META_KEY_W;
  const rows: string[][] = [];
  let row: string[] = [];
  let used = 0;
  for (const tag of tags) {
    const w = badgeWidth(tag) + (row.length 
? TAG_GAP : 0);
    if (row.length && used + w > avail) {
      rows.push(row);
      row = [tag];
      used = badgeWidth(tag);
    } else {
      row.push(tag);
      used += w;
    }
  }
  if (row.length) rows.push(row);
  return rows;
}
 
──────────────────────────────────────────────────────────────────────────────────────
OOKNET
────────────────────────────────────────────────
OOKNET