-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
49 additions
and
50 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
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) | ||
} | ||
} | ||
} |