Documentation ¶
Index ¶
- Constants
- Variables
- func ImportNode(from, to, nodeid string) error
- func MakeDex(kegdir string) error
- func MkTempNode() (string, error)
- func Publish(kegpath string) error
- func UpdateUpdated(kegpath string) error
- func Updated(kegpath string) (*time.Time, error)
- func UpdatedString(kegpath string) string
- type Dex
- func (e Dex) AsIncludes() string
- func (e Dex) ByID() Dex
- func (d Dex) Highest() int
- func (d Dex) HighestString() string
- func (d Dex) HighestWidth() int
- func (e Dex) MD() string
- func (d *Dex) MarshalJSON() ([]byte, error)
- func (d Dex) Pretty() string
- func (d Dex) PrettyLines() []string
- func (e Dex) String() string
- func (e Dex) TSV() string
- func (e Dex) WithTitleText(keyword string) Dex
- type DexEntry
- type Local
Examples ¶
Constants ¶
const IsoDateExpStr = `\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\dZ`
const IsoDateFmt = `2006-01-02 15:04:05Z`
Variables ¶
var Cmd = &Z.Cmd{ Name: `keg`, Aliases: []string{`kn`}, Summary: `manage knowledge exchange graphs (KEG)`, Version: `v0.1.0`, Copyright: `Copyright 2022 Robert S Muhlestein`, License: `Apache-2.0`, Site: `rwxrob.tv`, Source: `git@github.com:rwxrob/keg.git`, Issues: `github.com/rwxrob/keg/issues`, Commands: []*Z.Cmd{ editCmd, help.Cmd, conf.Cmd, vars.Cmd, dexCmd, createCmd, currentCmd, dirCmd, deleteCmd, latestCmd, titleCmd, initCmd, }, Shortcuts: Z.ArgMap{ `set`: {`var`, `set`}, }, ConfVars: true, Description: ` The {{cmd .Name}} command is for personal and public knowledge management as a Knowledge Exchange Graph (sometimes called "personal knowledge graph" or "zettelkasten"). Using {{cmd .Name}} you can create and share knowledge on the free, decentralized, protocol-agnostic, world-wide, Knowledge Exchange Grid. Run {{cmd "init"}} inside of a new directory to get started with a new keg. After editing the {{pre "keg"}} file you can create your first node with {{cmd "create"}}. For more about the emerging KEG 2023-01 specification and how to create content that complies for knowledge exchange and publication (while we work more on linting and validation within the {{cmd .Name}} command) have a look at https://github.com/rwxrob/keg-spec `, }
var DefaultInfoFile string
var DefaultZeroNode string
var LatestDexEntryExp = regexp.MustCompile(
`^\* (\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\dZ) \[(.*)\]\(/(\d+)\)$`,
)
var NodePaths = _fs.IntDirs
NodePaths returns a list of node directory paths contained in the keg root directory path passed. Paths returns are fully qualified and cleaned. Only directories with valid integer node IDs will be recognized. Empty slice is returned if kegroot doesn't point to directory containing node directories with integer names.
The lowest and highest integer names are returned as well to help determine what to name a new directory.
File and directories that do not have an integer name will be ignored.
Functions ¶
func ImportNode ¶
ImportNode moves the nodedir into the KEG directory for the kegid giving it the nodeid name. Import will fail if the given nodeid already existing the the target KEG.
func MakeDex ¶
MakeDex calls ScanDex and writes (or overwrites) the output to the reserved dex node file within the kegdir passed. File-level locking is attempted using the go-internal/lockedfile (used by Go itself). Both a friendly markdown file reverse sorted by time of last update (latest.md) and a tab-delimited file sorted numerically by node ID (nodes.tsv) are created.
func MkTempNode ¶
MkTempNode creates a text node directory containing a README.md file within a directory created with os.MkdirTemp and returns a full path to the README.md file itself. Directory names are always prefixed with keg-node.
func Publish ¶
Publish publishes the keg at kegpath location to its distribution targets listed in the keg file under "publish." Currently, this only involves looking for a .git directory and if found doing a git push. Git commit messages are always based on the latest node title without any verb.
func UpdateUpdated ¶
UpdateUpdated sets the updated YAML field in the keg info file.
func Updated ¶
Updated parses the most recent change time in the dex/node.md file (the first line) and returns the time stamp it contains as a time.Time. If a time stamp could not be determined returns time.
func UpdatedString ¶
UpdatedString returns Updated time as a string or an empty string if there is a error.
Example ¶
package main import ( "fmt" "github.com/rwxrob/keg" ) func main() { fmt.Println(keg.UpdatedString(`testdata/samplekeg`)) }
Output: 2022-11-17 18:34:10Z
Types ¶
type Dex ¶
type Dex []DexEntry
Dex is a collection of DexEntry structs. This allows mapping methods for its serialization to different output formats.
Example (Json) ¶
package main import ( "encoding/json" "fmt" "time" "github.com/rwxrob/keg" ) func main() { date := time.Date(2022, 12, 10, 6, 10, 4, 0, time.UTC) d := keg.DexEntry{U: date, N: 2, T: `Some title`} byt, err := json.Marshal(d) if err != nil { fmt.Println(err) } fmt.Println(string(byt)) }
Output: {"U":"2022-12-10T06:10:04Z","T":"Some title","N":2}
Example (String) ¶
package main import ( "fmt" "time" "github.com/rwxrob/keg" ) func main() { date := time.Date(2022, 12, 10, 6, 10, 4, 0, time.UTC) d := keg.DexEntry{U: date, N: 2, T: `Some title`} fmt.Println(d) fmt.Println(d.MD()) }
Output: * 2022-12-10 06:10:04Z [Some title](/2) * 2022-12-10 06:10:04Z [Some title](/2)
Example (Tsv) ¶
package main import ( "fmt" "time" "github.com/rwxrob/keg" ) func main() { date := time.Date(2022, 12, 10, 6, 10, 4, 0, time.UTC) d := keg.DexEntry{U: date, N: 2, T: `Some title`} fmt.Println(d.TSV()) }
Output: 2 2022-12-10 06:10:04Z Some title
func ParseDex ¶
ParseDex parses any input valid for to.String into a Dex pointer. FIXME: replace regular expression with pegn.Scanner instead
func (Dex) AsIncludes ¶
AsIncludes renders the entire Dex as a KEGML include list (markdown bulleted list) and cab be useful from within editing sessions to include from the current keg without leaving the terminal editor.
func (Dex) HighestWidth ¶
HighestWidth returns width of highest integer identifier.
func (Dex) MD ¶
MD renders the entire Dex as a Markdown list suitable for the standard dex/latest.md file.
func (*Dex) MarshalJSON ¶
MarshalJSON produces JSON text that contains one DexEntry per line that has not been HTML escaped (unlike the default).
func (Dex) Pretty ¶
Pretty returns a string with pretty color string with time stamps rendered in more readable way.
func (Dex) PrettyLines ¶
PrettyLines returns Pretty but each line separate and without line return.
func (Dex) String ¶
String fulfills the fmt.Stringer interface as JSON. Any error returns a "null" string.
func (Dex) WithTitleText ¶
WithTitleText filters all nodes with titles that do not contain the text substring in the title.
type DexEntry ¶
DexEntry represents a single line in an index (usually the latest.md or nodes.tsv file). All three fields are always required.
func Last ¶
Last parses and returns a DexEntry of the most recently updated node from first line of the dex/latest.md file. If cannot determine returns nil.
func (DexEntry) AsInclude ¶
Asinclude returns a KEGML include link list item without the time suitable for creating include blocks in node files.
func (DexEntry) ID ¶
ID returns the node identifier as a string instead of an integer. Returns an empty string if unable to parse the integer.
func (DexEntry) MD ¶
MD returns the entry as a single Markdown list item for inclusion in the dex/nodex.md file:
- Second last changed in UTC in ISO8601 (RFC3339)
- Current title (always first line of README.md)
- Unique node integer identifier
Note that the second of last change is based on *any* file within the node directory changing, not just the README.md or meta files.
func (*DexEntry) MarshalJSON ¶
MarshalJSON produces JSON text that contains one DexEntry per line that has not been HTML escaped (unlike the default) and that uses a consistent DateTime format. Note that the (broken) encoding/json encoder is not used at all.