Open kaushalmodi opened 4 years ago
how about:
nim doc --project -o:htmldocs/myfoo.html sub/foo.nim
does following:
behaves like nim doc --project --outdir:htmldocs sub/main.nim
and then adds a redirect page from htmldocs/myfoo.html
to htmldocs/foo.html
if these are 2 distinct files (or to wherever foo.html
ends with according to other options in particular --docroot
)this could be the simplest, so that files end in predictable locations and in particular browsing to foo.html
would also work.
And for the case where myfoo.html
is index.html
, it'll allow browsing via kaushalmodi.github.io/std_vector/
as in your example which would redirect to kaushalmodi.github.io/std_vector/std_vector.html
in your case
so that files end in predictable locations
We shouldn't need to predict the file locations. Some would expect an index.html while some would expect a PRJ.html. But that should not matter as the project repo will be putting in the correct hyperlink.
Adding redirection page, etc is entering the realm of designing a static site generator. Instead we should just make --out generate the specified file instead of a directory.
Another option is to make --out throw and error if used with --project and add a --prettyUrls option.
We shouldn't need to predict the file locations
# in main.nim
proc baz*(a: int) = discard
proc baz*(a: float) =
## see also `baz <main.html#baz,int>`_
or in some readme.md:
see [main fail](main.html)
the redirect would keep all links working.
Adding redirection page, etc is entering the realm of designing a static site generator
nah it's really simple:
<html>
<head>
<meta http-equiv="refresh" content="0; URL='nim.html'" />
</head>
</html>
or:
<html>
<body>
<script type="text/javascript">
window.location.href = "nim.html"; // or: window.location.replace("nim.html");
</script>
</body>
</html>
I just tried it, it works great, and all links keep working too.
but they're also used in human written doc comment links,
Yes, but the project author who uses --out:index.html
should how to cross-reference them in their own project. May be your point is valid for projects receiving a high influx of PR's. But still, this seems to be a really minor "issue".
For my projects at least, I wouldn't want the extra noise of extra html page created for each .nim file. It just boils down to the project author's preference on how the doc HTML should be named, and I think that the --out
should solve that for --project
just as it does for nim doc
without --project
.
nah it's really simple:
:)
I vaguely remember that with redirections, 301 redirections are the only ones recommendated. Meta refreshes like you suggested are frowned upon and not usually good for indexing by search engines. Ref: https://moz.com/learn/seo/redirection
It's a completely different territory than simple doc generation.
For the purpose of this issue, let's brainstorm how --project
+ --out
should behave.
Yes, but the project author who uses --out:index.html should how to cross-reference them in their own project.
that's not good, now when you write doc comment links you'd then have to know how the main module is going to be renamed; what if a module is used in different contexts? what if you're changing which one is the main module? all links get broken.
what if someone else is generating docs for that module? (eg: it should be feasible for nimble to generate docs for all packages, or nim to generate docs for all important_packages, or some org to generate docs for a number of projects under its umbrella etc)
I vaguely remember that with redirections, 301 redirections are the only ones recommendated. Meta refreshes like you suggested are frowned upon and not usually good for indexing by search engines. Ref: moz.com/learn/seo/redirection
adding <link rel="canonical" href="nim.html" />
does the trick see https://stackoverflow.com/a/19717455/1426932:
As for Google Bot, it treats <link rel="canonical" href= as 301 redirect, the effect is that you get your pages reindexed and that is what you want.
<html>
<head>
<meta http-equiv="refresh" content="0; URL='nim.html'" />
<link rel="canonical" href="nim.html" />
</head>
</html>
Redirect provides a simple and practical fix for that, with similar behavior as symlinks or aliases.
--project
should just go ahead and create index.html (via redirect) by default, since as you mentioned it makes navigating easierthe more uniform and simple doc creation is, the easier it is to interoperate. That's why i automated index generation when using --project
; by default it should all "just work" with sane defaults and the simplest command line.
And that's also why i'm automating --git:branch
etc tags so that it works out of the box without customization needed
now when you write doc comment links you'd then have to know how the main module is going to be renamed; what if a module is used in different contexts? what if you're changing which one is the main module? all links get broken.
First enough. That's a valid point.
Redirect provides a simple and practical fix for that, with similar behavior as symlinks or aliases.
Ok. Just to confirm that you are proposing to do this just for the main module's page? If not and if we want to do this for submodules too, it becomes a bit hairy.. we need to spec it out properly with all cases. E.g. what if we have submodules proj/sub1.nim, proj/sub2.nim? For those, there won't be a clear way to create redirect pages.
So to summarize:
nim doc --out:foo/index.html bar.nim
,
proposing to do this just for the main module's page
yes, where main
is whatever file is given to a nim doc command
The index.html will be a meta refresh page to foo/bar.html
yes (more precisely, to wherever bar.html is generated which depends on --docroot
)
need to check if anchorized links also get redirected
they don't (but should be possible with js) but I don't think that's needed since index.html would just be a "landing" (redirection) page for convenience, and all docgen links would just be links after redirection so you'd normally never see a foo/#abc
, you'd only see foo/bar.html#abc
(nor would you want external references to foo/#abc
)
This works the same way with or without --project
the case without --project
is maybe a bit more controversial, but we can implement proposal just for --project
for now.
--project
: same arguments as given above (avoiding broken links) and consistency.nim doc -b:js -o:htmldocs/foo_js.html foo.nim
nim doc -b:cpp -o:htmldocs/foo_cpp.html foo.nim
(counter argument:
nim doc -b:js -o:htmldocs/js/foo.html foo.nim
;I don't think that's needed since index.html would just be a "landing" (redirection) page for convenience, and all docgen links would just be links after redirection so you'd normally never see a foo/#abc, you'd only see foo/bar.html#abc
Ok. Makes sense.
the case without --project is maybe a bit more controversial, but we can implement proposal just for --project for now.
Ok. Sounds good.
--out:foo/bar.html
does not work withnim doc --project ..
(works well withnim doc ..
i.e. without--project
)Example
Create a test file
t.nim
like below:and run this command:
Look at the generated docs' tree stucture.
Current Output
Expected Output
A Nim project would have many nested Nim modules. So in that case,
nim doc --project --out:foo/bar.html
is expected to modify only the name of only main HTML page.Also it doesn't make sense for
--out
to create a directory; we already have--outdir
to do that.Reason
Having the main or landing page export as
index.html
allows a better looking URL likehttps://USER.github.io/PROJECT/
(instead ofhttps://USER.github.io/PROJECT/PROJECT.html
).Possible Solution
Additional Information
nim doc --out:..
without--project
. Example:nim doc --out:test2/index.html t.nim
generates:--out:dirname/index.html
would be very useful!/
as a result of the landing page being index.html. Few examples:nim doc --project --out:foo/index.html ..
, we wouldn't need to create a landing page separately. One example I know that exists in wild (/cc @c-blake ):/cc @timotheecour