-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Scaladoc: Warn about special characters in filenames according to the default Jekyll rules #14657
Conversation
cce9982
to
1c4489c
Compare
If the problem manifests only with Jekyll, I’d be tempted to find a fix on the Jekyll side rather than the Scaladoc side. What happens if you do Otherwise, could you please provide a list of page URLs in the Scala API that are affected by this change? |
Yes, |
I'd say we need to merge that before 3.1.3-RC1 release because otherwise users would need to work with Jekyll to have their static sites deployed. |
IIUC, the output of Scaladoc does not contain |
It does contain |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's only one thing to change here. Besides that, LGTM.
val relativised = root.toPath.relativize(path).toString() | ||
// we remove all the '_' from _docs, _blog ... as having | ||
// $underlinedocs in the url by default will look quite ugly | ||
val withUnderlineRemoved = relativised.replaceFirst("^\\_", "") | ||
Paths.get(withUnderlineRemoved) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should there just do:
root.toPath.resolve("docs").relativize(path)
Oh, that’s an issue then. I thought |
I agree that when user decides to create a page which is not accepted by Jekyll then they should take care of that in Jekyll. In case of the |
@@ -101,7 +101,7 @@ abstract class Renderer(rootPackage: Member, val members: Map[DRI, Member], prot | |||
val all = navigablePage +: redirectPages | |||
// We need to check for conflicts only if we have top-level member called docs | |||
val hasPotentialConflict = | |||
rootPackage.members.exists(m => m.name.startsWith("_docs")) | |||
rootPackage.members.exists(m => m.name.startsWith("docs")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn’t it the case only if apiSubdirectory
is false
? Also, would a package named blog
cause a conflict too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blog
won't cause a conflict because it's rendered under docs
This place is just a heuristics that informs user about potential conflict. Even so, of course, checking the apiSubdirectory flag seems sensible.
I agree with changing this in Scaladoc too. I am not sure about escaping some symbols because of Jekyll. I prefer if we tell the users to put a |
We can check generated links if they contain invalid characters and produce a warning with possible solution. Should we have a |
I like this idea! I prefer not introducing another configuration flag 😄 |
Sound good to me as well. I will redo this PR so that we:
|
1c4489c
to
4402151
Compare
val relativizeFrom = if args.apiSubdirectory then docsPath else root.toPath | ||
def relativize(path: Path): Path = | ||
if args.apiSubdirectory then | ||
docsPath.relativize(path) | ||
else | ||
val relativised = root.toPath.relativize(path).toString() | ||
// we remove all the '_' from _docs to avoid unnecessary | ||
// incompatiblilites with Jekyll | ||
val withUnderlineRemoved = relativised.replaceFirst("^\\_", "") | ||
Paths.get(withUnderlineRemoved) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately I was not able to simplify this, @pikinier20 suggestion resulted in obtaining paths like ../_docs/A.md
instead of docs/A.md
like we want to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we then just be specific to _docs
?
ie, relativised.replaceFirst("^\\_docs", "docs")
(it’s a pity that there is no replaceFirstLiterally
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def relativize(path: Path): Path =
if args.apiSubdirectory then
docsPath.relativize(path)
else
val relativised = docsPath.relativize(path)
Paths.get("docs").resolve(relativised)
4402151
to
60a0ed7
Compare
|
||
|
||
// We collect and report any generated files incompatible with Jekyll | ||
private lazy val jekyllIncompatLinks = mutable.HashSet[String]() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the scope of this cache?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's used anywhere where Paths are generated, from Tasty reading to rendering, so DocContext felt like the right place for it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One problem that might come is that this set exists throughout the life of the entire Scaladoc process. However, it shouldn't be that big so that's probably OK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think it would be too big. My concern is that if we run scaladoc twice it may still warn about the files of the first run, or something like that.
Would it be possible to emit the warnings on the fly, rather than keeping a global mutable set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late response. It would be possible to emit them on the fly, but it would be much less elegant in my opinion with harder to read repeated suggestions. With any empty package potentially causing multiple paths to be affected, users are going to see this warning a lot, so I would personally prefer it to be as concise as possible - also having the paths printed right next to each other will make them easier to work with in for the Jekyll config. I'm unsure about the scope now - I was under the impression that the scaladoc process always ended after generation, but I don't actually know how it's handled by sbt etc. @pikinier20 What do you think? Sorry for dragging this issue for such a long time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DocContext is re-created on each run so we dont need to worry about warnings from previous runs. Also, I don't have strong opinion about keeping links in set instead of warning on the fly. For me, it can stay as it is.
60a0ed7
to
4d6fd7e
Compare
@@ -17,6 +17,8 @@ import java.io.PrintStream | |||
import scala.io.Codec | |||
import java.net.URL | |||
import scala.util.Try | |||
import scala.collection.mutable | |||
import dotty.tools.scaladoc.util.Check._ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this import used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I've made the import more explicit since it was only one method, not sure why I made it like this before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like nothing changed here.
There were problems with GitHub last week. Perhaps something didn't get pushed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true, thanks for noticing, I've force pushed it just now.
4d6fd7e
to
b8ffef5
Compare
As Jekyll (and in extension GitHub pages) makes starting a file/folder name with a couple characters illegal, an additional check is added for those and problematic paths are reported. To avoid always having "_docs" if not using -Yapi_subdirectory in url by default in the static site, we also replace that with "docs". Some tests concerning links were adjusted to accomodate the changes. Example testcase for illegal jekyll chars in Scaladoc was also added.
b8ffef5
to
d3ce129
Compare
This PR adds functionality of escaping special characters in generated filenames. These rules consist of the default Jekyll rules, which do not allow to put some chars in certain places of names of the deployed files - otherwise those file are not being generated. Since GitHub Pages uses Jekyll for deployment, an effect of these rules can be wide (even if the Jekyll itself can have those rules changed).Those rules can be found here.
They consist of:* _ at the beginning of the filenames* ~ at the beginning of the filenames (docs above mention the end of the filenames, but neither the original issue nor my tests confirm)* # at the beginning of the filenames* . at the beginning of the filenames (doesn’t really matter here, but added for clarity and to future-proof)Tests were adjusted to accomodate the changes.I also tested GitHub Pages manually: without the PR, with the PR.
Instead of escaping the characters, we collect them and report them in a warning after generating the documentation, hinting about adding a
.nojekyll
file if using GitHub Pages.Important: will break links (previous _docs will become docs if -Yapi-subdirectory is not used).
Fixes #14612