Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/cmd/godoc: generate static docs #2381

Open
moraes opened this issue Oct 18, 2011 · 35 comments
Open

x/tools/cmd/godoc: generate static docs #2381

moraes opened this issue Oct 18, 2011 · 35 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@moraes
Copy link
Contributor

moraes commented Oct 18, 2011

It is fairly trivial to compile a given Go version and run the doc server locally to
search for an older API.

But it would be nice if golang.org provided access to docs per release. One simple
solution to this is to add an option to godoc to generate static docs on disk -- just a
tree of static files (search would be disabled of course). Then docs for old versions
could be made available somewhere in golang.org.

One additional benefit is that projects that want to ship docs could generate the static
files and provide the html files for download, or create pdfs, chms etc based on them.

PS: I tried searching for a similar issue; sorry if this is a duplicate.
@bradfitz
Copy link
Contributor

Comment 1:

This is being worked on, kinda.
Now that godoc can run on App Engine, we'll be doing something like running different
subdomains of golang.org for old releases.
Andrew knows the details.

Owner changed to @adg.

Status changed to Accepted.

@adg
Copy link
Contributor

adg commented Oct 26, 2011

Comment 2:

To generate static docs, just run this command:
godoc -http=localhost:8080 &
wget -r -np http://localhost:8080/pkg/
We're working on providing online docs for older versions of Go.

@moraes
Copy link
Contributor Author

moraes commented Oct 31, 2011

Comment 3:

I haven't thought about using wget. Nice. For those interested in this trick, here are
some notes.
First, edit robots.txt in the go root directory, and remove "Disallow: /". Otherwise
only the index will be downloaded because wget respects robots.txt.
Then start godoc pointing to the project path:
godoc -path="/path/to/project" -http=:8080
And finally this a more complete command to get a working static docs, including static
files and with proper links:
wget -r -np -N -E -p -k http://localhost:8080/pkg/
-r  : download recursive
-np : don't ascend to the parent directory
-N  : don't retrieve files unless newer than local
-E  : add extension .html to html files (if they don't have)
-p  : download all necessary files for each page (css, js, images)
-k  : convert links to relative

@rsc
Copy link
Contributor

rsc commented Dec 9, 2011

Comment 4:

Labels changed: added priority-later.

@adg
Copy link
Contributor

adg commented Dec 19, 2011

Comment 5:

Owner changed to ---.

Status changed to HelpWanted.

@adg
Copy link
Contributor

adg commented Mar 18, 2013

Comment 7:

Labels changed: added godoc.

@gopherbot
Copy link

Comment 8 by pedromorgan:

Yes please

@josharian
Copy link
Contributor

Comment 9:

You can ask wget to ignore robots.txt by adding the flag `-e robots=off`.

@rsc
Copy link
Contributor

rsc commented Nov 27, 2013

Comment 10:

Labels changed: added go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 11:

Labels changed: added release-none, removed go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 12:

Labels changed: added repo-tools.

@rsc rsc added this to the Unplanned milestone Apr 10, 2015
@rsc rsc changed the title cmd/godoc: generate static docs x/tools/cmd/godoc: generate static docs Apr 14, 2015
@rsc rsc removed the repo-tools label Apr 14, 2015
@kegsay
Copy link

kegsay commented Nov 2, 2016

I would also like godoc to be able to generate static docs. The proposed workaround (hosting all the files and wgeting it) works but it crawls the entire contents of your GOPATH, which is less than ideal because that then bloats the static docs incredibly.

I still want things like the builtins to link correctly to docs, so some incantation of go list to pull out the dependencies of the project would be ideal. Unfortunately, I can't just write a bash script to do this because using godoc -html path/to/package just returns the raw HTML without any CSS, and no JS to handle section expansion.

EDIT: Managed to do this in the end with a fairly noddy script.

@gopherbot
Copy link

Change https://golang.org/cl/72890 mentions this issue: godoc/internal/render: add render package for text formatting

@dsnet
Copy link
Member

dsnet commented Oct 24, 2017

As part of my work on #18342, I wrote simple static generator for godoc, that I realized is really well suited for resolving this issue. Is there any interest in including it's generated output in each release?

You can see statically generated docs at: https://static-hotlinks.digitalstatic.net/

@dsnet dsnet self-assigned this Oct 31, 2017
@dsnet dsnet removed the help wanted label Oct 31, 2017
@ghost
Copy link

ghost commented Nov 6, 2017

As part of my work on #18342, I wrote simple static generator for godoc, that I realized is really well suited for resolving this issue. Is there any interest in including it's generated output in each release?

@dsnet Is this static generator available somewhere? I'd like to give it a try for hosting docs for a few packages.

@ghost
Copy link

ghost commented Feb 19, 2018

For the record, I went with Cheney's godoc2md tool: https://github.com/davecheney/godoc2md and it works perfectly. I feed the resulting markdown files into a static site generator like Hugo.

@Linuturk
Copy link

I'd like to second supporting a static output of go doc without having to use other external tools like wget. I feel like https://github.com/davecheney/godoc2md solves this fairly well, but that tool is no longer being supported. I'd recommend adding markdown output to the go doc command.

The use case is fairly simple. When working on private packages or modules that can't be made public, it's nice to just bundle the docs in the repo as a README.md.

@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 26, 2019
@dmitshur dmitshur self-assigned this Aug 31, 2019
@marcellanz
Copy link

marcellanz commented Sep 10, 2019

As user, I'd like to express how "lost" I feel to generate a directory containing self contained documentation of a go project and not using any server or service. I've found many pointers and I might not be that informed, but having a multi language project where "the other guys" produce some "nice" javadoc contained in one directory; I'm lost to do that easily with go/go doc/godoc/... just my 2cents.

@dmitshur
Copy link
Contributor

@marcellanz I agree, there doesn't exist a user friendly way of doing this yet. This issue is open and tracking resolving that task.

As a brief update, there has been progress made on relevant components that will enable resolving this issue. So it is moving along.

@marcellanz
Copy link

marcellanz commented Sep 10, 2019

@dmitshur thanks for the update. sounds good.

@tholsapp
Copy link

@dmitshur this would be a great feature. Is there a timeline of when this would be rolled out?

@dmitshur
Copy link
Contributor

It's not known when this issue will be complete. When there are updates, they'll be posted on this issue.

@bpeake-illuscio
Copy link

I want to add my two cents that I am currently wrapping up my first go library after being a python developer for 5 or so years, and the lack of easy static docs has me a little lost as well. Streamlined documentation is so important for team projects, and using godoc.org isn't a viable option for many in-house projects.

My use case: We already host most of our docs on readthdocs.org in a private repo. If i had a way of generating a static html file for my projects, then I might be able to upload them to their own page and keep our docs all in one place.

@dharmjit
Copy link

Any update on this or any external library currently able to do this. I need to host go documentation on private Gitlab. Thanks

@mraerino
Copy link
Contributor

I wrote a small prototype that can output static html: https://github.com/netlify/godoc-static
(not in any way complete, will try to write a blog post on it soon)

@zomglings
Copy link

@dmitshur : Is someone actively working on this? Is there a public discussion or collection of PRs that we can follow to get a better sense of the progress and perhaps where we could pitch in?

@tymonx
Copy link

tymonx commented May 16, 2020

I have workaround that using the wget command for that. Example: snippet

I have a similar issue with that. I'm using GitLab for my projects and I have decide to create and share with some handy GitLab CI YAML templates for Go projects that will automatically generate a static HTML Go documentation from the godoc tool without any external packages: https://gitlab.com/tymonx/gitlab-ci

Example: Go Logger documentation

Two nice features:

  • Embedded Go source code files
  • Search box is referencing to GitLab

I'm also waiting for this feature :)

@yash97
Copy link

yash97 commented May 8, 2021

Folks Its been 10 years can I ask if there is progress in this feature? 1 use case is if we get static docs we can host the project godocs at enterprise level.

@JohnStarich
Copy link

I've created a tool gopages based on the suggestions outlined here. Perhaps that may be useful for those generating internal enterprise docs for static sites.

A built-in solution would be excellent, nonetheless.

@edaniels
Copy link
Contributor

edaniels commented May 9, 2021

Wow @JohnStarich, beat me by 6 hours. I've created a similar tool that only outputs docs for direct dependencies here :) https://github.com/viamrobotics/govanity

@dsnet
Copy link
Member

dsnet commented Jun 4, 2021

For the record, that old Gerrit CL of mine has been partially mirrored over to https://github.com/dsnet/godoc. My original intention for that repo is to serve as a testing bed for various godoc proposals (e.g., #7873, #25444, #44447, #45533). If others want to use it to statically generate godoc pages, then they are free to do so.

@HRogge
Copy link

HRogge commented Nov 20, 2023

This is really annoying, especially because the anchors of links to source files are too the wrong line number... which is normally not recognized because godoc uses javascript to jump to the line too.

@3052
Copy link

3052 commented Jan 20, 2024

you can generate with Doc2Go:

https://github.com/abhinav/doc2go

it also supports generating different versions of a module

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests