13

So, I've finally released v1.0 of my EcoEvo package. Yay. Maybe I'll give an overview here soon.

I'd also like to advertise to my colleagues, perhaps non-Mathematica users, who might use it. The documentation, made with Workbench, has some worked examples already, so I thought it might be easiest to publish them on the Wolfram Cloud. I opened one such tutorial in the Mathematica help browser and hit "Publish to Cloud...", and it doesn't look too bad!

However, it doesn't look perfect either: enter image description here

The search bar was included and is totally non-functional. The links under "Related Tutorials" at the top and bottom don't work.

Still, this seems 95% of the way towards having decent-looking documentation on the web without much trouble.

Questions:

  1. Is there a way to remove that broken search-bar header and fix the links?
  2. Can I upload all the documentation pages to the cloud automatically, and maintain the directory structure?
Chris K
  • 20,207
  • 3
  • 39
  • 74
  • 1
    paclet: to properly linked can be resolved by using URLParse on them then changing the "Scheme" and "Domain" via ReplacePart and if needed also inserting the path before hitting it with a URLBuild or whatever the functions are again. This assumes you already know where the stuff will be going. Otherwise you'll need relative linking inside the package and to full WRI docs outside. I took that approach at one time before I decided I didn't want to host documentation for my packages (or really deal with documentation in any way...). – b3m2a1 Oct 24 '19 at 01:35
  • I updated my answer to address the problem with paclet: links. It's in the same spirit as the (slightly later) suggestion by @b3m2a1 above. Could certainly be made a bit more sophisticated, but should be a good start. Does this help, @Chris K? – Jan Pöschko Oct 25 '19 at 13:08

1 Answers1

12

Good to hear it (almost) works!

  1. The header is a docked cell, so, to remove it, you could evaluate
SetOptions[EvaluationNotebook[], DockedCells->{}]

in the notebook (before you publish it to the cloud).

  1. To upload a whole directory to the cloud, you can use
CopyDirectory["localpath", CloudObject["cloudpath"]]

(with localpath and cloudpath set appropriately). To make all the created cloud objects public, you could temporarily change $Permissions, or you could (recursively) iterate over them using CloudObjects and apply SetPermissions to each of them. We're working on more direct ways to do this, also in the GUI ("Publish Directory to Cloud"). Documentation also needs to be further improved, but the guide page about Managing Content in the Cloud is a good starting point for more information.

To address the problem with paclet: hyperlinks: I think the best option (for now) is to preprocess each notebook before publishing it to the cloud, replacing the target URLs of all such ButtonBoxes with corresponding cloud object URLs. Here's some code that does this:

dirPrefixes = <|
   "Guides" -> "guide", {"ReferencePages", "Symbols"} -> "ref", 
   "Tutorials" -> "tutorial"|>;

subdirString[prefix_String] := prefix
subdirString[prefixes_List] := FileNameJoin[prefixes]

pacletLinkQ[str_String] := StringStartsQ[str, "paclet:"]
pacletLinkQ[_] := False

fixPacletLink[str_, pacletName_, targetURL_] := 
 StringReplace[
   str, (StartOfString ~~ "paclet:" ~~ pacletName) -> targetURL] <> 
  ".nb"

fixPacletLinks[nb_Notebook, pacletName_, targetDir_String] := 
 nb /. ButtonBox[content_, opts1___, ButtonData -> data_?pacletLinkQ, 
    opts2___] :> 
   ButtonBox[content, 
    ButtonFunction :> (FrontEndExecute[
        NotebookLocate[{URL[#2], None}]] &), opts1, 
    ButtonData -> fixPacletLink[data, pacletName, targetDir], opts2]

removeDockedCells[
  Notebook[content_, opts1___, DockedCells -> _, opts2___]] := 
 Notebook[content, opts1, DockedCells -> {}, opts2]
removeDockedCells[Notebook[content_, opts___]] := 
 Notebook[content, DockedCells -> {}, opts]

resetMagnification[
  Notebook[content_, opts1___, (Rule | RuleDelayed)[Magnification, _],
    opts2___]] := Notebook[content, opts1, opts2]
resetMagnification[nb_Notebook] := nb

fixStyleSheet[
  Notebook[content_, opts1___, StyleDefinitions -> _, opts2___]] := 
 Notebook[content, opts1, 
  StyleDefinitions -> FrontEnd`FileName[{"Wolfram"}, "Reference.nb"], 
  opts2]

publishDocNB[filename_String, target : CloudObject[targetURL_, ___], 
  prefix_, pacletName_] := 
 Module[{nb, newNB, obj}, nb = Get[filename]; 
  newNB = resetMagnification@
    fixStyleSheet@
     removeDockedCells@fixPacletLinks[nb, pacletName, targetURL]; 
  obj = FileNameJoin[{target, prefix, FileNameTake[filename]}]; 
  Print["Publishing ", filename, " to ", obj]; 
  CloudPublish[newNB, obj]]

publishDocDir[pacletDir_, subdir_, prefix_, target_] := 
 Module[{nbfiles = 
    FileNames["*.nb", 
     FileNameJoin[{pacletDir, "Documentation", "English", 
       subdirString[subdir]}]], pacletName = FileNameTake[pacletDir]},
   publishDocNB[#, target, prefix, pacletName] & /@ nbfiles]

PublishPacletDocs[pacletDir_String, target_CloudObject] := 
 KeyValueMap[publishDocDir[pacletDir, #1, #2, target] &, dirPrefixes]

Calling the function like

PublishPacletDocs["~/Projects/EcoEvo/EcoEvo", CloudObject["EcoEvo"]]

will publish all documentation notebooks in the given paclet directory (assuming they're all in the usual subdirectory structure of Documentation/English) to a cloud directory EcoEvo in your cloud home directory.

This also takes care of points 1 and 2, and, as a little bonus, I also made it change the stylesheet to Wolfram/Reference.nb (since Wolfram/FunctionPageStyles.nb doesn't exist right now) and reset the Magnification to 1. (You could also deploy a custom stylesheet to the cloud and reference that.)

You can see the result here: https://www.wolframcloud.com/obj/jpoeschko/EcoEvo/guide/EcoEvo.nb

(Hope it's okay that I took your https://github.com/cklausme/EcoEvo and published it to my own Wolfram Cloud account for now. Just let me know if I should replace the link in this answer with a link to your own published version.)

Jan Pöschko
  • 922
  • 6
  • 14
  • 1
    I was experimenting with this too recently, and while the docked cell would be easy to fix, there are many other rendering problems which would be just too much trouble for me to work around. On this page, https://www.wolframcloud.com/obj/szhorvat/Published/MaTeX open the Applications heading and see many pink boxes. I was not even able to reproduce these pink boxes if I copied those cells into a new notebook and uploaded that one to the cloud. In the end, I gave up on trying to fix it. – Szabolcs Oct 10 '19 at 14:08
  • 1
    Trying to share docs like this seems like a lot of work. One would also need to rewrite the links (which now use the paclet:... format). – Szabolcs Oct 10 '19 at 14:09
  • 2
    However, I do have a package whose documentation is a single notebook (for better or worse). I seriously considered sharing this through the cloud. See here: https://www.wolframcloud.com/obj/szhorvat/Published/IGDocumentation Some issues with this: 1. *Very* slow rendering. This is somewhat understandable because the notebook is huge. But at the time when I originally uploaded it, the rendering was not this slow. Now it takes multiple minutes. – Szabolcs Oct 10 '19 at 14:21
  • WholeCellGroupOpener setting was either not honoured or went missing during cloud publishing ... This is better now because it seems that there are inline openers. 3. There are some random pink boxes which will work the next time I load the page. The good news is that I have not yet found anything that is consistently pink in this notebook.
  • – Szabolcs Oct 10 '19 at 14:23
  • 1
    Generally, for documentation sharing purposes, it would be extremely useful if we could have a way to share strictly read-only, non-interactive notebooks that load fast and don't put a lot of strain on the browser (think e.g. reading them on a Raspberry Pi). It'd be sufficient to have input cells copyable, just like in Mathematica's online documentation. – Szabolcs Oct 10 '19 at 14:27
  • A few more notes: The MaTeX doc notebooks were last saved with v10.0.2 (for compatibility), and created with several different versions (MaTeX is several years old). || In "IGDocumentation.nb", when I rotate 3D Graphs interactively, only the vertices are visible. || Most Graphs render in "retina resolution" temporarily when loading, then suddenly they drop to standard resolution. These are not dealbreakers for IGDocumntation, though. – Szabolcs Oct 10 '19 at 14:38
  • Hi Jan, thanks for your update, which solves most of my problems. I ran your script on the Workbench-built version of my docs, which looks even better. (I've now exposed the "build" directory on github). I had to add one more pattern to fixPacletLinks, namely TemplateBox[{content_, data_?pacletLinkQ}, "RefLink", opts___] :> TemplateBox[{content, fixPacletLink[data, pacletName, targetDir]}, "WebLink", opts]. Results are here. – Chris K Oct 27 '19 at 09:15
  • I've got only a few remaining issues. The only crucial one is that closed cell groups don't have openers (especially bad for "Details" section). Other less essential ones: the pulldown menus "See Also" and "Related Guides" on the top don't function and links to built-in Mathematica functions ask to "open in Mathematica" instead of linking to the web docs. See this page for examples of these issues. But this is quickly approaching great -- thanks! – Chris K Oct 27 '19 at 09:23
  • TBH, I don't fully understand the problem yet and there's probably a bug with WholeCellGroupOpener that we need to fix, and maybe another problem that prevents the new-style group openers (on the right of the cell content). But I looked at the style definitions in Reference.nb and ShowGroupOpener is set depending on the notebook's TaggingRules. One way to make the traditional group openers (on the left) show up is to set the notebook option TaggingRules->{"NewStyles"->False}. I tried this (using SetOptions[EvaluationNotebook[], ...]) in a copy of your SolveEcoEq.nb and it's fine. – Jan Pöschko Oct 28 '19 at 16:26
  • In terms of the pulldown menus at the top, you'd have to adjust the function fixPacletLinks to also look for these ActionMenuBoxes and fix up their right-hand sides which involve Documentation`HelpLookup (or just replace all of those in the whole notebook expression). – Jan Pöschko Oct 28 '19 at 16:29
  • 1
    @JanPöschko Omitting the fixStyleSheet step also brought the openers back, so something about those StyleSheets. I should be able to figure out the pulldown menus myself. Thanks again for all your help! – Chris K Oct 28 '19 at 22:02
  • Great! Thanks for the bounty. :-) Happy to help if you have follow-up questions. – Jan Pöschko Oct 29 '19 at 03:22
  • @JanPöschko I ended up using removePulldownMenus[Notebook[content_,opts___]]:=Notebook[content[[2;;]],opts]; to simply remove the pulldown menus. The final product is here. This should tide me over until the official paclet sharing becomes available. – Chris K Oct 31 '19 at 12:32