Commit 6d46d82f authored by Trevor Slocum's avatar Trevor Slocum

Add --site-footer flag

parent fdf6456c
Pipeline #116137345 passed with stages
in 2 minutes and 23 seconds
0.1.4:
- Add --site-footer flag
- Rewrite links to subpackage import paths
0.1.3:
......
......@@ -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...")
}
......
......@@ -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>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment