README

tcmts.content.README · #ubo6zawu · md file

content

Content collections for a tcm codebase, as a library: a namespace of pages read as typed entries, each one's frontmatter checked against a schema. tcm ships it, so tcm lib add tcm content adds the release your tcm has, with no network (and tcm lib upgrade content the one a newer tcm has). It's a tcm library, not an npm package: it holds everything its code uses but the yaml, marked and shiki packages.

import * as files from "#codebase/blog/posts";
import { collection, markdown } from "#codebase/app/lib/content";
import { z } from "zod";

export const posts = collection(files, {
  schema: z.object({ title: z.string(), date: z.iso.date() }),
  sort: (a, b) => b.data.date.localeCompare(a.data.date),
});

export const page = (name: string) => {
  const post = posts.get(name);
  return post && `<h1>${post.data.title}</h1>${markdown(post.body)}`;
};

What it has

Checked when saved

A collection says it is one (by Symbol.for("tcm.collection")), so tcm asks it about each file saved into its namespace, and refuses one that doesn't fit, saying why (content collections).

Its versions follow semver from its API, as any package's do (releases).