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

// Directory listing rows, github-shape: NAME  LAST COMMIT  DATE.
// The name is a link; widths flex per frame and the subject column
// drops when the narrow frame can't seat it.
import { checkGrid, len, pad } from "../../lib/ascii";
import type { DirEntry } from "../../lib/git";

export interface Props {
  entries: DirEntry[];
  /** Url prefixes for links. */
  treeBase: string;
  blobBase: string;
  commitBase: string;
}

export interface ListingRow {
  name: string;
  href: string | null;
  gap1: string;
  subject: string;
  subjectHref: string;
  gap2: string;
  date: string;
}

const DATE_W = 10;
const GAP = 2;

export function layoutListing(
  entries: DirEntry[],
  width: number,
  treeBase: string,
  blobBase: string,
  commitBase = "",
  isLinked: (e: DirEntry) => boolean = () => true,
): ListingRow[] {
  const nameW = Math.min(
    Math.max(8, ...entries.map((e) => len(e.name) + (e.kind === "tree" ? 1 : 0))),
    Math.floor(width / 2) - GAP,
  );
  const subjectW = Math.max(0, width - nameW - DATE_W - GAP * 2);
  return entries.map((e) => {
    const rawName = e.kind === "tree" ? `${e.name}/` : e.name;
    const name =
      len(rawName) > nameW ? [...rawName].slice(0, nameW - 3).join("") + "..." : r
awName;
    const subject =
      subjectW < 8
        ? ""
        : len(e.subject) > subjectW
          ? [...e.subject].slice(0, subjectW - 3).join("") + "..."
          : e.subject;
    const row: ListingRow = {
      name,
      href: isLinked(e) ? `${e.kind === "tree" ? treeBase : blobBase}${e.path}/` :
 null,
      gap1: " ".repeat(nameW - len(name) + GAP),
      subject,
      subjectHref: `${commitBase}${e.hash}/`,
      gap2: " ".repeat(Math.max(GAP, width - nameW - GAP - len(subject) - len(e.da
te))),
      date: e.date,
    };
    checkGrid(row.name + row.gap1 + row.subject + row.gap2 + row.date, width, "git
 listing");
    return row;
  });
}

// Directory listing rows, github-shape: NAM
E  LAST COMMIT  DATE.
// The name is a link; widths flex per frame
 and the subject column
// drops when the narrow frame can't seat it
.
import { checkGrid, len, pad } from "../../l
ib/ascii";
import type { DirEntry } from "../../lib/git
";

export interface Props {
  entries: DirEntry[];
  /** Url prefixes for links. */
  treeBase: string;
  blobBase: string;
  commitBase: string;
}

export interface ListingRow {
  name: string;
  href: string | null;
  gap1: string;
  subject: string;
  subjectHref: string;
  gap2: string;
  date: string;
}

const DATE_W = 10;
const GAP = 2;

export function layoutListing(
  entries: DirEntry[],
  width: number,
  treeBase: string,
  blobBase: string,
  commitBase = "",
  isLinked: (e: DirEntry) => boolean = () =>
 true,
): ListingRow[] {
  const nameW = Math.min(
    Math.max(8, ...entries.map((e) => len(e.
name) + (e.kind === "tree" ? 1 : 0))),
    Math.floor(width / 2) - GAP,
  );
  const subjectW = Math.max(0, width - nameW
 - DATE_W - GAP * 2);
  return entries.map((e) => {
    const rawName = e.kind === "tree" ? `${e
.name}/` : e.name;
    const name =
      len(rawName) > nameW ? [...rawName].sl
ice(0, nameW - 3).join("") + "..." : rawName
;
    const subject =
      subjectW < 8
        ? ""
        : len(e.subject) > subjectW
          ? [...e.subject].slice(0, subjectW
 - 3).join("") + "..."
          : e.subject;
    const row: ListingRow = {
      name,
      href: isLinked(e) ? `${e.kind === "tre
e" ? treeBase : blobBase}${e.path}/` : null,
      gap1: " ".repeat(nameW - len(name) + G
AP),
      subject,
      subjectHref: `${commitBase}${e.hash}/`
,
      gap2: " ".repeat(Math.max(GAP, width -
 nameW - GAP - len(subject) - len(e.date))),
      date: e.date,
    };
    checkGrid(row.name + row.gap1 + row.subj
ect + row.gap2 + row.date, width, "git listi
ng");
    return row;
  });
}
 
──────────────────────────────────────────────────────────────────────────────────────
OOKNET
────────────────────────────────────────────────
OOKNET