feat(index): add exclude index config (#41)
This commit is contained in:
parent
18d4e79741
commit
38b4cb815f
6 changed files with 64 additions and 14 deletions
|
|
@ -11,9 +11,11 @@ import (
|
|||
)
|
||||
|
||||
type initializeCommand struct {
|
||||
VaultName string `json:"vaultName"`
|
||||
VaultPath string `json:"vaultPath"`
|
||||
TemplateDirectory string `json:"templateDirectory"`
|
||||
VaultName string `json:"vaultName"`
|
||||
VaultPath string `json:"vaultPath"`
|
||||
TemplateDirectory string `json:"templateDirectory"`
|
||||
ExcludeIndexFiles []string `json:"excludeIndexFiles"`
|
||||
OverrideDefaultIgnores bool `json:"overrideDefaultIgnores"`
|
||||
}
|
||||
|
||||
type InitializeHandler struct {
|
||||
|
|
@ -32,7 +34,12 @@ func (h InitializeHandler) Handle(ctx context.Context, raw json.RawMessage) (any
|
|||
return nil, err
|
||||
}
|
||||
|
||||
store := store.NewVaultStore(cmd.VaultName, cmd.VaultPath, cmd.TemplateDirectory)
|
||||
store := store.NewVaultStore(
|
||||
cmd.VaultName,
|
||||
cmd.VaultPath,
|
||||
cmd.TemplateDirectory,
|
||||
cmd.ExcludeIndexFiles,
|
||||
cmd.OverrideDefaultIgnores)
|
||||
|
||||
err := persistence.InitializeDBContext(store.Config.VaultName())
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -8,10 +8,11 @@ import (
|
|||
"slices"
|
||||
"strings"
|
||||
|
||||
filehandling "github.com/KristianJBorgwarth/dendrite.daemon/core/file_handling"
|
||||
"github.com/KristianJBorgwarth/dendrite.daemon/core/file_handling"
|
||||
"github.com/KristianJBorgwarth/dendrite.daemon/core/models"
|
||||
"github.com/KristianJBorgwarth/dendrite.daemon/persistence"
|
||||
"github.com/KristianJBorgwarth/dendrite.daemon/persistence/repositories"
|
||||
"github.com/KristianJBorgwarth/dendrite.daemon/persistence/store"
|
||||
)
|
||||
|
||||
type IIndexRebuilder interface {
|
||||
|
|
@ -136,7 +137,7 @@ func (r *indexRebuilder) readFiles(vault string) ([]*filehandling.File, error) {
|
|||
}
|
||||
|
||||
func (r *indexRebuilder) IsValidDirectory(path string) bool {
|
||||
ignoredDirs := []string{".git", ".templates", "temp"}
|
||||
ignoredDirs := store.GetVaultStore().GetExcludeIndexFiles()
|
||||
for part := range strings.SplitSeq(path, string(filepath.Separator)) {
|
||||
if slices.Contains(ignoredDirs, part) {
|
||||
return false
|
||||
|
|
|
|||
BIN
dendrite
BIN
dendrite
Binary file not shown.
|
|
@ -1,13 +1,28 @@
|
|||
package persistenceconfig
|
||||
|
||||
type VaultConfiguration struct {
|
||||
name string
|
||||
path string
|
||||
templateDirectory string
|
||||
name string
|
||||
path string
|
||||
templateDirectory string
|
||||
exludeIndexFiles []string
|
||||
defaultExcludes []string
|
||||
overrideDefaultIgnores bool
|
||||
}
|
||||
|
||||
func NewVaultConfiguration(vaultName, vaultPath, templateDirectory string) *VaultConfiguration {
|
||||
return &VaultConfiguration{name: vaultName, path: vaultPath, templateDirectory: templateDirectory}
|
||||
func NewVaultConfiguration(
|
||||
vaultName,
|
||||
vaultPath,
|
||||
templateDirectory string,
|
||||
excludeIndexFiles []string,
|
||||
overrideDefaultIgnores bool,
|
||||
) *VaultConfiguration {
|
||||
return &VaultConfiguration{
|
||||
name: vaultName,
|
||||
path: vaultPath,
|
||||
templateDirectory: templateDirectory,
|
||||
exludeIndexFiles: excludeIndexFiles,
|
||||
defaultExcludes: []string{".git", ".templates"},
|
||||
}
|
||||
}
|
||||
|
||||
func (vc *VaultConfiguration) VaultName() string {
|
||||
|
|
@ -21,3 +36,15 @@ func (vc *VaultConfiguration) VaultPath() string {
|
|||
func (vc *VaultConfiguration) TemplateDirectory() string {
|
||||
return vc.templateDirectory
|
||||
}
|
||||
|
||||
func (vc *VaultConfiguration) ExcludeIndexFiles() []string {
|
||||
return vc.exludeIndexFiles
|
||||
}
|
||||
|
||||
func (vc *VaultConfiguration) GetExcludeIndexFiles() []string {
|
||||
defaultIgnores := []string{".git", ".templates"}
|
||||
if vc.overrideDefaultIgnores {
|
||||
return vc.exludeIndexFiles
|
||||
}
|
||||
return append(defaultIgnores, vc.exludeIndexFiles...)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,11 +12,23 @@ type VaultStore struct {
|
|||
|
||||
var vaultStore *VaultStore
|
||||
|
||||
func NewVaultStore(vaultName, vaultPath, templateDir string) *VaultStore {
|
||||
func NewVaultStore(
|
||||
vaultName,
|
||||
vaultPath,
|
||||
templateDir string,
|
||||
exludeIndexFiles []string,
|
||||
overrideDefaultIgnores bool,
|
||||
) *VaultStore {
|
||||
if vaultStore != nil {
|
||||
return vaultStore
|
||||
}
|
||||
vaultStore = &VaultStore{Config: persistenceconfig.NewVaultConfiguration(vaultName, vaultPath, templateDir)}
|
||||
vaultStore = &VaultStore{Config: persistenceconfig.NewVaultConfiguration(
|
||||
vaultName,
|
||||
vaultPath,
|
||||
templateDir,
|
||||
exludeIndexFiles,
|
||||
overrideDefaultIgnores,
|
||||
)}
|
||||
return vaultStore
|
||||
}
|
||||
|
||||
|
|
@ -44,3 +56,6 @@ func (vs *VaultStore) fileTypeCheck(templateName string) string {
|
|||
return templateName
|
||||
}
|
||||
|
||||
func (vs *VaultStore) GetExcludeIndexFiles() []string {
|
||||
return vs.Config.GetExcludeIndexFiles()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ func NewDBFixture() *DBFixture {
|
|||
DB: dbContext.DB,
|
||||
DBPath: dbPath,
|
||||
TestContext: context.Background(),
|
||||
VaultStore: store.NewVaultStore("testVault", vaultPath, path.Join(vaultPath, "templates")),
|
||||
VaultStore: store.NewVaultStore("testVault", vaultPath, path.Join(vaultPath, "templates"), []string{}, false),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue