To feed the output of doc2go into Hugo, you need at least the following:
_index.html
contentDir
—defaults to ‘content/’So if your Hugo website is a subdirectory inside your project with a layout similar to the following:
Project root
|- go.mod
|- foo.go
'- docs/
|- config.toml
'- content/
|- _index.md
'- other-pages.md
Run this command from your project root:
doc2go -embed \
-basename _index.html \
-out docs/content/api \
./...
This will generate an api/
subfolder in your Hugo website
that holds your project’s API reference.
Depending on the theme you’re using you will probably need to provide a front matter template to make the generated pages compatible with the template.
doc2go -embed \
-basename _index.html \
-out docs/content/api \
-frontmatter frontmatter.tmpl \
./...
For example, the theme may require an explicit title, to set the page type, or other customization.
See Adding front matter to write your own templates, or see below for some you can use.
Mix and match the following into your front matter template.
Be sure to add the ---
delimiters at the start and end of the template.
---
# ...
---
title: "{{ with .Name }}{{ . }}{{ else }}Reference{{ end }}"
This gives us a title based on the package or binary name, or the base name of the directory if it’s not a Go package.
no_list: true
type: docs
no_list
because doc2go generates its own subpackage listing.bookToC: false
bookCollapseSection: {{ if .NumChildren }}true{{ else }}false{{ end }}