-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
repo: generalize blog by introducing a blog config
- Loading branch information
1 parent
26e0f00
commit abd2f88
Showing
4 changed files
with
68 additions
and
14 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package config | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
const ( | ||
CONFIG_FILE = "blog.json" | ||
) | ||
|
||
type Config struct { | ||
Version int `json:"version"` | ||
Domain string `json:"domain"` | ||
Author string `json:"author"` | ||
Title string `json:"title"` | ||
Description string `json:"description"` | ||
Footer string `json:"footer"` | ||
} | ||
|
||
func ConfigPath(postPath string) string { | ||
return filepath.Join(postPath, CONFIG_FILE) | ||
} | ||
|
||
func Load(postPath string) (*Config, error) { | ||
raw, err := os.ReadFile(ConfigPath(postPath)) | ||
if err != nil { | ||
return nil, fmt.Errorf("Error reading config: %s", err) | ||
} | ||
|
||
config := new(Config) | ||
if err := json.Unmarshal(raw, &config); err != nil { | ||
return nil, fmt.Errorf("Error parsing config: %s", err) | ||
} | ||
|
||
return config, nil | ||
} |