1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-10-30 03:36:16 +00:00

Categories: Draft the API for categories package

This commit is contained in:
Timur Ismagilov 2022-03-15 23:17:40 +03:00
parent 72cbca926c
commit 94fa2e5688
2 changed files with 49 additions and 0 deletions

View File

@ -15,6 +15,7 @@ var paths struct {
configPath string
tokensJSON string
userCredentialsJSON string
categoriesJSON string
}
// HyphaeDir returns the path to hyphae storage.
@ -38,6 +39,9 @@ func TokensJSON() string { return paths.tokensJSON }
// UserCredentialsJSON returns the path to the JSON user credentials storage.
func UserCredentialsJSON() string { return paths.userCredentialsJSON }
// CategoriesJSON returns the path to the JSON categories storage.
func CategoriesJSON() string { return paths.categoriesJSON }
// FileInRoot returns full path for the given filename if it was placed in the root of the wiki structure.
func FileInRoot(filename string) string { return filepath.Join(cfg.WikiDir, filename) }
@ -67,6 +71,7 @@ func PrepareWikiRoot() error {
paths.userCredentialsJSON = filepath.Join(cfg.WikiDir, "users.json")
paths.tokensJSON = filepath.Join(paths.cacheDir, "tokens.json")
paths.categoriesJSON = filepath.Join(cfg.WikiDir, "tags.json")
return nil
}

44
hyphae/categories/tags.go Normal file
View File

@ -0,0 +1,44 @@
// Package categories provides category management.
//
// As per the long pondering, this is how categories (cats for short)
// work in Mycorrhiza:
//
// - Cats are not hyphae. Cats are separate entities. This is not as
// vibeful as I would have wanted, but seems to be more practical
// due to //the reasons//.
// - Cats are stored outside of git. Instead, they are stored in a
// JSON file, path to which is determined by files.CategoriesJSON.
// - Due to not being stored in git, no cat history is tracked, and
// cat operations are not mentioned on the recent changes page.
// - For cat A, if there are 0 hyphae in the cat, cat A does not
// exist. If there are 1 or more hyphae in the cat, cat A exists.
package categories
// For WithHypha and Contents, should the results be sorted?
// WithHypha returns what categories have the given hypha.
func WithHypha(hyphaName string) (categoryList []string) {
panic("todo")
return
}
// Contents returns what hyphae are in the category. If the returned slice is empty, the category does not exist, and vice versa.
func Contents(catName string) (hyphaList []string) {
panic("todo")
return
}
// AddHyphaToCategory adds the hypha to the category and updates the records on the disk. If the hypha is already in the category, nothing happens. This operation is async-safe.
func AddHyphaToCategory(hyphaName, catName string) {
for _, cat := range WithHypha(hyphaName) {
if cat == catName {
return
}
}
panic("todo")
}
// RemoveHyphaFromCategory removes the hypha from the category and updates the records on the disk. If the hypha is not in the category, nothing happens. This operation is async-safe.
func RemoveHyphaFromCategory(hyphaName, catName string) {
panic("todo")
}