-
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.
- Loading branch information
Showing
4 changed files
with
102 additions
and
0 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 |
---|---|---|
|
@@ -16,3 +16,8 @@ | |
|
||
# Go workspace file | ||
go.work | ||
|
||
config.toml | ||
|
||
dist/ | ||
content/ |
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,9 @@ | ||
module github.com/jmcharter/lumaca | ||
|
||
go 1.20 | ||
|
||
require ( | ||
github.com/BurntSushi/toml v1.3.2 // indirect | ||
github.com/adrg/frontmatter v0.2.0 // indirect | ||
gopkg.in/yaml.v2 v2.3.0 // indirect | ||
) |
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,9 @@ | ||
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= | ||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= | ||
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= | ||
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= | ||
github.com/adrg/frontmatter v0.2.0 h1:/DgnNe82o03riBd1S+ZDjd43wAmC6W35q67NHeLkPd4= | ||
github.com/adrg/frontmatter v0.2.0/go.mod h1:93rQCj3z3ZlwyxxpQioRKC1wDLto4aXHrbqIsnH9wmE= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= | ||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |
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,79 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/BurntSushi/toml" | ||
"github.com/adrg/frontmatter" | ||
) | ||
|
||
type Config struct { | ||
ContentDirectories struct { | ||
Posts string | ||
Pages string | ||
} | ||
Author struct { | ||
Name string | ||
} | ||
} | ||
|
||
type Matter struct { | ||
Title string `yaml:"title"` | ||
Author string `yaml:"author"` | ||
Tags []string `yaml:"tags"` | ||
Date string | ||
} | ||
|
||
func main() { | ||
fmt.Println("Lumaca starting...") | ||
var config Config | ||
if _, err := toml.DecodeFile("config.toml", &config); err != nil { | ||
log.Fatal(err) | ||
} | ||
err := run(config) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Println("Lumaca finished.") | ||
} | ||
|
||
func run(config Config) error { | ||
|
||
files, err := os.ReadDir(config.ContentDirectories.Posts) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var matters []Matter | ||
for _, file := range files { | ||
if file.IsDir() || !strings.HasSuffix(file.Name(), ".md") { | ||
break | ||
} | ||
filepath := filepath.Join(config.ContentDirectories.Posts, file.Name()) | ||
content, err := os.ReadFile(filepath) | ||
if err != nil { | ||
log.Println("Error reading file:", err) | ||
continue | ||
} | ||
|
||
var matter Matter | ||
_, err = frontmatter.Parse(strings.NewReader(string(content)), &matter) | ||
if err != nil { | ||
log.Println("Error parsing frontmatter from file:", err) | ||
continue | ||
} | ||
matters = append(matters, matter) | ||
|
||
} | ||
|
||
for _, m := range matters { | ||
fmt.Printf("%v\n", m) | ||
} | ||
|
||
return nil | ||
|
||
} |