okf

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package okf reads and writes Open Knowledge Format (OKF v0.2) concept files.

A concept is a Markdown file with YAML frontmatter whose only required key is `type`. Unknown keys are preserved on round-trip, as the spec requires.

Index

Constants

View Source
const (
	IndexFile = "index.md"
	LogFile   = "log.md"
)

Reserved file names that are not concept documents.

View Source
const GeneratedMarker = "<!-- okvault:generated -->"

GeneratedMarker marks an index.md that okvault owns and may rewrite. Hand-written index files (without the marker) are never overwritten.

View Source
const Version = "0.2"

Version is the OKF spec version this package targets.

Variables

View Source
var ErrNoFrontmatter = errors.New("okf: missing YAML frontmatter")

ErrNoFrontmatter is returned when a document has no frontmatter block.

Functions

func AppendLog

func AppendLog(src []byte, at time.Time, kind, text string) []byte

AppendLog inserts an entry into an OKF §9 log.md (date-grouped, newest first). kind is the conventional bold lead word: Creation, Update, Deprecation.

func IsGeneratedIndex

func IsGeneratedIndex(src []byte) bool

IsGeneratedIndex reports whether src is an index okvault may overwrite.

func IsReserved

func IsReserved(base string) bool

IsReserved reports whether a file base name is reserved by OKF.

func MergeLogs

func MergeLogs(a, b []byte) []byte

MergeLogs combines two versions of log.md (e.g. both sides of a merge conflict): entries from both, one section per date, newest first.

func NormalizeLog

func NormalizeLog(src []byte) []byte

NormalizeLog merges log.md sections that share a date and orders them newest first. Git merges of two branches that both logged on the same day (with `merge=union`) produce duplicate headings; this repairs them. Identical entry lines are kept once. A log with a heading that is not an ISO date is returned unchanged, for a person to fix.

func RelLink(from, to string) string

RelLink returns a relative link from the document at `from` to `to` (both vault-relative), e.g. "../tools/go.md". Relative links resolve the same way in Obsidian, GitHub and OKF consumers.

func RenderIndex

func RenderIndex(dir string, entries []IndexEntry, subdirs []string, root bool) []byte

RenderIndex renders an OKF §8 index.md for directory dir ("." for the root). Concepts are grouped into `# <type>` sections; subdirectories get a Sections list.

func ResolvePath

func ResolvePath(dir, target string) string

ResolvePath resolves a link target against the directory of the linking file. It returns "" for targets that escape the vault.

func SplitFrontmatter

func SplitFrontmatter(src []byte) (front []byte, body []byte, ok bool)

SplitFrontmatter separates a leading `---` YAML block from the body. It accepts LF and CRLF line endings.

func StripCode

func StripCode(body string) string

StripCode removes fenced code blocks and inline code spans, so references shown as examples are not treated as real links or ticket mentions.

func TitleFromPath

func TitleFromPath(path string) string

TitleFromPath derives a display title from a file name: "go-modules.md" -> "Go modules".

Types

type Concept

type Concept struct {
	Path        string   // vault-relative, forward slashes, e.g. "tools/go.md"
	Type        string   // required
	Title       string   // recommended; derived from file name when empty
	Description string   // recommended, one sentence
	Tags        []string // recommended
	Aliases     []string // Obsidian aliases; for FAQ these are question variants
	Status      string   // draft | stable | deprecated; empty means stable
	Body        string
	// contains filtered or unexported fields
}

Concept is a parsed OKF concept document.

func New

func New(path, typ string) *Concept

New creates an empty concept with the given type.

func Parse

func Parse(path string, src []byte) (*Concept, error)

Parse parses a concept document. path is the vault-relative path.

func Plain

func Plain(path string, src []byte) *Concept

Plain wraps a Markdown file that has no frontmatter, as most notes in an existing Obsidian vault do. It has no type, so it is not yet an OKF concept, but it can be searched and linked; writing it adds frontmatter.

func (*Concept) AddVerified

func (c *Concept) AddVerified(by string, at time.Time) error

AddVerified appends a `{by, at}` record to `verified`, always writing a list.

func (*Concept) Generated

func (c *Concept) Generated() (Stamp, bool)

Generated returns the `generated: {by, at}` stamp, if any.

func (*Concept) Get

func (c *Concept) Get(key string) any

Get returns a raw frontmatter value decoded into a Go value, or nil.

func (*Concept) LastVerified

func (c *Concept) LastVerified() (Stamp, bool)

LastVerified returns the most recent verification, if any.

func (*Concept) List

func (c *Concept) List(key string) []string

List returns a frontmatter key as a string list (a YAML sequence or a comma-separated scalar), for keys this package does not model, such as `tickets` or `owners`.

func (*Concept) MarkGenerated

func (c *Concept) MarkGenerated(by string, at time.Time) error

MarkGenerated records agent provenance (`generated: {by, at}`).

func (*Concept) Marshal

func (c *Concept) Marshal() ([]byte, error)

Marshal renders the concept with frontmatter. Line endings are LF.

func (*Concept) Meta

func (c *Concept) Meta() map[string]any

Meta returns all frontmatter keys decoded as a map (for display).

func (*Concept) Set

func (c *Concept) Set(key string, value any) error

Set sets a frontmatter key, keeping the position of an existing key. A nil value removes the key.

func (*Concept) StaleAfter

func (c *Concept) StaleAfter() (t time.Time, present, ok bool)

StaleAfter returns the `stale_after` instant, if set and parseable. present reports whether the key exists at all.

func (*Concept) Verified

func (c *Concept) Verified() []Stamp

Verified returns the `verified` stamps. OKF allows a list of `{by, at}` or a single mapping, which counts as a one-element list.

type IndexEntry

type IndexEntry struct {
	Path        string
	Title       string
	Type        string
	Description string
}

IndexEntry is one concept listed in a directory index.

type Link struct {
	Target string // resolved vault-relative path (markdown links) or bare name (wikilinks)
	Wiki   bool   // true for [[wikilinks]], resolved later by name
}

Link is an outgoing reference from a concept.

func ExtractLinks(from, body string) []Link

ExtractLinks returns links to other vault documents found in body. from is the vault-relative path of the document containing them. Both OKF forms are handled: "/abs/path.md" (bundle-relative) and "./rel.md".

type Stamp

type Stamp struct {
	By string    `json:"by"`
	At time.Time `json:"at"`
}

Stamp is an OKF provenance record: who did something, and when.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL