-
Notifications
You must be signed in to change notification settings - Fork 2
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
DedLad
committed
Mar 31, 2024
1 parent
f195ffe
commit 0a13722
Showing
1 changed file
with
48 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package anna | ||
|
||
import ( | ||
"encoding/json" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
type FileIndex struct { | ||
Files []string `json:"files"` | ||
} | ||
|
||
func CreateIndex() { | ||
rootDir := "site/rendered" // Replace with the root directory of your site | ||
|
||
// Recursively walk through the root directory and collect all HTML files | ||
var files []string | ||
err := filepath.Walk(rootDir, func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
if !info.IsDir() && filepath.Ext(path) == ".html" { | ||
files = append(files, path) | ||
} | ||
return nil | ||
}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Create a file index | ||
index := FileIndex{ | ||
Files: files, | ||
} | ||
|
||
// Convert the index to JSON | ||
jsonData, err := json.Marshal(index) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Write the JSON data to a file | ||
err = ioutil.WriteFile("site\\static\\scripts\\index.json", jsonData, 0644) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |