-
Notifications
You must be signed in to change notification settings - Fork 0
/
sitemap.go
55 lines (50 loc) · 1.48 KB
/
sitemap.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
)
func main() {
// Get the current directory
dir, err := os.Getwd()
if err != nil {
fmt.Println("Error getting current directory:", err)
return
}
// Get the GitHub repository name from the current directory
repoName := strings.ToLower(filepath.Base(dir))
// Walk through the current directory
err = filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
return nil
}
// Check for files with .xml extension
if filepath.Ext(path) == ".xml" {
// Read file contents
content, err := ioutil.ReadFile(path)
if err != nil {
return err
}
// Replace "loc>/" with "loc>https://[githubrepositorynameinlowercase]/"
updatedContent := bytes.Replace(content, []byte("loc>/"), []byte(fmt.Sprintf("loc>https://%s/", repoName)), -1)
// Write updated content back to the file
err = ioutil.WriteFile(path, updatedContent, 0644)
if err != nil {
return err
}
fmt.Println("Updated", path)
}
return nil
})
if err != nil {
fmt.Println("Error walking through directory:", err)
return
}
fmt.Println("Replacement completed successfully.")
}