@@ -11,18 +11,22 @@ import (
1111)
1212
1313type StaticStore struct {
14- baseDir string
15- composePath string
16- docsPath string
17- assetsPath * paths.Path
14+ baseDir string
15+ composePath string
16+ docsPath string
17+ assetsPath * paths.Path
18+ apiDocsPath string
19+ codeExamplesPath string
1820}
1921
2022func NewStaticStore (baseDir string ) * StaticStore {
2123 return & StaticStore {
22- baseDir : baseDir ,
23- composePath : filepath .Join (baseDir , "compose" ),
24- docsPath : filepath .Join (baseDir , "docs" ),
25- assetsPath : paths .New (baseDir ),
24+ baseDir : baseDir ,
25+ composePath : filepath .Join (baseDir , "compose" ),
26+ docsPath : filepath .Join (baseDir , "docs" ),
27+ apiDocsPath : filepath .Join (baseDir , "api-docs" ),
28+ codeExamplesPath : filepath .Join (baseDir , "examples" ),
29+ assetsPath : paths .New (baseDir ),
2630 }
2731}
2832
@@ -63,3 +67,24 @@ func (s *StaticStore) GetBrickComposeFilePathFromID(brickID string) (*paths.Path
6367 }
6468 return paths .New (s .composePath , namespace , brickName , "brick_compose.yaml" ), nil
6569}
70+
71+ func (s * StaticStore ) GetBrickApiDocPathFromID (brickID string ) (string , error ) {
72+ namespace , brickName , ok := strings .Cut (brickID , ":" )
73+ if ! ok {
74+ return "" , errors .New ("invalid ID" )
75+ }
76+ return filepath .Join (s .apiDocsPath , namespace , "app_bricks" , brickName , "API.md" ), nil
77+ }
78+
79+ func (s * StaticStore ) GetBrickCodeExamplesPathFromID (brickID string ) (paths.PathList , error ) {
80+ namespace , brickName , ok := strings .Cut (brickID , ":" )
81+ if ! ok {
82+ return nil , errors .New ("invalid ID" )
83+ }
84+ targetDir := paths .New (s .codeExamplesPath , namespace , brickName )
85+ dirEntries , err := targetDir .ReadDir ()
86+ if err != nil {
87+ return nil , fmt .Errorf ("cannot read examples directory %q: %w" , targetDir , err )
88+ }
89+ return dirEntries , nil
90+ }
0 commit comments