func (c *collection) Process(ctx goldsmith.Context, f goldsmith.File) error {
	c.mtx.Lock()
	defer func() {
		f.SetValue(c.groupsKey, c.groups)
		c.files = append(c.files, f)
		c.mtx.Unlock()
	}()

	coll, ok := f.Value(c.collKey)
	if !ok {
		return nil
	}

	var collStrs []string
	switch t := coll.(type) {
	case string:
		collStrs = append(collStrs, t)
	case []string:
		collStrs = append(collStrs, t...)
	}

	for _, collStr := range collStrs {
		files, _ := c.groups[collStr]
		files = append(files, f)
		c.groups[collStr] = files
	}

	return nil
}
func (t *breadcrumbs) Process(ctx goldsmith.Context, f goldsmith.File) error {
	var parentNameStr string
	if parentName, ok := f.Value(t.parentKey); ok {
		parentNameStr, _ = parentName.(string)
	}

	var nodeNameStr string
	if nodeName, ok := f.Value(t.nameKey); ok {
		nodeNameStr, _ = nodeName.(string)
	}

	t.mtx.Lock()
	defer t.mtx.Unlock()

	node := &bcNode{File: f, parentName: parentNameStr}
	t.allNodes = append(t.allNodes, node)

	if len(nodeNameStr) > 0 {
		if _, ok := t.namedNodes[nodeNameStr]; ok {
			return fmt.Errorf("duplicate node: %s", nodeNameStr)
		}

		t.namedNodes[nodeNameStr] = node
	}

	return nil
}
Beispiel #3
0
func (lay *layout) Process(ctx goldsmith.Context, f goldsmith.File) error {
	var buff bytes.Buffer
	if _, err := buff.ReadFrom(f); err != nil {
		return err
	}

	if _, ok := f.Value(lay.layoutKey); ok {
		f.SetValue(lay.contentKey, template.HTML(buff.Bytes()))

		lay.filesMtx.Lock()
		lay.files = append(lay.files, f)
		lay.filesMtx.Unlock()
	} else {
		ctx.DispatchFile(f)
	}

	return nil
}
Beispiel #4
0
func (t *tags) Process(ctx goldsmith.Context, f goldsmith.File) error {
	tagState := &tagState{Info: t.info}

	t.mtx.Lock()
	defer func() {
		f.SetValue(t.stateKey, tagState)
		t.files = append(t.files, f)
		t.mtx.Unlock()
	}()

	tags, ok := f.Value(t.tagsKey)
	if !ok {
		return nil
	}

	tagsArr, ok := tags.([]interface{})
	if !ok {
		return nil
	}

	for _, tag := range tagsArr {
		tagStr, ok := tag.(string)
		if !ok {
			continue
		}

		tagState.Tags = append(tagState.Tags, tagStr)

		item, ok := t.info[tagStr]
		item.Files = append(item.Files, f)
		if !ok {
			item.SafeName = safeTag(tagStr)
			item.RawName = tagStr
			item.Path = t.tagPagePath(tagStr)
		}

		t.info[tagStr] = item
	}

	sort.Strings(tagState.Tags)
	return nil
}