Closed bennn closed 4 years ago
related issues: #208 #76
I think we should close racket/racket#874 since this subsumes that, and we should merge this as the first step.
Note that another possibility is to do this entirely with JavaScript -- just query the pkg server for the source package.
JavaScript sounds better. If we merged this as-is, we'd need to edit every Scribble file that needs a link.
Here's the algorithm we want:
Look at the x-source-pkg
attribute of the element. For https://docs.racket-lang.org/reference/More_Path_Utilities.html for the top title that's racket-doc
. Then you fetch https://pkgd.racket-lang.org/pkgn/pkg/racket-doc.json. Then that JSON document has a "versions"
key which has a "default"
key which has a "source"
key, which is "git://github.com/racket/racket/?path=pkgs/racket-doc"
for that document.
Then we probably need to process that URL a little, to get: https://github.com/racket/racket/tree/master/pkgs/racket-doc
and then add in the value of the x-source-module
attribute. That's (lib "scribblings/reference/reference.scrbl")
in this case, which we need to extract the string, and then combine them, to get https://github.com/racket/racket/tree/master/pkgs/racket-doc/scribblings/reference/reference.scrbl
which is what we want to link to.
That's basically the simplest case we need to handle, although some source URLs won't have ?path
. Other URLs will have a specification for the branch as well, and some will not be on GitHub where we won't know what to do. In general, a basic implemenation that just handled that example and ones without ?path
, only for GitHub, would be a great start.
Since this PR and renewed discussion has been one of the reason for me outlining the proposal for the possible long term solution in the issue: #228, I am referencing it here. It doesn't address the solution to be implemented right away unlike the one proposed by @samth but once overhauled it would make implementing this type of changes really simple with RDFa + JSON-LD.
If a part has the
package-source
property, then attach a URL to the HTML output so that the manuals can show a link to the "Document source" for editing / pull-requesting.For example:
That picture came from this code:
Another example, using GitLab:
Source code:
Both the above work very nicely because the source is a single file. If a document uses
include-section
, then sub-parts inherit the parent's URL.For example these two links in the redex docs:
Come from one line of code, but sadly point to the same source file:
A sub-part can manually give a more specific URL:
But I haven't figured out a nice way to infer a better URL.
And really, ideally, I'd like to put one base URL in the
scribblings
entry of aninfo.rkt
and get precise URLs without any changes to the document. So, suggestions are definitely welcome.