changesConceptContent function

bool changesConceptContent(
  1. OkfDocument? before,
  2. OkfDocument after
)

Whether after changes the content of the concept before: its body, title, description or type, the content a generated stamp dates (OKF 0.2 ยง5.2). before is null for a concept a write creates, whose content is always new.

A field changes when its value differs by deep equality, including one that appears or is removed. Bodies compare as okf writes them, so a difference okf's serialization removes, such as line endings or a missing final newline, changes nothing. No other field, such as status, tags, relationships, generated or verified, is content.

KnowledgeWriter.prepare records generated exactly when the write creates a concept or this holds for the one it updates, and KnowledgeContentLog records its entry on the same rule; a link, a deprecation and RegenerateIndexes change no content.

Implementation

bool changesConceptContent(OkfDocument? before, OkfDocument after) {
  if (before == null) return true;
  for (final key in _contentFields) {
    if (!const DeepCollectionEquality().equals(
      before.frontmatter[key],
      after.frontmatter[key],
    )) {
      return true;
    }
  }
  String canonical(String text) =>
      OkfDocument(body: text, hasFrontmatter: false).serialize();
  return canonical(before.body) != canonical(after.body);
}