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
- Variables
- func AppendLog(src []byte, at time.Time, kind, text string) []byte
- func IsGeneratedIndex(src []byte) bool
- func IsReserved(base string) bool
- func MergeLogs(a, b []byte) []byte
- func NormalizeLog(src []byte) []byte
- func RelLink(from, to string) string
- func RenderIndex(dir string, entries []IndexEntry, subdirs []string, root bool) []byte
- func ResolvePath(dir, target string) string
- func SplitFrontmatter(src []byte) (front []byte, body []byte, ok bool)
- func StripCode(body string) string
- func TitleFromPath(path string) string
- type Concept
- func (c *Concept) AddVerified(by string, at time.Time) error
- func (c *Concept) Generated() (Stamp, bool)
- func (c *Concept) Get(key string) any
- func (c *Concept) LastVerified() (Stamp, bool)
- func (c *Concept) List(key string) []string
- func (c *Concept) MarkGenerated(by string, at time.Time) error
- func (c *Concept) Marshal() ([]byte, error)
- func (c *Concept) Meta() map[string]any
- func (c *Concept) Set(key string, value any) error
- func (c *Concept) StaleAfter() (t time.Time, present, ok bool)
- func (c *Concept) Verified() []Stamp
- type IndexEntry
- type Link
- type Stamp
Constants ¶
const ( IndexFile = "index.md" LogFile = "log.md" )
Reserved file names that are not concept documents.
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.
const Version = "0.2"
Version is the OKF spec version this package targets.
Variables ¶
var ErrNoFrontmatter = errors.New("okf: missing YAML frontmatter")
ErrNoFrontmatter is returned when a document has no frontmatter block.
Functions ¶
func AppendLog ¶
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 ¶
IsGeneratedIndex reports whether src is an index okvault may overwrite.
func IsReserved ¶
IsReserved reports whether a file base name is reserved by OKF.
func MergeLogs ¶
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 ¶
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 ¶
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 ¶
ResolvePath resolves a link target against the directory of the linking file. It returns "" for targets that escape the vault.
func SplitFrontmatter ¶
SplitFrontmatter separates a leading `---` YAML block from the body. It accepts LF and CRLF line endings.
func StripCode ¶
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 ¶
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 Plain ¶
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 ¶
AddVerified appends a `{by, at}` record to `verified`, always writing a list.
func (*Concept) LastVerified ¶
LastVerified returns the most recent verification, if any.
func (*Concept) List ¶
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 ¶
MarkGenerated records agent provenance (`generated: {by, at}`).
func (*Concept) Set ¶
Set sets a frontmatter key, keeping the position of an existing key. A nil value removes the key.
func (*Concept) StaleAfter ¶
StaleAfter returns the `stale_after` instant, if set and parseable. present reports whether the key exists at all.
type IndexEntry ¶
IndexEntry is one concept listed in a directory index.
type Link ¶
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 ¶
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".