Create a structure
This structure stores articles, categories and metadata about the whole generated context
This commit is contained in:
parent
e9e6b8c547
commit
8896fcda09
13
main.go
13
main.go
|
@ -56,21 +56,18 @@ func main() {
|
|||
|
||||
files, _ := walk(*outputDir)
|
||||
|
||||
var articles []models.Article
|
||||
site := models.Site{Name: "Grimboite"}
|
||||
|
||||
for _, file := range files {
|
||||
fmt.Println(file)
|
||||
article := models.Article{
|
||||
File: file,
|
||||
}
|
||||
article.FromFile()
|
||||
fmt.Println(article)
|
||||
|
||||
articles = append(articles, article)
|
||||
|
||||
article.Write()
|
||||
site.Append(&article)
|
||||
}
|
||||
|
||||
site.Build()
|
||||
|
||||
fmt.Println("HTML files were written to: ", *outputDir)
|
||||
fmt.Println("Number of parsed articles: ", len(articles))
|
||||
fmt.Println("Number of parsed articles: ", len(site.Articles))
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package models
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
|
@ -14,6 +15,27 @@ import (
|
|||
"github.com/yuin/goldmark/renderer/html"
|
||||
)
|
||||
|
||||
type Category struct {
|
||||
Children []Category
|
||||
}
|
||||
|
||||
type Site struct {
|
||||
Name string
|
||||
Articles []Article
|
||||
Categories []Category
|
||||
}
|
||||
|
||||
func (s *Site) Append(a *Article) {
|
||||
s.Articles = append(s.Articles, *a)
|
||||
fmt.Println(a)
|
||||
}
|
||||
|
||||
func (s *Site) Build() {
|
||||
for _, article := range s.Articles {
|
||||
article.Convert()
|
||||
}
|
||||
}
|
||||
|
||||
type Article struct {
|
||||
Title string
|
||||
HtmlContent string
|
||||
|
@ -58,7 +80,8 @@ func (a *Article) FromContent(content []byte) {
|
|||
a.Title, _ = metadata["Title"].(string)
|
||||
}
|
||||
|
||||
func (a Article) Write() {
|
||||
func (a Article) Convert() {
|
||||
outputFilePath := strings.Replace(a.File, ".md", ".html", -1)
|
||||
ioutil.WriteFile(outputFilePath, []byte(a.HtmlContent), 0644)
|
||||
os.Remove(a.File)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue