Skip to content

Commit 84e02af

Browse files
panglesdjonludlam
andauthored
feat: use output from new doc-ci with odoc 3 features in the package documentation area (#3124)
* Get docs from new docs CI Co-authored-by: Jon Ludlam <jon@recoil.org> * Docs: Update to new odoc3 json format Co-authored-by: Jon Ludlam <jon@recoil.org> * Docs: use new `status.json` from odoc 3 Co-authored-by: Jon Ludlam <jon@recoil.org> * Docs: use header field It was added in ocaml/odoc#1314 and needs not be ignored Co-authored-by: Jon Ludlam <jon@recoil.org> * Docs: fix search script location change with odoc_driver Co-authored-by: Jon Ludlam <jon@recoil.org> * Docs: fix search results' url Co-authored-by: Jon Ludlam <jon@recoil.org> * Docs: compute sidebar from toc json Co-authored-by: Jon Ludlam <jon@recoil.org> * Docs: do not reload global toc on toc click Co-authored-by: Jon Ludlam <jon@recoil.org> * Docs: uniformize toc look Co-authored-by: Jon Ludlam <jon@recoil.org> * Docs: small refactor of breadcrumbs Co-authored-by: Jon Ludlam <jon@recoil.org> * Docs: allow breadcrumbs without href Odoc 3 allows to have breadcrumbs without href. Currently, the breadcrumbs are still computed by ocaml.org, but soon it will be taken from odoc3's json output. Co-authored-by: Jon Ludlam <jon@recoil.org> * Docs breadcrumbs: Adding `page` kind With odoc 3 and hierarchical documentation, breadcrumbs will include pages. They are rendered with `/` between them (while other components are rendered with `.` between them). So We can have `library1/Module.Submodule`. Pages cannot yet happen since we still compute breadcrumbs ourselves. Co-authored-by: Jon Ludlam <jon@recoil.org> * rename `library_path` to `path`: pages also have/are in breadcrumbs Co-authored-by: Jon Ludlam <jon@recoil.org> * Docs breadcrumbs: use the one computed by odoc without processing Co-authored-by: Jon Ludlam <jon@recoil.org> * Add dependency on ppx_deriving_yojson * Docs: hide toc until alpine has loaded From https://alpinejs.dev/directives/cloak : > Sometimes, when you're using AlpineJS for a part of your template, there is a > "blip" where you might see your uninitialized template after the page loads, > but before Alpine loads. > > `x-cloak` addresses this scenario by hiding the element it's attached to until > Alpine is fully loaded on the page. > > For `x-cloak` to work however, you must add the following CSS to the page. > > ``` > [x-cloak] { display: none !important; } > ``` * Add source pages to docs * Render html in breadcrumbs * Add style for rendered source code * Handle redirection Since odoc 3, and the replacement of voodoo by odoc_driver as the odoc driver, the layout for docs has changed. Since we do not want to break previously existing links, we redirect the old layout to the new one. * Sidebar: open sub-toc when clicking on a page from the sidebar * Doc: handle asset loading Documentation assets are not present as json files. Therefore, if we do not find a .json target, we try to load it as an asset. This is not ideal: assets always require two requests to the documentation server. 404 pages also trigger two requests... * Fix package files' links * Fix package files appearing in global toc * Fix theme for source rendering * Revert keeping the sidebar on new page loading * Finally implement avoid reloading sidebar * Docs: Improve source code target highlighting * Improve css of source rendering line numbers * Improve links to source style * Docs: only show right sidebar when it exists * Improve error handling for status.json * Fix enter on search result Odoc 3's search has already a leading `/`. * Fix redirection on edge cases `old_path` and `new_path` do not include the prefix, which makes the detection of redirection harder. Previously, the url `/p/odoc/3.0.0/doc/odoc.odoc/Odoc_odoc/Sidebar/index.html` would trigger the rewriting: `doc/Odoc_odoc/Sidebar/index.html` -> `doc/odoc.odoc/Odoc_odoc/Sidebar/index.html` which is a bug. Adding a / in the rewriting rules solves it * Put documentation-related code in a documentation file * Consider non-html files as assets * Turn sidebar into Navmap earlier * Increment cache version and update comments around it --------- Co-authored-by: Jon Ludlam <jon@recoil.org>
1 parent f4512d9 commit 84e02af

File tree

17 files changed

+1008
-589
lines changed

17 files changed

+1008
-589
lines changed

asset/css/doc.css

Lines changed: 302 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
[x-cloak] { display: none !important; }
2+
13
div.odoc {
2-
max-width: 56rem /* 896px */;
4+
max-width: 67rem;
35
position: relative;
46
}
57

@@ -186,12 +188,12 @@ div.odoc span.at-tag {
186188
font-weight: bold;
187189
}
188190

189-
div.odoc a {
191+
div.odoc a:not(.source_container a):not(.source_link) {
190192
font-weight: bold;
191193
color: #cc4e0c;
192194
}
193195

194-
.dark div.odoc a {
196+
.dark div.odoc a:not(.source_container a):not(.source_link) {
195197
text-decoration: underline;
196198
color:white;
197199
}
@@ -314,6 +316,24 @@ div.odoc .comment-delim {
314316
border-color: rgb(32, 68, 165);
315317
}
316318

319+
.navmap-tag.page-tag::after {
320+
content: "P";
321+
}
322+
.page-tag{
323+
color: rgb(32, 68, 165);
324+
background-color: rgb(32, 68, 165);
325+
border-color: rgb(32, 68, 165);
326+
}
327+
328+
.navmap-tag.source-tag::after {
329+
content: "S";
330+
}
331+
.source-tag{
332+
color: rgb(97, 8, 138);
333+
background-color: rgb(97, 8, 138);
334+
border-color: rgb(97, 8, 138);
335+
}
336+
317337
span.icon-expand > .navmap-tag,
318338
span.no-expand > .navmap-tag {
319339
color: white;
@@ -344,10 +364,12 @@ span.arrow-expand.open {
344364
}
345365

346366
span.sign-expand::before {
347-
content: " \002B";
367+
content: "\002B";
348368
display: flex;
369+
justify-content: center;
349370
align-items: center;
350371
font-size: 1.25rem;
372+
width: 1.25rem;
351373
margin-top: -0.25rem;
352374
}
353375

@@ -359,3 +381,279 @@ span.sign-expand.open::before {
359381
/* Lists of modules */
360382

361383
.modules { list-style-type: none; padding-left:0; }
384+
385+
/* Taken from odoc's css sheet */
386+
387+
.source_container {
388+
389+
/* light gruvbox theme colors */
390+
--bg_h: #f9f5d7;
391+
--bg: #f6f8fa; /*#fbf1c7;*/
392+
--bg_s: #f2e5bc;
393+
--bg1: #ebdbb2;
394+
--bg2: #d5c4a1;
395+
--bg3: #bdae93;
396+
--bg4: #a89984;
397+
--bg_highlighted: #fff3a0;
398+
399+
--fg: #282828;
400+
--fg1: #3c3836;
401+
--fg2: #504945;
402+
--fg3: #665c54;
403+
--fg4: #7c6f64;
404+
405+
--red: #9d0006;
406+
--green: #79740e;
407+
--yellow: #b57614;
408+
--blue: #076678;
409+
--purple: #8f3f71;
410+
--aqua: #427b58;
411+
--orange: #af3a03;
412+
--gray: #928374;
413+
414+
--red-dim: #cc2412;
415+
--green-dim: #98971a;
416+
--yellow-dim: #d79921;
417+
--blue-dim: #458598;
418+
--purple-dim: #b16286;
419+
--aqua-dim: #689d6a;
420+
--orange-dim: #d65d0e;
421+
--gray-dim: #7c6f64;
422+
423+
/* odoc colors */
424+
--odoc-blue: #5c9cf5;
425+
--odoc-bg: #FFFFFF;
426+
--odoc-bg1: #f6f8fa;
427+
--odoc-fg: #333333;
428+
--odoc-fg1: #1F2D3D;
429+
430+
}
431+
432+
body.dark .source_container {
433+
/* dark gruvbox theme colors */
434+
--bg_h: #1d2021;
435+
--bg: #282828;
436+
--bg_s: #32302f;
437+
--bg1: #3c3836;
438+
--bg2: #504945;
439+
--bg3: #665c54;
440+
--bg4: #7c6f64;
441+
--bg_highlighted: #3c3836;
442+
443+
--fg: #fbf1c7;
444+
--fg1: #ebdbb2;
445+
--fg2: #d5c4a1;
446+
--fg3: #bdae93;
447+
--fg4: #a89984;
448+
449+
--red: #fb4934;
450+
--green: #b8bb26;
451+
--yellow: #fabd2f;
452+
--blue: #83a598;
453+
--purple: #d3869b;
454+
--aqua: #8ec07c;
455+
--gray: #928374;
456+
--orange: #fe8019;
457+
458+
--red-dim: #cc2412;
459+
--green-dim: #98971a;
460+
--yellow-dim: #d79921;
461+
--blue-dim: #458588;
462+
--purple-dim: #b16286;
463+
--aqua-dim: #689d6a;
464+
--gray-dim: #a89984;
465+
--orange-dim: #d65d0e;
466+
467+
/* odoc colors */
468+
--odoc-blue: #5c9cf5;
469+
--odoc-bg: #202020;
470+
--odoc-bg1: #252525;
471+
--odoc-fg: #bebebe;
472+
--odoc-fg1: #777;
473+
}
474+
475+
.source_container .source_line_column a {
476+
text-decoration: none;
477+
color:var(--fg4);
478+
}
479+
480+
481+
.source_container {
482+
--code-color: var(--fg);
483+
--code-background: var(--bg);
484+
--code-highligthed-background: var(--bg_highlighted);
485+
486+
--source-link-color: var(--fg4);
487+
--source-line-column: var(--fg3);
488+
--source-line-column-bg: var(--bg_h);
489+
490+
--source-code-comment: var(--gray);
491+
--source-code-docstring: var(--green-dim);
492+
--source-code-lident: var(--fg1);
493+
--source-code-uident: var(--blue);
494+
--source-code-literal: var(--yellow);
495+
--source-code-keyword: var(--red);
496+
--source-code-underscore: var(--fg3);
497+
--source-code-operator: var(--purple);
498+
--source-code-parens: var(--orange-dim);
499+
--source-code-separator: var(--orange-dim);
500+
}
501+
502+
.source_container .source_code a:not(:hover) {
503+
text-decoration: inherit;
504+
}
505+
506+
/* Source links float inside preformated text or headings. */
507+
.odoc a.source_link {
508+
float: right;
509+
color: gray;
510+
font-size: initial;
511+
text-decoration: none;
512+
}
513+
514+
.odoc a.source_link:hover {
515+
color: unset;
516+
}
517+
518+
.source_container {
519+
display: flex;
520+
padding: 0;
521+
}
522+
523+
.source_line_column {
524+
padding-right: 0.5em;
525+
text-align: right;
526+
color: var(--source-line-column);
527+
background: var(--source-line-column-bg);
528+
}
529+
530+
.source_line {
531+
padding: 0 1em;
532+
}
533+
534+
.source_code {
535+
flex-grow: 1;
536+
background: var(--code-background);
537+
padding: 0 0.3em;
538+
color: var(--code-color);
539+
}
540+
541+
542+
/* Linked highlight */
543+
.source_code *:target {
544+
box-decoration-break: clone;
545+
-webkit-box-decoration-break: clone; /* for Safari/Chrome */
546+
background-color: var(--code-highligthed-background);
547+
padding: 3px 0 3px;
548+
/* Extend the background without expanding the element's size. Without expansion
549+
of background, lines background don't touch each other and make things look
550+
weird on multilines targets */
551+
}
552+
553+
/* Keywords */
554+
.source_code :is(.AND, .ANDOP, .AS, .ASSERT,
555+
.BAR, .BEGIN,
556+
.CLASS, .CONSTRAINT,
557+
.DO, .DONE, .DOWNTO,
558+
.ELSE, .END, .EXCEPTION, .EXTERNAL,
559+
.FOR, .FUN, .FUNCTION, .FUNCTOR,
560+
.IF, .IN, .INCLUDE, .INHERIT, .INITIALIZER,
561+
.LAZY, .LESSMINUS, .LET, .LETOP,
562+
.MATCH, .METHOD, .MINUSGREATER, .MODULE, .MUTABLE,
563+
.NEW, .NONREC,
564+
.OBJECT, .OF, .OPEN,
565+
.PERCENT, .PRIVATE,
566+
.REC,
567+
.SEMISEMI, .SIG, .STRUCT,
568+
.THEN, .TO, .TRY, .TYPE,
569+
.VAL, .VIRTUAL,
570+
.WHEN, .WITH, .WHILE)
571+
{
572+
color: var(--source-code-keyword);;
573+
}
574+
575+
/* Separators */
576+
.source_code :is(.COMMA, .COLON, .COLONGREATER, .SEMI) {
577+
color: var(--source-code-separator);
578+
}
579+
580+
/* Parens
581+
`begin` and `end ` are excluded because `end` is used in other, more
582+
keyword-y contexts*/
583+
.source_code :is(.BARRBRACKET,
584+
.LBRACE,
585+
.LBRACELESS,
586+
.LBRACKET,
587+
.LBRACKETAT,
588+
.LBRACKETATAT,
589+
.LBRACKETATATAT,
590+
.LBRACKETBAR,
591+
.LBRACKETGREATER,
592+
.LBRACKETLESS,
593+
.LBRACKETPERCENT,
594+
.LBRACKETPERCENTPERCENT,
595+
.LPAREN,
596+
.RBRACE,
597+
.RBRACKET,
598+
.RPAREN)
599+
{
600+
color: var(--source-code-parens);
601+
}
602+
603+
/* Prefix operators */
604+
.source_code :is(.ASSERT, .BANG, .PREFIXOP,
605+
/* Infix operators.
606+
A choice had to be made for equal `=` which is both a keyword and an operator.
607+
It looked better having it as an operator, because when it is a keyword,
608+
there are already loads of keyword around.
609+
It would look even nicer if there was a way to distinguish between these
610+
two cases.*/
611+
.INFIXOP0, .INFIXOP1, .INFIXOP2, .INFIXOP3, .INFIXOP4,
612+
.BARBAR, .PLUS, .STAR, .AMPERAMPER, .AMPERAND, .COLONEQUAL, .GREATER, .LESS,
613+
.MINUS, .MINUSDOT, .MINUSGREATER, .OR, .PLUSDOT, .PLUSEQ, .EQUAL)
614+
{
615+
color: var(--source-code-operator);
616+
}
617+
618+
/* Upper case ident
619+
`true` and `false` are considered uident here, because you can bind them in a
620+
constructor defintion :
621+
```ocaml
622+
type my_bool =
623+
| true of string
624+
| false
625+
| Other of int
626+
```
627+
*/
628+
.source_code :is(.UIDENT, .COLONCOLON, .TRUE, .FALSE) {
629+
color: var(--source-code-uident);
630+
631+
}
632+
633+
/* Lower case idents.
634+
Quotes are here because of `type 'a t = 'a list`,
635+
and question mark and tildes because of
636+
```ocaml
637+
let f ~a ?b () = Option.map a b
638+
```
639+
*/
640+
.source_code :is(.LIDENT, .QUESTION, .QUOTE, .TILDE) {
641+
color: var(--source-code-lident);
642+
}
643+
644+
/* Litterals */
645+
.source_code :is( .STRING, .CHAR, .INT, .FLOAT, .QUOTED_STRING_EXPR, .QUOTED_STRING_ITEM) {
646+
color: var(--source-code-literal);
647+
}
648+
649+
.source_code :is(.UNDERSCORE) {
650+
color: var(--source-code-underscore);
651+
}
652+
653+
.source_code :is(.DOCSTRING) {
654+
color: var(--source-code-docstring);
655+
}
656+
657+
.source_code :is(.COMMENT) {
658+
color: var(--source-code-comment);
659+
}

dune-project

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
ezjsonm
7373
lambdasoup
7474
ptime
75+
ppx_deriving_yojson
7576
(cmdliner
7677
(>= 1.1.0))
7778
xmlm

ocamlorg.opam

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ depends: [
4949
"ezjsonm"
5050
"lambdasoup"
5151
"ptime"
52+
"ppx_deriving_yojson"
5253
"cmdliner" {>= "1.1.0"}
5354
"xmlm"
5455
"uri"

0 commit comments

Comments
 (0)