summaryrefslogtreecommitdiffstats
path: root/internal/cms/status.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/cms/status.go')
-rw-r--r--internal/cms/status.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/internal/cms/status.go b/internal/cms/status.go
new file mode 100644
index 0000000..8147ee7
--- /dev/null
+++ b/internal/cms/status.go
@@ -0,0 +1,50 @@
+package cms
+
+import (
+ "os"
+ "path/filepath"
+)
+
+func Status(root string) (StatusReport, error) {
+ project, err := LoadProject(root)
+ if err != nil {
+ return StatusReport{}, err
+ }
+ check, err := Check(root)
+ if err != nil {
+ return StatusReport{}, err
+ }
+ report := StatusReport{
+ Root: root,
+ Config: project.Config,
+ Menus: len(project.Menus),
+ Sections: len(project.Sections),
+ Widgets: len(project.Widgets),
+ PublicFiles: countPublicFiles(filepath.Join(root, "public")),
+ Issues: check.Issues,
+ }
+ for _, doc := range project.Docs {
+ switch doc.Type {
+ case "page":
+ report.Pages++
+ case "article":
+ report.Articles++
+ }
+ if doc.Draft {
+ report.Drafts++
+ }
+ }
+ return report, nil
+}
+
+func countPublicFiles(root string) int {
+ count := 0
+ filepath.WalkDir(root, func(_ string, entry os.DirEntry, err error) error {
+ if err != nil || entry.IsDir() {
+ return nil
+ }
+ count++
+ return nil
+ })
+ return count
+}