nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.58k stars 1.47k forks source link

`nim doc --project --out:foo/bar.html` doesn't work; creates `foo/bar.html/` dir instead of a file #14508

Open kaushalmodi opened 4 years ago

kaushalmodi commented 4 years ago

--out:foo/bar.html does not work with nim doc --project .. (works well with nim doc .. i.e. without --project)

Example

Create a test file t.nim like below:

# t.nim
proc foo*() =
  ## Some proc

and run this command:

nim doc --project --out:test1/index.html t.nim

Look at the generated docs' tree stucture.

Current Output

test1/
└── index.html/
   ├── dochack.js
   ├── nimdoc.out.css
   ├── t.html
   ├── t.idx
   └── theindex.html

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.

test1/
├── dochack.js
├── nimdoc.out.css
├── index.html                <-- index.html instead of t.html
├── index.idx                 <-- index.idx instead of t.idx (for consistency, as name of this file doesn't matter)
└── theindex.html

Reason

Having the main or landing page export as index.html allows a better looking URL like https://USER.github.io/PROJECT/ (instead of https://USER.github.io/PROJECT/PROJECT.html).

Possible Solution

Additional Information

$ nim -v
Nim Compiler Version 1.3.5 [Linux: amd64]
Compiled at 2020-05-29
Copyright (c) 2006-2020 by Andreas Rumpf

git hash: 63d1a0289e872212e836559f92a785df51f4faac
active boot switches: -d:release

/cc @timotheecour

timotheecour commented 4 years ago

how about:

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

kaushalmodi commented 4 years ago

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.

kaushalmodi commented 4 years ago

Another option is to make --out throw and error if used with --project and add a --prettyUrls option.

timotheecour commented 4 years ago

We shouldn't need to predict the file locations

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.

kaushalmodi commented 4 years ago

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.

timotheecour commented 4 years ago

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.

the 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

kaushalmodi commented 4 years ago

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:

timotheecour commented 4 years ago

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.

(counter argument:

kaushalmodi commented 4 years ago

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.