Write HTML content to output directory (kind of...)
This commit is contained in:
parent
014a072b25
commit
770195324c
4
main.go
4
main.go
|
@ -61,6 +61,10 @@ func main() {
|
|||
articles = append(articles, article)
|
||||
}
|
||||
|
||||
for _, article := range articles {
|
||||
article.WriteTo(outputDir)
|
||||
}
|
||||
|
||||
fmt.Println("HTML files were written to: ", *outputDir)
|
||||
fmt.Println("Number of parsed articles: ", len(articles))
|
||||
}
|
||||
|
|
|
@ -3,8 +3,10 @@ package models
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/yuin/goldmark"
|
||||
meta "github.com/yuin/goldmark-meta"
|
||||
|
@ -63,5 +65,12 @@ func (a Article) FromContent(content []byte) Article {
|
|||
}
|
||||
|
||||
func (a Article) WriteTo(outputPath *string) {
|
||||
outputFilePath := filepath.Join(*outputPath, a.RelativeFilePath, "index.html")
|
||||
|
||||
// creates the full directories tree
|
||||
if err := os.MkdirAll("a/b/c/d", os.ModePerm); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
ioutil.WriteFile(outputFilePath, []byte(a.HtmlContent), 0644) // the 0644 is octal representation of the filemode
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue