Skip to content

Commit

Permalink
fix: deprecated go conventions (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
BachErik authored Jul 7, 2024
2 parents ed3e2b5 + c839706 commit 1ce72e6
Showing 1 changed file with 49 additions and 50 deletions.
99 changes: 49 additions & 50 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,57 +1,56 @@
package main

import (
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"fmt"
"log"
"os"
"path/filepath"
)

func main() {
// Define the directory paths
contentDir := "content"
templatesDir := "templates"
outputDir := "output"

// Read header and footer templates
header, err := ioutil.ReadFile(filepath.Join(templatesDir, "header.html"))
if err != nil {
log.Fatalf("Error reading header: %v", err)
}
footer, err := ioutil.ReadFile(filepath.Join(templatesDir, "footer.html"))
if err != nil {
log.Fatalf("Error reading footer: %v", err)
}

// Create output directory if it doesn't exist
if _, err := os.Stat(outputDir); os.IsNotExist(err) {
os.Mkdir(outputDir, os.ModePerm)
}

// Read the content directory
files, err := ioutil.ReadDir(contentDir)
if err != nil {
log.Fatalf("Error reading content directory: %v", err)
}

for _, file := range files {
if filepath.Ext(file.Name()) == ".html" {
content, err := ioutil.ReadFile(filepath.Join(contentDir, file.Name()))
if err != nil {
log.Printf("Error reading content file %s: %v", file.Name(), err)
continue
}

outputFilePath := filepath.Join(outputDir, file.Name())
err = ioutil.WriteFile(outputFilePath, append(append(header, content...), footer...), 0644)
if err != nil {
log.Printf("Error writing output file %s: %v", outputFilePath, err)
continue
}

fmt.Printf("Generated %s\n", outputFilePath)
}
}
// Define the directory paths
contentDir := "content"
templatesDir := "templates"
outputDir := "output"

// Read header and footer templates
header, err := os.ReadFile(filepath.Join(templatesDir, "header.html"))
if err != nil {
log.Fatalf("Error reading header: %v", err)
}

footer, err := os.ReadFile(filepath.Join(templatesDir, "footer.html"))
if err != nil {
log.Fatalf("Error reading footer: %v", err)
}

// Create output directory if it doesn't exist
if _, err := os.Stat(outputDir); os.IsNotExist(err) {
os.Mkdir(outputDir, os.ModePerm)
}

// Read the content directory
files, err := os.ReadDir(contentDir)
if err != nil {
log.Fatalf("Error reading content directory: %v", err)
}

for _, file := range files {
if filepath.Ext(file.Name()) == ".html" {
content, err := os.ReadFile(filepath.Join(contentDir, file.Name()))
if err != nil {
log.Printf("Error reading content file %s: %v", file.Name(), err)
continue
}

outputFilePath := filepath.Join(outputDir, file.Name())
err = os.WriteFile(outputFilePath, append(append(header, content...), footer...), 0644)
if err != nil {
log.Printf("Error writing output file %s: %v", outputFilePath, err)
continue
}

fmt.Printf("Generated %s\n", outputFilePath)
}
}
}

0 comments on commit 1ce72e6

Please sign in to comment.