zord_tree

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2024 License: MIT Imports: 15 Imported by: 1

README

zord-tree

Build Status

Library for golang to build articles tree from file system. The file should be in specific format to hold meta data, id and content. For now it supports markdown format.

Process should go in two steps:

  • populate existing source directory with formatting files, add missing id and meta data
  • separate images and other data files to ex. __a root directory
  • build Tree to operate on object for your app
  • read file content without meta data by path

File and tree format

Category

During building Tree directory path is converted into array of categories. So, file in path linux/command/video will get categories: linux, command, video.

Split line

File meta should be split by --- line. If there is markdown formating to mark header, first such case (---) will be formatted to contain empty line. Example:

Text
---

will become

Text

---
Meta data

Meta data separated by lines and in format * name: value. By default library supports tags as comma separated array. During populating tree it adds missing id in abcex format and empty meta data lines and saves in source directory.

Additionally it moves images and other not .md files to separate __a root directory and replace in content linked urls.

There is possibility to add custom default value. That is passed with custom function what returns string.

File structure
* tags: linux,command,video
* meta1: example
* meta2: some long description

---

Hear goes content. It can be written in html, markdown or whatever what can be processed later

Usage

There are two main commands: PopulateTree to prepare source (format, add metadata and add Id) and separate images and other data files and BuildTree to get object of tree.

Also both commands use Config object that can be prepared by NewConfig command. With it can be configurable readable formats, attachment directory, custom meta and excludes (not movable files by regexp).

Tree object has methods: FileById to get File by Id, Slice to get sub-tree of given path and Filter to filter tree by filter. Filter contains array of meta key and searching value. tag key is searched as equal and other meta values of keys can contain part.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PopulateTree

func PopulateTree(sourcePath string, meta []string, config Config) error

func ReadFileContent added in v0.1.2

func ReadFileContent(file File) (string, error)

Types

type Config added in v0.4.0

type Config struct {
	ReadableFormats   []string
	AttachmentDirName string
	CustomMeta        map[string]func() string
	Excludes          []string
}

func NewConfig added in v0.4.0

func NewConfig(
	readableFormats []string,
	attachmentDirName string,
	customMeta map[string]func() string,
	excludes []string,
) Config

type File

type File struct {
	Id       string
	Name     string
	FullPath string
	Category []string
	Tags     []string
	Meta     map[string]string
}

type Tree

type Tree struct {
	Path  string
	Dirs  []Tree
	Files []File
}

func BuildTree

func BuildTree(dirPath string, meta []string, config Config) (Tree, error)

func (Tree) FileById added in v0.2.0

func (t Tree) FileById(id string) (File, error)

func (Tree) Filter added in v0.2.0

func (t Tree) Filter(filter map[string][]string) (Tree, bool)

func (Tree) Slice added in v0.2.0

func (t Tree) Slice(path string) (Tree, error)

Jump to

Keyboard shortcuts

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