Skip to content

Commit

Permalink
change anchor to folder link
Browse files Browse the repository at this point in the history
Signed-off-by: Avelino <[email protected]>
  • Loading branch information
avelino committed Dec 25, 2021
1 parent 7e0981b commit 76a03b6
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions make_site.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"log"
"os"
"strings"
"text/template"

"github.com/PuerkitoBio/goquery"
Expand Down Expand Up @@ -49,6 +50,7 @@ func main() {

makeSiteStruct(objs)
makeSitemap(objs)
changeLinksInIndex(string(input), query)
}

func makeSiteStruct(objs []Object) {
Expand Down Expand Up @@ -95,3 +97,18 @@ func makeObjById(selector string, s *goquery.Selection) (obj Object) {
})
return
}

func changeLinksInIndex(html string, query *goquery.Document) {
query.Find("body #content ul li ul li a").Each(func(_ int, s *goquery.Selection) {

href, exists := s.Attr("href")
if exists {
uri := strings.SplitAfter(href, "#")
if len(uri) >= 2 {
html = strings.ReplaceAll(html, fmt.Sprintf(`href="%s"`, href), fmt.Sprintf(`href="%s"`, uri[1]))
}
}
})

os.WriteFile("./tmpl/index.html", []byte(html), 0644)
}

0 comments on commit 76a03b6

Please sign in to comment.