Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

1.1 KB
Raw Blame
import type { OkfRuleId } from '../okf-rule-meta.ts';
import { fileNameFor, OKF_SCHEMA_DIR, okfSchemaPathFor } from './paths.ts';
import { OKF_FRONTMATTER_REGISTRY } from './registry.ts';

export { OKF_SCHEMA_DIR, okfSchemaPathFor };

const GENERATED_NOTE =
  'Generated by the OpenKnowledge `okf` lint plugin — do not edit. The plugin validates ' +
  'from its own compiled copy and never reads this file, so changes here have no effect ' +
  'and are overwritten when the server restarts. This describes an external format ' +
  '(Google’s Open Knowledge Format); to change what is enforced, change the rule ' +
  'toggles under Settings → this project → Plugins → OKF.';

export interface OkfSchemaFile {
  readonly path: string;
  readonly ruleId: OkfRuleId;
  readonly contents: string;
}

export function renderOkfSchemaFiles(): OkfSchemaFile[] {
  return OKF_FRONTMATTER_REGISTRY.map((entry) => ({
    path: `${OKF_SCHEMA_DIR}/${fileNameFor(entry.id)}`,
    ruleId: entry.id,
    contents: `${JSON.stringify({ $comment: GENERATED_NOTE, ...entry.schema }, null, 2)}\n`,
  }));
}