summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorHimanshu Sardana <himanshusardana2005@gmail.com>2026-03-26 21:26:35 +0000
committerHimanshu Sardana <himanshusardana2005@gmail.com>2026-03-26 21:26:35 +0000
commit103e84d847262830bbaa550b37218e9ca8b317d3 (patch)
treee19d3bfd6594600fb28be1ccac1a3869207bc49c /pkg
parent5c631f0cdb8ee3238ff054d171dd8babd158047b (diff)
refactor: split into cmd, pkg
Diffstat (limited to 'pkg')
-rw-r--r--pkg/config/config.go29
-rw-r--r--pkg/content/content.go66
-rw-r--r--pkg/themes/themes.go40
3 files changed, 135 insertions, 0 deletions
diff --git a/pkg/config/config.go b/pkg/config/config.go
new file mode 100644
index 0000000..56f40aa
--- /dev/null
+++ b/pkg/config/config.go
@@ -0,0 +1,29 @@
+package config
+
+import (
+ "os"
+
+ "gopkg.in/yaml.v2"
+)
+
+type Config struct {
+ SiteTitle string `yaml:"siteTitle"`
+ AuthorName string `yaml:"authorName"`
+ AuthorRole string `yaml:"authorRole"`
+ AuthorBio string `yaml:"authorBio"`
+ DefaultTheme string `yaml:"defaultTheme"`
+}
+
+func Load(path string) (*Config, error) {
+ data, err := os.ReadFile(path)
+ if err != nil {
+ return nil, err
+ }
+
+ var cfg Config
+ if err := yaml.Unmarshal(data, &cfg); err != nil {
+ return nil, err
+ }
+
+ return &cfg, nil
+}
diff --git a/pkg/content/content.go b/pkg/content/content.go
new file mode 100644
index 0000000..934b2ee
--- /dev/null
+++ b/pkg/content/content.go
@@ -0,0 +1,66 @@
+package content
+
+import (
+ "io/fs"
+ "path/filepath"
+ "strings"
+)
+
+type Frontmatter struct {
+ Title string `yaml:"title"`
+ Date string `yaml:"date"`
+ Tags []string `yaml:"tags"`
+}
+
+type PostSummary struct {
+ Title string
+ Slug string
+ Date string
+ Tags []string
+}
+
+type ContentFile struct {
+ Path string
+ Slug string
+ Frontmatter Frontmatter
+}
+
+func ListContentFiles(contentDir string) ([]ContentFile, error) {
+ var files []ContentFile
+
+ err := filepath.WalkDir(contentDir, func(path string, d fs.DirEntry, err error) error {
+ if err != nil {
+ return err
+ }
+
+ if d.IsDir() {
+ return nil
+ }
+
+ if strings.HasSuffix(d.Name(), ".md") {
+ slug := strings.TrimSuffix(d.Name(), ".md")
+ files = append(files, ContentFile{
+ Path: path,
+ Slug: slug,
+ })
+ }
+
+ return nil
+ })
+
+ if err != nil {
+ return nil, err
+ }
+
+ return files, nil
+}
+
+func GetOutputPath(contentDir, contentPath, outputDir string) (string, error) {
+ relPath, err := filepath.Rel(contentDir, contentPath)
+ if err != nil {
+ return "", err
+ }
+
+ outputFilePath := filepath.Join(outputDir, strings.Replace(relPath, ".md", "/index.html", 1))
+ return outputFilePath, nil
+}
diff --git a/pkg/themes/themes.go b/pkg/themes/themes.go
new file mode 100644
index 0000000..a8af863
--- /dev/null
+++ b/pkg/themes/themes.go
@@ -0,0 +1,40 @@
+package themes
+
+import (
+ "os"
+ "path/filepath"
+)
+
+type Theme struct {
+ Name string
+ Path string
+}
+
+func List(themesDir string) ([]Theme, error) {
+ entries, err := os.ReadDir(themesDir)
+ if err != nil {
+ return nil, err
+ }
+
+ var themes []Theme
+ for _, entry := range entries {
+ if entry.IsDir() {
+ themes = append(themes, Theme{
+ Name: entry.Name(),
+ Path: filepath.Join(themesDir, entry.Name()),
+ })
+ }
+ }
+
+ return themes, nil
+}
+
+func GetThemePath(themesDir, themeName string) string {
+ return filepath.Join(themesDir, themeName)
+}
+
+func ThemeExists(themesDir, themeName string) bool {
+ path := GetThemePath(themesDir, themeName)
+ info, err := os.Stat(path)
+ return err == nil && info.IsDir()
+}