Skip to content

Commit

Permalink
implemented indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
DedLad committed Mar 31, 2024
1 parent f195ffe commit 0a13722
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions cmd/anna/indexer.go
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)
}
}

0 comments on commit 0a13722

Please sign in to comment.