vanitydoc

command module
v0.18.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2024 License: BSD-3-Clause Imports: 27 Imported by: 0

README

Vanitydoc Gopher - based on Gopherize.me output - Artwork by Ashley McNamara - inspired by Renee French - Web app by Mat Ryer

vanitydoc Vanitydoc Reference Pipeline Status Go Report Card

Generate Go documentation as a static site (HTML and Gemtext). When served under the import path URL, it makes the package importable by the Go tools ("vanity import path").

For Go reference and a demo, visit https://code.pfad.fr/vanitydoc. To view an example with all the godoc features, visit https://code.pfad.fr/fluhus/godoc-tricks/.

Configuration

Create a JSON file and give its path as argument to the vanitydoc executable. Example configuration file:

{
  "defaults": { // allows to specify defaults for all "modules" below
    // forgejo, gitsrht, hgsrht and github are supported
    "type": "forgejo",

    // the module name will be appended to construct the forge url
    "url_prefix": "https://codeberg.org/pfad.fr/",
    "default_branch": "main"
  },

  "modules": {
    "vanitydoc": {}, // use all defaults for the module hosted at "{url_prefix}/vanitydoc"
    "risefront": {
      "ref": "v1.0.0" // specify the ref to retrieve for this module
    },
    "fluhus/godoc-tricks": {
      "type": "github",
      "url": "https://github.com/fluhus/godoc-tricks",
      "default_branch": "master",
      "ref": "master",

      // github tweak to download the archive of a branch
      // (use "tags/" when "ref" is a tag)
      "archive_ref_prefix": "heads/"
    },
    "exp": {
      "type": "gitsrht",
      "url": "https://git.sr.ht/~oliverpool/exp"
    }
  },

  "html": {
    "output": "dist/http"

    // uncomment to add your templates to customize the HTML
    // "template.pattern": "header.gohtml",

    // uncomment to add a file under "info/refs.redirect" containing the clone url
    // "first_clone_url_info_refs_path": "info/refs.redirect"
  },
  "gemtext": {
    // uncomment the following line to generate documentation as gemtext
    // "output": "dist/gmi"
  },

  "max_conns_per_host": 3 // be nice with the forge when downloading module archives
}

Overview of the sections of the JSON (reference below):

{
	"defaults": {...}, // allows to specify defaults for all "modules" below
	"modules": {...}, // modules map: "module_name": {...}

	"html": {...}, // HTML output settings
	"gemtext": {...}, // Gemtext output settings

	"max_conns_per_host": 3 // be nice with the forge when downloading module archives
}
defaults object

Allows to specify some defaults for the modules:

  • type: type of forge. One of forgejo, gitsrht, hgsrht or github. See https://code.pfad.fr/vanitydoc/autodiscovery/#New for an up-to-date list.
  • url_prefix: URL prefix. When generating the modules, the name of the module will be appended to this prefix to construct the full URL.
  • default_branch: default branch (used as VCS hint)
  • ref: default reference to generate the documentation for (e.g. main, v1.0.0)
  • archive_ref_prefix: prefix to download the given ref (required for github: "tags/" when ref is a tag, "heads/" for branches)
modules objects

The keys of this object are the module names, the value is an object describing the module:

  • type: type of forge. One of forgejo, gitsrht, hgsrht or github. See https://code.pfad.fr/vanitydoc/autodiscovery/#New for an up-to-date list.

  • url: URL of the VCS (if set, the defaults.url_prefix is ignored).

  • default_branch: default branch (used as VCS hint)

  • ref: default reference to generate the documentation for (e.g. main, v1.0.0)

  • archive_ref_prefix: prefix to download the given ref (required for github: "tags/" when ref is a tag, "heads/" for branches)

  • archive_url: url to download the archive (zip or tar.gz) containing the module

  • archive_targz: set to true if the archive is a tar.gz file

html object
  • output specifies the root of output folder for the .html files. If empty, no HTML will be generated. Each module documentation will be generated under {output}/{module_name} ({module_name} being the keys in the modules object above).

  • stylesheet_links when set, will be used as stylesheet links for all pages. When not set, a default CSS file will be generated and used (see the note below to generate this file).

    The default CSS file can be written to an arbitrary folder by running echo '{ "html": { "output": "dist" } }' | vanitydoc - (replace dist with the desired output folder).

  • template.root when set, indicates the root folder for template customization.

  • template.pattern when set, indicates a pattern to look for template customization. See the layout template to check the block names to customize. Example of custom header for code.pfad.fr.

  • first_clone_url_info_refs_path when set, a file with this name will be created for each module. The file will contain the first clone URL of the module. For vanitydoc, this file is used to set-up a redirection to the actual forge, allowing to run git clone https://code.pfad.fr/vanitydoc, see my blog post for details.

gemtext object - Project Gemini
  • output specifies the root of output folder for the .gmi files. If empty, no Gemtext will be generated. Each module documentation will be generated under {output}/{module_name} ({module_name} being the keys in the modules object above).
max_conns_per_host integer

Set the (http.Transport).MaxConnsPerHost used for downloading the modules as zip archives from the forge.

MaxConnsPerHost optionally limits the total number of connections per host, including connections in the dialing, active, and idle states. On limit violation, dials will block.

Zero means no limit.

Documentation

Overview

vanitydoc generates go documentation as a static site (HTML and Gemtext). When served under the import path URL, it makes the package importable by the Go tools ("vanity import path").

For instance the import path for this command is code.pfad.fr/vanitydoc and the documentation is hosted at the following URL: https://code.pfad.fr/vanitydoc

Usage:

vanitydoc [flags] <path>
# or using go run:     go run code.pfad.fr/vanitydoc@latest [flags] <path>
# or using nix flakes: nix run git+https://code.pfad.fr/vanitydoc [flags] <path>

If the <path> argument points to a folder (or is omitted), a local HTTP server will be started to render the documentation on demand of the given folder (or the current folder), taking into account the following flags:

-addr string
	listen address to expose the documentation (default "localhost:8080")
-gomodcache string
	path to the GOMODCACHE folder, for pkg.go.dev-like experience when giving the stdlib path as <path> argument
-html.template.pattern string
	pattern for additional HTML templates
-html.template.root string
	root folder of the additional HTML templates (default ".")
-modulePath string
	module path (will be read from <path>/go.mod if empty)

If the <path> argument points to a file (or "-" for stdin), the file is read as JSON, the configured modules are downloaded and their documentation generated.

Example to generate this documentation

The path to the JSON file containing the configuration should be given as argument to the executable. See the README for configuration reference.

{
	"defaults": { // allows to specify defaults for all "modules" below
		// forgejo, gitsrht, hgsrht and github are supported
		"type": "forgejo",

		// the module name will be appended to construct the forge url
		"url_prefix": "https://codeberg.org/pfad.fr/",
		"default_branch": "main"
	},

	"modules": {
		"vanitydoc": {}, // use all defaults for the module hosted at "{url_prefix}/vanitydoc"
		"risefront": {
			"ref": "v1.0.0" // specify the ref to retrieve for this module
		},
		"fluhus/godoc-tricks": {
			"type": "github",
			"url": "https://github.com/fluhus/godoc-tricks",
			"default_branch": "master",
			"ref": "master",

			// github tweak to download the archive of a branch
			// (use "tags/" when "ref" is a tag)
			"archive_ref_prefix": "heads/"
		},
		"exp": {
			"type": "gitsrht",
			"url": "https://git.sr.ht/~oliverpool/exp"
		}
	},

	"html": {
		"output": "dist/http",

		// you can add your templates to customize the HTML
		"template.pattern": "header.gohtml",
		"first_clone_url_info_refs_path": "info/refs.redirect"
	},
	"gemtext": {
		"output": "dist/gmi"
	},

	"max_conns_per_host": 3 // be nice with the forge when downloading module archives
}

License and credits

Code is available under the BSD-3-Clause license.

Most of the templates originate from gddo (available under BSD-3-Clause). The default CSS styling is inspired by simple.css (available under MIT). go-import meta tag as well as the meta tags proposed by the VCS Autodiscovery RFC are included in the HTML output.

Directories

Path Synopsis
package autodiscovery is an implementation of the [VCS Autodiscovery RFC].
package autodiscovery is an implementation of the [VCS Autodiscovery RFC].
package template generates documentation for a given package.
package template generates documentation for a given package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL