repositories

daemon-sec-cheatsheet

The cheatsheet vault for operators: AD, enumeration, exploitation, priv-esc, web, DFIR

clonegit clone https://git.daemon-sec.xyz/daemon-sec-cheatsheet.git
hacktricks.tsTypeScript46 lines1.4 KiBraw download
import { getCollection, type CollectionEntry } from 'astro:content';

export type HackTricksPage = CollectionEntry<'hacktricks'>;

export async function allHackTricks(): Promise<HackTricksPage[]> {
  return await getCollection('hacktricks');
}

export function hackTricksHref(entry: HackTricksPage): string {
  return `hacktricks/${entry.id}`;
}

export interface HackTricksSection {
  slug: string;
  title: string;
  items: HackTricksPage[];
  count: number;
}

export async function hackTricksBySection(): Promise<HackTricksSection[]> {
  const pages = await allHackTricks();
  const grouped = new Map<string, HackTricksPage[]>();
  for (const page of pages) {
    const items = grouped.get(page.data.sectionSlug) ?? [];
    items.push(page);
    grouped.set(page.data.sectionSlug, items);
  }

  return [...grouped].map(([slug, items]) => ({
    slug,
    title: items[0].data.section,
    items: items.sort((a, b) => a.data.title.localeCompare(b.data.title)),
    count: items.length,
  })).sort((a, b) => a.title.localeCompare(b.title));
}

export function prevNext(
  order: HackTricksPage[],
  current: HackTricksPage,
): { prev?: HackTricksPage; next?: HackTricksPage } {
  const index = order.findIndex((page) => page.id === current.id);
  return {
    prev: index > 0 ? order[index - 1] : undefined,
    next: index >= 0 && index < order.length - 1 ? order[index + 1] : undefined,
  };
}