Add --site-footer flag
This commit is contained in:
parent
fdf6456c43
commit
6d46d82f22
|
@ -1,4 +1,5 @@
|
|||
0.1.4:
|
||||
- Add --site-footer flag
|
||||
- Rewrite links to subpackage import paths
|
||||
|
||||
0.1.3:
|
||||
|
|
36
main.go
36
main.go
|
@ -30,6 +30,8 @@ var (
|
|||
siteName string
|
||||
siteDescription string
|
||||
siteDescriptionFile string
|
||||
siteFooter string
|
||||
siteFooterFile string
|
||||
linkIndex bool
|
||||
outDir string
|
||||
excludePackages string
|
||||
|
@ -47,6 +49,8 @@ func main() {
|
|||
flag.StringVar(&siteName, "site-name", "Documentation", "site name")
|
||||
flag.StringVar(&siteDescription, "site-description", "", "site description (markdown-enabled)")
|
||||
flag.StringVar(&siteDescriptionFile, "site-description-file", "", "path to markdown file containing site description")
|
||||
flag.StringVar(&siteFooter, "site-footer", "", "site footer (markdown-enabled)")
|
||||
flag.StringVar(&siteFooterFile, "site-footer-file", "", "path to markdown file containing site footer")
|
||||
flag.BoolVar(&linkIndex, "link-index", false, "set link targets to index.html instead of folder")
|
||||
flag.StringVar(&outDir, "out", "", "site directory")
|
||||
flag.StringVar(&excludePackages, "exclude", "", "list of packages to exclude from index")
|
||||
|
@ -96,6 +100,38 @@ func run() error {
|
|||
siteDescription = buf.String()
|
||||
}
|
||||
|
||||
if siteFooterFile != "" {
|
||||
siteFooterBytes, err := ioutil.ReadFile(siteFooterFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read site footer file %s: %s", siteFooterFile, err)
|
||||
}
|
||||
siteFooter = string(siteFooterBytes)
|
||||
}
|
||||
|
||||
if siteFooter != "" {
|
||||
markdown := goldmark.New(
|
||||
goldmark.WithRendererOptions(
|
||||
gmhtml.WithUnsafe(),
|
||||
),
|
||||
goldmark.WithExtensions(
|
||||
extension.NewLinkify(),
|
||||
),
|
||||
)
|
||||
|
||||
buf.Reset()
|
||||
err := markdown.Convert([]byte(siteFooter), &buf)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to render site footer markdown: %s", err)
|
||||
}
|
||||
siteFooter = buf.String()
|
||||
}
|
||||
|
||||
if siteFooter != "" {
|
||||
siteFooter += "<p>" + footerText + "</p>"
|
||||
} else {
|
||||
siteFooter = footerText
|
||||
}
|
||||
|
||||
if verbose {
|
||||
log.Println("Starting godoc...")
|
||||
}
|
||||
|
|
6
page.go
6
page.go
|
@ -18,8 +18,11 @@ import (
|
|||
const additionalCSS = `
|
||||
details { margin-top: 20px; }
|
||||
summary { margin-left: 20px; cursor: pointer; }
|
||||
#footer > p, #footer > li { max-width: none; word-wrap: normal; }
|
||||
`
|
||||
|
||||
const footerText = `Documentation generated with <a href="https://godoc.org/golang.org/x/tools/godoc" target="_blank">godoc</a> + <a href="https://gitlab.com/tslocum/godoc-static" target="_blank">godoc-static</a>`
|
||||
|
||||
func topBar(basePath string, siteName string) string {
|
||||
var index string
|
||||
if linkIndex {
|
||||
|
@ -154,7 +157,7 @@ func updatePage(doc *goquery.Document, basePath string, siteName string) {
|
|||
}
|
||||
})
|
||||
|
||||
doc.Find("#footer").Last().Remove()
|
||||
doc.Find("#footer").Last().SetHtml(siteFooter)
|
||||
}
|
||||
|
||||
func writeIndex(buf *bytes.Buffer, outDir string, basePath string, siteName string, pkgs []string, filterPkgs []string) error {
|
||||
|
@ -261,6 +264,7 @@ PACKAGEINDEX:
|
|||
buf.WriteString(`
|
||||
</table>
|
||||
</div>
|
||||
<div id="footer">` + siteFooter + `</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
|
Loading…
Reference in New Issue