Documentation ¶
Index ¶
- Variables
- type Node
- func (n *Node) Asset(name string) (*NodeAsset, error)
- func (n *Node) Assets() ([]*NodeAsset, error)
- func (n *Node) Authors() []*author.Author
- func (n *Node) CalculateHash() (string, error)
- func (n *Node) Create() error
- func (n *Node) CreateDoc(name string, contents []byte) error
- func (n *Node) CreateMeta(name string, meta *NodeMeta) error
- func (n *Node) Crumbs(get NodeGetter) []*Node
- func (n *Node) Custom() interface{}
- func (n *Node) Description() string
- func (n *Node) Docs() ([]*NodeDoc, error)
- func (n *Node) Keywords() []string
- func (n *Node) Load() error
- func (n *Node) LookupURL() string
- func (n *Node) Modified() (time.Time, error)
- func (n *Node) Name() string
- func (n *Node) Order() uint64
- func (n *Node) Related(get NodeGetter) []*Node
- func (n *Node) Tags() []string
- func (n *Node) Title() string
- func (n *Node) URL() string
- func (n *Node) UnnormalizedURL() string
- func (n *Node) Version() string
- type NodeAsset
- type NodeDoc
- func (d NodeDoc) CleanText() ([]byte, error)
- func (d NodeDoc) Components() ([]*NodeDocComponent, error)
- func (d NodeDoc) HTML(treePrefix string, nodeURL string, nodeGet NodeGetter, nodeSource string) ([]byte, error)
- func (d NodeDoc) Name() string
- func (d NodeDoc) Order() uint64
- func (d NodeDoc) Raw() ([]byte, error)
- func (d NodeDoc) Title() string
- type NodeDocComponent
- type NodeDocTransformer
- type NodeGetter
- type NodeMeta
- type NodesGetter
- type Tree
- func (t *Tree) CalculateHash() (string, error)
- func (t *Tree) Get(url string) (ok bool, n *Node, err error)
- func (t *Tree) GetAll() []*Node
- func (t *Tree) NeighborNodes(current *Node) (prev *Node, next *Node, err error)
- func (t *Tree) String() string
- func (t *Tree) Sync() error
- func (t *Tree) TotalNodes() uint16
Constants ¶
This section is empty.
Variables ¶
var ( // Basenames matching this pattern are considered configuration files. NodeMetaRegexp = regexp.MustCompile(`(?i)^(index|meta)\.(json|ya?ml)$`) // Basenames matching this pattern are considered documents. NodeDocsRegexp = regexp.MustCompile(`(?i)^.*\.(md|markdown|html?|txt)$`) // Files that are not considered to be assets in addition to node // meta and doc files. NodeAssetsIgnoreRegexp = regexp.MustCompile(`(?i)^(dsk|dsk\.(json|ya?ml)|AUTHORS\.txt|empty)$`) // Characters that are ignored when looking up an URL, // i.e. "foo/bar baz" and "foo/barbaz" are than equal. NodeLookupURLIgnoreChars = regexp.MustCompile(`[\s\-_]+`) // Patterns for extracting order number and title from a node's // path/URL segment in the form of 06_Foo. As well as for // "slugging" the URL/path segment. NodePathTitleRegexp = regexp.MustCompile(`^0?(\d+)[_,-]+(.*)$`) NodePathInvalidCharsRegexp = regexp.MustCompile(`[^A-Za-z0-9-_]`) NodePathMultipleDashRegexp = regexp.MustCompile(`-+`) )
var (
ErrTreeRootNotFound = errors.New("no tree root found")
)
Functions ¶
This section is empty.
Types ¶
type Node ¶
type Node struct { // Ensure node is locked for writes, when updating the node's hash // value cache. sync.RWMutex // Absolute path to the node's directory. Path string // The parent ddt. If this is the root node, left unset. Parent *Node // A list of children nodes. Children []*Node // contains filtered or unexported fields }
Node represents a directory inside the design definitions tree.
func NewNode ¶
NewNode constructs a new Node using its path in the filesystem and initalizing fields. The initialization must finalized by using Load().
func (*Node) Asset ¶
Asset returns the that matches name. Generally we don't support order numbers on assets, they make sense on documents and design aspects but do not make sense on assets.
However users may assume, they can be used on assets too.
Assuming 02_cat.jpg exists in the filesystem, both a request for 02_cat.jpg and a request for cat.jpg will succeed.
However there is one side-effect that is undesired but okay for us: having cat.jpg and requesting 02_cat.jpg or using any other order prefix will succeed. This behavior is not guaranteed to work in future versions.
func (*Node) Assets ¶
Assets are all files inside the node directory excluding system files, node documents and meta files.
func (*Node) Authors ¶
Returns a list of node authors; wil use the given authors database to augment data with full name if possible.
func (*Node) CalculateHash ¶
CalculateHash calculates a good enough hash over all aspects of the node, including its children. Excludes parent in calculation, as it would cause an infinite loop.
Will cache the once calculated hash, and use the cached on if exists. The assumption here is that the node will be entirely re-initialized when it changes.
func (*Node) CreateMeta ¶
CreateMeta creates a meta file in the node's directory using the given name as the file name. The provided Meta struct, does not need to have its path initialized, this is done by this function.
func (*Node) Crumbs ¶
func (n *Node) Crumbs(get NodeGetter) []*Node
Returns a list of crumbs. The last element is the current active one. Does not include a root ddt.
func (*Node) Description ¶
Returns the full description of the ddt.
func (*Node) Docs ¶
Returns a slice of documents for this ddt.
The provided tree URL prefix will be used to resolve and make relative links inside the document absolute. This is usually something like: /api/v1/tree
func (*Node) Keywords ¶
Returns a list of keywords terms. Deprecated, will be removed once APIv1 search support is removed.
func (*Node) Load ¶
Load node meta data from the first config file found and further initialize Node.
func (*Node) Modified ¶
Modified finds the most recent modified time of this node, including assets and docs.
func (*Node) Related ¶
func (n *Node) Related(get NodeGetter) []*Node
Returns a list of related nodes.
func (*Node) Title ¶
The node's computed title with any ordering numbers stripped off, usually for display purposes. We normalize the title string to make sure all special characters are represented in their composed form. Some filesystems store filenames in decomposed form. Using these directly in the frontend led to visual inconsistencies. See: https://blog.golang.org/normalization
func (*Node) URL ¶
Returns the normalized URL path fragment, that can be used to address this node i.e Input/Password.
func (*Node) UnnormalizedURL ¶
Returns the unnormalized URL path fragment.
type NodeAsset ¶
type NodeAsset struct { // Absolute path to the file. Path string // The URL, relative to the design defintion tree root. URL string // contains filtered or unexported fields }
An emebeddable or otherwise downloadable file.
func (NodeAsset) Dimensions ¶
Dimensions for asset media when these are possible to detect. "ok" indicates if the format was supported.
func (NodeAsset) Name ¶
Name is the basename of the file. The canonical name of the asset intentionally contains (non-functional) order numbers if the are used.
type NodeDoc ¶
type NodeDoc struct {
// contains filtered or unexported fields
}
NodeDoc is a document file.
func (NodeDoc) Components ¶
func (d NodeDoc) Components() ([]*NodeDocComponent, error)
Components as found in the raw document.
func (NodeDoc) HTML ¶
func (d NodeDoc) HTML(treePrefix string, nodeURL string, nodeGet NodeGetter, nodeSource string) ([]byte, error)
HTML as parsed from the underlying file. The provided tree prefix and node URL will be used to resolve relative source and node URLs inside the documents, to i.e. make them absolute.
func (NodeDoc) Title ¶
Title of the document and computed with any ordering numbers and the extension stripped off, usually for display purposes. We normalize the title string to make sure all special characters are represented in their composed form. For more on this topic see the docblock of Node.Title().
type NodeDocComponent ¶
type NodeDocComponent struct { Id int // Unique ID Raw string Level int // Nesting level Position int // Start position inside document. Length int // Length of the component code. }
func NewNodeDocComponent ¶
func NewNodeDocComponent(raw string, level int, position int) *NodeDocComponent
func (*NodeDocComponent) Placeholder ¶
func (c *NodeDocComponent) Placeholder() string
type NodeDocTransformer ¶
type NodeDocTransformer struct {
// contains filtered or unexported fields
}
NodeDocTransformer post-processes given HTML after it has been processed file-type specific parsers. See NodeDoc.HTML().
Makes the HTML more portable, by turning relative source links into absolute ones. We need to have all source URLs absolute as documents can be placed anywhere inside the frontend's URL structure.
All references to nodes and node assets are discovered and re-constructed as an absolute URL, using the canonical node URL.
All other relative links are made absolute using treeBase.
For elements referencing a node, "data-node" attribute containing the node's ref-URL is added. For elements referencing a node asset, a "data-node" attribute containing the node's ref-URL is added and a "data-node-asset" attribute with the name of the asset is added.
Dimension attributes are added to images of nodes.
HTML inside <code> tags is escaped while preventing double escaping.
func NewNodeDocTransformer ¶
func NewNodeDocTransformer(treePrefix string, nodeURL string, nodeGet NodeGetter, nodeSource string) (*NodeDocTransformer, error)
NewNodeDocTransformer returns an initialized NodeDocTransformer, it'll derive values for nodeBase and treeBase from the treePrefix and nodeURL.
func (NodeDocTransformer) ProcessHTML ¶
func (dt NodeDocTransformer) ProcessHTML(contents []byte) ([]byte, error)
ProcessHTML is the main entry point.
type NodeGetter ¶
NodeGetter retrieves nodes from the tree, using the node's relative URL. When the node cannot be found ok will be false.
type NodeMeta ¶
type NodeMeta struct { // Email addresses of node authors. Authors []string `json:"authors,omitempty" yaml:"authors,omitempty"` Description string `json:"description,omitempty" yaml:"description,omitempty"` Related []string `json:"related,omitempty" yaml:"related,omitempty"` Tags []string `json:"tags,omitempty" yaml:"tags,omitempty"` Custom interface{} `json:"custom,omitempty" yaml:"custom,omitempty"` // Freeform version string. Version string `json:"version,omitempty" yaml:"version,omitempty"` // Deprecated, will be removed once APIv1 search support is removed. Keywords []string `json:"keywords,omitempty" yaml:"keywords,omitempty"` // contains filtered or unexported fields }
Metadata parsed from node configuration.
type Tree ¶
type Tree struct { // Ensures the tree is locked, when it is being synced, to // prevent reads in the middle of syncs. sync.RWMutex // The absolute root path of the tree. Path string // The root node and entry point to the acutal tree. Root *Node `json:"root"` // contains filtered or unexported fields }
func NewTree ¶
func NewTree( path string, cdb config.DB, adb author.DB, mdb meta.DB, b *bus.Broker, ) (*Tree, error)
NewTree construct and initializes a Tree.
func (*Tree) CalculateHash ¶
func (*Tree) NeighborNodes ¶
Returns the neighboring previous and next nodes for the given current ddt. When current node is the last or first node, the behavior is not to wrap around.
Determines the next node following the given current ddt. This may either be the first child of the given node, if there are none the sibling node and - walking up the tree - if there is none the parents sibling ddt. The algorithm for determing the previous node is analogous.
func (*Tree) Sync ¶
Sync recursively crawls the given root directory, constructing a tree of nodes. Will rebuild the entire tree on every sync. This makes the algorithm really simple - as we don't need to do branch selection - but also slow.
Nodes that are discover but fail to finalize their initialization using Node.Load() will not be skipped but kept in tree in a semi-initialized way. So that the their children are not disconnected and no gaps exist in tree branches.
It will not descend into directories it considers hidden (their name is prefixed by a dot), except when the given directory itself is dot-hidden.
func (*Tree) TotalNodes ¶
Returns the number of total nodes in the tree.