Skip to content

Every analytics tool wants a subscription. And your data. I built Twiligent instead. YouTube stats. Instagram stats. One dashboard. Runs locally on your machine.

1.1 KB
Raw Blame
// shared by the build plugin that writes the index and the browser code that reads it, so both agree

export interface SearchDocument {
  id: string;
  // the page path, with the heading anchor for a section: docs/self-host/redis#create-a-database
  href: string;
  // the heading, or the page title for the part above the first heading
  title: string;
  page: string;
  text: string;
}

export const SEARCH_OPTIONS = {
  fields: ['title', 'page', 'text'],
  storeFields: ['href', 'title', 'page'],
  searchOptions: { boost: { title: 3, page: 1.5 }, prefix: true, fuzzy: 0.2 },
};

// heading text to an anchor id: lowercase words joined by hyphens
export function slugify(text: string): string {
  return text
    .toLowerCase()
    .replace(/[^a-z0-9\s-]/g, '')
    .trim()
    .replace(/\s+/g, '-')
    .replace(/-+/g, '-');
}

// what a screen reader hears after each search, since the results appear without moving focus
export function resultCountText(count: number): string {
  if (count === 0) return 'No pages match';
  return count === 1 ? '1 result' : `${count} results`;
}