mirror of
https://github.com/go-i2p/go-gh-page.git
synced 2025-06-07 01:57:38 -04:00
fix links on docs pages
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
@ -13,6 +14,8 @@ import (
|
||||
"github.com/go-i2p/go-gh-page/pkg/generator"
|
||||
"github.com/go-i2p/go-gh-page/pkg/git"
|
||||
"github.com/go-i2p/go-gh-page/pkg/templates"
|
||||
github "github.com/google/go-github/v45/github"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -26,6 +29,7 @@ func main() {
|
||||
docTemplateOverride := flag.String("doc-template", "", "Path to custom documentation template")
|
||||
styleTemplateOverride := flag.String("style-template", "", "Path to custom style template")
|
||||
setupYaml := flag.Bool("page-yaml", false, "Generate .github/workflows/page.yaml file")
|
||||
setupPage := flag.Bool("setup-page", false, "Setup GitHub Pages to build from gh-pages branch")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
@ -41,6 +45,12 @@ func main() {
|
||||
if err := exec.Command("git", "add", ".github/workflows/page.yml").Run(); err != nil {
|
||||
log.Fatalf("Failed to add page.yml to git: %v", err)
|
||||
}
|
||||
if err := exec.Command("git", "commit", "-m", "Add GitHub Actions workflow for page generation").Run(); err != nil {
|
||||
log.Fatalf("Failed to commit page.yml: %v", err)
|
||||
}
|
||||
if err := exec.Command("git", "push").Run(); err != nil {
|
||||
log.Fatalf("Failed to push page.yml: %v", err)
|
||||
}
|
||||
fmt.Println("Added .github/workflows/page.yml to git staging area.")
|
||||
fmt.Println("You can now commit and push this file to your repository.")
|
||||
os.Exit(0)
|
||||
@ -59,6 +69,13 @@ func main() {
|
||||
flag.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
if *setupPage {
|
||||
if err := enableGithubPage(repoParts[0], repoParts[1]); err != nil {
|
||||
log.Fatalf("Failed to enable GitHub Pages: %v", err)
|
||||
}
|
||||
fmt.Printf("Enabled GitHub Pages for %s/%s\n", strings.Split(*repoFlag, "/")[0], strings.Split(*repoFlag, "/")[1])
|
||||
os.Exit(0)
|
||||
}
|
||||
// if mainTemplateOverride is not empty, check if a file exists
|
||||
if *mainTemplateOverride != "" {
|
||||
if _, err := os.Stat(*mainTemplateOverride); os.IsNotExist(err) {
|
||||
@ -177,3 +194,30 @@ func main() {
|
||||
|
||||
fmt.Printf("\nTotal time: %.2f seconds\n", time.Since(startTime).Seconds())
|
||||
}
|
||||
|
||||
func enableGithubPage(userName, repoName string) error {
|
||||
branch := "gh-pages"
|
||||
token := os.Getenv("GITHUB_TOKEN")
|
||||
if len(token) == 0 {
|
||||
return fmt.Errorf("GITHUB_TOKEN not set")
|
||||
}
|
||||
ctx := context.Background()
|
||||
ts := oauth2.StaticTokenSource(
|
||||
&oauth2.Token{AccessToken: token},
|
||||
)
|
||||
tc := oauth2.NewClient(ctx, ts)
|
||||
client := github.NewClient(tc)
|
||||
path := "/"
|
||||
_, _, err := client.Repositories.EnablePages(ctx, userName, repoName, &github.Pages{
|
||||
Source: &github.PagesSource{
|
||||
Branch: github.String(branch),
|
||||
Path: github.String(path),
|
||||
},
|
||||
Public: github.Bool(true),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not enable github pages: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
3
go.mod
3
go.mod
@ -5,6 +5,8 @@ go 1.24.2
|
||||
require (
|
||||
github.com/go-git/go-git/v5 v5.16.0
|
||||
github.com/gomarkdown/markdown v0.0.0-20250311123330-531bef5e742b
|
||||
github.com/google/go-github/v45 v45.2.0
|
||||
golang.org/x/oauth2 v0.30.0
|
||||
)
|
||||
|
||||
require (
|
||||
@ -17,6 +19,7 @@ require (
|
||||
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
|
||||
github.com/go-git/go-billy/v5 v5.6.2 // indirect
|
||||
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
|
||||
github.com/google/go-querystring v1.1.0 // indirect
|
||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
|
||||
github.com/kevinburke/ssh_config v1.2.0 // indirect
|
||||
github.com/pjbgf/sha1cd v0.3.2 // indirect
|
||||
|
8
go.sum
8
go.sum
@ -34,8 +34,13 @@ github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 h1:f+oWsMOmNPc8J
|
||||
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8/go.mod h1:wcDNUvekVysuuOpQKo3191zZyTpiI6se1N1ULghS0sw=
|
||||
github.com/gomarkdown/markdown v0.0.0-20250311123330-531bef5e742b h1:EY/KpStFl60qA17CptGXhwfZ+k1sFNJIUNR8DdbcuUk=
|
||||
github.com/gomarkdown/markdown v0.0.0-20250311123330-531bef5e742b/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA=
|
||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/go-github/v45 v45.2.0 h1:5oRLszbrkvxDDqBCNj2hjDZMKmvexaZ1xw/FCD+K3FI=
|
||||
github.com/google/go-github/v45 v45.2.0/go.mod h1:FObaZJEDSTa/WGCzZ2Z3eoCDXWJKMenWWTrd8jrta28=
|
||||
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
|
||||
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
|
||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
|
||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
|
||||
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
|
||||
@ -77,6 +82,8 @@ golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbR
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.39.0 h1:ZCu7HMWDxpXpaiKdhzIfaltL9Lp31x/3fCP11bc6/fY=
|
||||
golang.org/x/net v0.39.0/go.mod h1:X7NRbYVEA+ewNkCNyJ513WmMdQ3BineSwVtN2zD/d+E=
|
||||
golang.org/x/oauth2 v0.30.0 h1:dnDm7JmhM45NNpd8FDDeLhK6FwqbOf4MLCM9zb1BOHI=
|
||||
golang.org/x/oauth2 v0.30.0/go.mod h1:B++QgG3ZKulg6sRPGD/mqlHQs5rB3Ml9erfeDY7xKlU=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
@ -92,6 +99,7 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0=
|
||||
golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
|
@ -243,7 +243,7 @@
|
||||
{{if .DocsPages}}
|
||||
<div class="nav-section-title">Documentation:</div>
|
||||
{{range .DocsPages}}
|
||||
<li><a href="{{.Path}}" {{if .IsActive}}class="active"{{end}}>{{.Title}}</a></li>
|
||||
<li><a href="../{{.Path}}" {{if .IsActive}}class="active"{{end}}>{{.Title}}</a></li>
|
||||
{{end}}
|
||||
{{end}}
|
||||
</ul>
|
||||
|
Reference in New Issue
Block a user