Write HTML content to output directory (kind of...)

This commit is contained in:
Fred Pauchet 2022-11-01 21:36:48 +01:00
parent 014a072b25
commit 770195324c
2 changed files with 13 additions and 0 deletions

View File

@ -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))
}

View File

@ -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
}