-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from fogo-sh/content-listing
page listing, discover all pages instead of just 1
- Loading branch information
Showing
5 changed files
with
94 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package content | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
"sort" | ||
) | ||
|
||
func DiscoverPages(path string) (map[string]Page, error) { | ||
paths, error := filepath.Glob(filepath.Join(path, "*.md")) | ||
|
||
if error != nil { | ||
return nil, fmt.Errorf("failed to glob files: %w", error) | ||
} | ||
|
||
pages := make(map[string]Page) | ||
|
||
for _, path := range paths { | ||
page, error := ParsePageFile(path) | ||
if error != nil { | ||
return nil, fmt.Errorf("failed to parse page: %w", error) | ||
} | ||
|
||
pages[page.Title] = page | ||
} | ||
|
||
return pages, nil | ||
} | ||
|
||
func AllPageTitles(pages map[string]Page) []string { | ||
allPageTitles := make([]string, 0, len(pages)) | ||
for key := range pages { | ||
allPageTitles = append(allPageTitles, key) | ||
} | ||
|
||
sort.Slice(allPageTitles, func(i, j int) bool { | ||
return allPageTitles[i] < allPageTitles[j] | ||
}) | ||
|
||
return allPageTitles | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters