summaryrefslogtreecommitdiff
path: root/pkg/content
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/content
parent5c631f0cdb8ee3238ff054d171dd8babd158047b (diff)
refactor: split into cmd, pkg
Diffstat (limited to 'pkg/content')
-rw-r--r--pkg/content/content.go66
1 files changed, 66 insertions, 0 deletions
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
+}