import { defineCollection, z } from 'astro:content';
import { glob } from 'astro/loaders';
// Every cheatsheet is a markdown file under src/content/sheets/<category>/.
// Nav + taxonomy are driven by the `category` frontmatter, not the folder.
const sheets = defineCollection({
loader: glob({ pattern: '**/*.{md,mdx}', base: './src/content/sheets' }),
schema: z.object({
title: z.string(),
description: z.string().default(''),
category: z.string(),
// Additional shelves share the canonical sheet and URL.
alsoIn: z.array(z.string()).default([]),
// Optional second-level grouping shown as sub-sections on a busy
// category page (Active Directory has 130+ sheets). Derived from the
// source vault path by scripts/stamp-subcategory.py.
subcategory: z.string().optional(),
// Optional editorial order inside a subcategory. The CPTS workflow uses
// this to preserve attack-stage order instead of sorting stage names A→Z.
order: z.number().int().nonnegative().optional(),
tags: z.array(z.string()).default([]),
tools: z.array(z.string()).default([]),
difficulty: z.enum(['beginner', 'intermediate', 'advanced']).default('intermediate'),
// Accept a quoted string or a bare YAML date; always expose YYYY-MM-DD.
updated: z
.union([z.string(), z.date()])
.optional()
.transform((v) => (v instanceof Date ? v.toISOString().slice(0, 10) : v)),
source: z.string().optional(),
// Third-party provenance. `source` above records only the vault path a sheet
// was imported from, which says nothing about who wrote it; these fields
// record the real upstream so the page can credit it. Set them together.
// `none` means the upstream publishes no licence at all — that grants no
// right to copy, so such a sheet must be a link-only stub, not a mirror.
upstreamName: z.string().optional(),
upstreamUrl: z.string().url().optional(),
upstreamAuthor: z.string().optional(),
upstreamLicense: z.enum(['MIT', 'BSD-2-Clause', 'BSD-3-Clause', 'Apache-2.0', 'none', 'proprietary']).optional(),
upstreamRelation: z.enum(['verbatim', 'derived', 'inspired', 'link-only']).optional(),
// The notice MIT/BSD/Apache require to travel with a copy.
upstreamCopyright: z.string().optional(),
// Secondary provenance, for a sheet that draws on more than one upstream.
// The flat `upstream*` fields above hold a single source, which is enough
// for a sheet that *is* a copy or a rewrite of one thing; it cannot express
// a sheet that reproduces an MIT cheatsheet and also folds in a section
// derived from somewhere else. Each entry credits one source and says in
// `note` what it actually contributed, so the credit is specific rather
// than a wall of links. Rendered by SheetReferences at the foot of the page.
references: z
.array(
z.object({
name: z.string(),
url: z.string().url(),
author: z.string().optional(),
license: z
.enum(['MIT', 'BSD-2-Clause', 'BSD-3-Clause', 'Apache-2.0', 'CC-BY-NC-4.0', 'none', 'proprietary'])
.optional(),
relation: z.enum(['verbatim', 'derived', 'inspired', 'link-only']).optional(),
note: z.string().optional(),
}),
)
.default([]),
// When set, the sheet embeds/links a PDF that lives in public/pdfs/<pdf>.
pdf: z.string().optional(),
draft: z.boolean().default(false),
}),
});
// Mirror of PayloadsAllTheThings (MIT, swisskyrepo). Generated by
// scripts/sync-payloads.py — do not hand-edit files under src/content/payloads.
const payloads = defineCollection({
loader: glob({ pattern: '**/*.md', base: './src/content/payloads' }),
schema: z.object({
title: z.string(),
topic: z.string(),
topicSlug: z.string(),
sourcePath: z.string(),
sourceUrl: z.string(),
sha: z.string(),
isReadme: z.boolean().default(false),
}),
});
// Mirror of InternalAllTheThings (swisskyrepo). Generated by
// scripts/sync-internal.py — do not hand-edit files under src/content/internal.
const internal = defineCollection({
loader: glob({ pattern: '**/*.md', base: './src/content/internal' }),
schema: z.object({
title: z.string(),
section: z.string(),
sectionSlug: z.string(),
sourcePath: z.string(),
sourceUrl: z.string(),
sha: z.string(),
isIndex: z.boolean().default(false),
}),
});
// Curated HackTricks mirror (CC BY-NC 4.0, Carlos Polop and contributors).
// Generated by scripts/sync-hacktricks.py. The collection is kept separate
// from hand-authored sheets so its non-commercial licence and provenance stay
// visible on every page.
const hacktricks = defineCollection({
loader: glob({ pattern: '**/*.md', base: './src/content/hacktricks' }),
schema: z.object({
title: z.string(),
section: z.string(),
sectionSlug: z.string(),
sourcePath: z.string(),
sourceUrl: z.string().url(),
sha: z.string(),
isIndex: z.boolean().default(false),
modified: z.boolean().default(true),
license: z.literal('CC-BY-NC-4.0'),
}),
});
export const collections = { sheets, payloads, internal, hacktricks };