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 (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 }
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 }