@@ -17,6 +17,7 @@ import (
17
17
"path/filepath"
18
18
"regexp"
19
19
"strings"
20
+ "text/template"
20
21
)
21
22
22
23
var writeFlag = flag .Bool ("w" , false , "Overwrite new file contents to disk." )
@@ -28,13 +29,15 @@ func main() {
28
29
errorf ("Usage: %v <dir>" , os .Args [0 ])
29
30
os .Exit (1 )
30
31
}
31
- if err := rewriteLinks (flag .Arg (0 ), * writeFlag ); err != nil {
32
+
33
+ genFooter := footerGenerator ("https://github.com/golang/vscode-go/edit/master/docs/" )
34
+ if err := rewriteLinks (flag .Arg (0 ), genFooter , * writeFlag ); err != nil {
32
35
errorf ("failed to rewrite links: %v" , err )
33
36
os .Exit (1 )
34
37
}
35
38
}
36
39
37
- func rewriteLinks (dir string , overwrite bool ) error {
40
+ func rewriteLinks (dir string , genFooter func ( srcPath string ) [] byte , overwrite bool ) error {
38
41
return filepath .WalkDir (dir , func (path string , d fs.DirEntry , err error ) error {
39
42
if err != nil {
40
43
return err
@@ -55,6 +58,10 @@ func rewriteLinks(dir string, overwrite bool) error {
55
58
}
56
59
converted := stripTitleInPage (data )
57
60
converted = markdownLink2WikiLink (converted )
61
+ if name != "_Footer.md" && name != "_Sidebar.md" {
62
+ relPath , _ := filepath .Rel (dir , path )
63
+ converted = append (converted , genFooter (filepath .ToSlash (relPath ))... )
64
+ }
58
65
if overwrite {
59
66
return ioutil .WriteFile (path , converted , 0644 )
60
67
}
@@ -128,3 +135,19 @@ func markdownLink2WikiLink(src []byte) []byte {
128
135
func errorf (format string , a ... interface {}) {
129
136
fmt .Fprintf (os .Stderr , format + "\n " , a ... )
130
137
}
138
+
139
+ func footerGenerator (sourceEditURL string ) func (string ) []byte {
140
+ return func (srcPath string ) []byte {
141
+ editURL := sourceEditURL + srcPath
142
+ buf := new (bytes.Buffer )
143
+ footerTmpl .Execute (buf , editURL )
144
+ return buf .Bytes ()
145
+ }
146
+ }
147
+
148
+ var footerTmpl = template .Must (template .New ("footer" ).Parse (`
149
+
150
+ ---
151
+ [*✏️ Want to contribute to this wiki?*]({{.}})
152
+
153
+ Update [the source]({{.}}) and send a PR.` ))
0 commit comments