Skip to content

Commit ce7d5b1

Browse files
committed
further repairs and refinments to "langfam" navigation
Enable a language-specific landing page to have "top" and "up" in the case that it's being viewed for a language family other than its own.
1 parent 4250d8a commit ce7d5b1

File tree

4 files changed

+115
-63
lines changed

4 files changed

+115
-63
lines changed

scribble-doc/scribblings/scribble/core.scrbl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,12 @@ The recognized @tech{style properties} are as follows:
491491
not include ``top,'' ``up,'', ``prev,'' and ``next'' controls
492492
if they would otherwise apply.}
493493

494+
@item{@indexed-racket['family-navigation] --- As a @tech{style
495+
property} for the main part of a rendered page, causes the HTML
496+
output to include ``top,'' ``up,'', ``prev,'' and ``next''
497+
controls only when the viewing context indicates a language
498+
family not in the page's language families.}
499+
494500
@item{@indexed-racket['no-header-controls] --- Suppresses link and
495501
link-information icons (if any) as part of a section header in
496502
HTML output.}
@@ -602,7 +608,8 @@ The @racket[parts] field contains sub-parts.
602608
#:changed "1.54" @elem{Changed @racket[tag-prefix] field to allow a
603609
@tech{part context} hash table.}
604610
#:changed "1.57" @elem{Added @racket['no-header-controls] support.}
605-
#:changed "1.59" @elem{Added @racket['no-navigation] support.}]}
611+
#:changed "1.59" @elem{Added @racket['no-navigation] and
612+
@racket['family-navigation] support.}]}
606613

607614

608615
@defstruct[paragraph ([style style?] [content content?])]{

scribble-lib/scribble/base-render.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@
326326
(cons p (current-tag-prefixes)))]
327327
[else (current-tag-prefixes)]))
328328

329-
(define/private (extend-part-context d)
329+
(define/public (extend-part-context d)
330330
(define p (part-tag-prefix d))
331331
(cond
332332
[(hash? p) (merge-part-contexts p (current-part-context))]

scribble-lib/scribble/html-render.rkt

Lines changed: 78 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@
281281
extract-version
282282
extract-authors
283283
extract-pretitle
284+
extend-part-context
284285
link-render-style-at-element)
285286
(inherit-field prefix-file style-file style-extra-files image-preferences)
286287

@@ -1025,12 +1026,29 @@
10251026
`([title . ,(if title* (string-append label " to " title*) label)]
10261027
[data-pltdoc . "x"]
10271028
,@more)))))
1029+
(define no-nav? (and (memq 'no-navigation (style-properties (part-style d))) #t))
1030+
(define family-nav? (and (memq 'family-navigation (style-properties (part-style d))) #t))
1031+
(define fam (and family-nav?
1032+
(or (search-extras (hash-ref (extend-part-context d) 'index-extras #hasheq()) 'language-family)
1033+
'("Racket"))))
1034+
(define (wrap-family c)
1035+
(if family-nav?
1036+
`((div ([style "display: none;"]
1037+
[class "family-navigation"]
1038+
[data-familynav ,(string-join fam ",")])
1039+
,@c))
1040+
c))
10281041
(define top-link
10291042
(titled-url
1030-
"up" (if (path? up-path)
1031-
(url->string* (path->url up-path))
1032-
"../index.html")
1033-
`[onclick . ,(format "return GotoPLTRoot(\"~a\");" (get-installation-name))]))
1043+
"up" (cond
1044+
[(path? up-path) (url->string* (path->url up-path))]
1045+
[up-path "../index.html"]
1046+
[else "index.html"])
1047+
`[onclick . ,(format "return GotoPLTRoot(\"~a\", \"index.html\", \"~a\");"
1048+
(get-installation-name)
1049+
(if up-path
1050+
"../"
1051+
""))]))
10341052
(define tocset-toggle
10351053
(make-element "tocsettoggle"
10361054
(list
@@ -1042,58 +1060,61 @@
10421060
'([title . "show/hide table of contents"]
10431061
[onclick . "TocsetToggle();"]))))
10441062
"contents"))))
1045-
(define no-nav? (and (memq 'no-navigation (style-properties (part-style d))) #t))
10461063
(define navleft
10471064
`(span ([class "navleft"])
10481065
,@(if search-box?
10491066
(list (if search-up-path search-box top-search-box))
10501067
(list `(div ([class "nosearchform"]))))
1051-
,@(render
1052-
sep-element
1053-
(and up-path (not no-nav?) (make-element top-link top-content))
1054-
tocset-toggle
1055-
;; sep-element
1056-
;; (make-element
1057-
;; (if parent (make-target-url "index.html" #f) "nonavigation")
1058-
;; contents-content)
1059-
;; sep-element
1060-
;; (if (or (not index) (eq? d index))
1061-
;; (make-element "nonavigation" index-content)
1062-
;; (make-link-element #f index-content (car (part-tags/nonempty index))))
1063-
)))
1068+
,@(wrap-family
1069+
(render
1070+
sep-element
1071+
(and (or up-path family-nav?) (not no-nav?) (make-element top-link top-content))
1072+
tocset-toggle
1073+
;; sep-element
1074+
;; (make-element
1075+
;; (if parent (make-target-url "index.html" #f) "nonavigation")
1076+
;; contents-content)
1077+
;; sep-element
1078+
;; (if (or (not index) (eq? d index))
1079+
;; (make-element "nonavigation" index-content)
1080+
;; (make-link-element #f index-content (car (part-tags/nonempty index))))
1081+
))))
10641082
(define navright
1065-
(if (or (not (or parent up-path next)) no-nav?)
1066-
""
1067-
`(span ([class "navright"])
1068-
,@(render
1069-
;; put space here for text browsers and to avoid an Opera issue
1070-
sep-element
1071-
(make-element
1072-
(cond [(not parent) "nonavigation"]
1073-
[prev (titled-url "backward" prev '[rel . "prev"])]
1074-
[else (titled-url "backward" "index.html" '[rel . "prev"]
1075-
#:title-from
1076-
(and (part? parent) parent))])
1077-
prev-content)
1078-
sep-element
1079-
(make-element
1080-
(cond
1081-
[(and (part? parent) (toc-part? parent ri)
1082-
(part-parent parent ri))
1083-
(titled-url "up" parent)]
1084-
[parent (titled-url "up" "index.html" #:title-from parent)]
1085-
;; up-path = #t => go up to the start page, using
1086-
;; cookies to get to the user's version of it (see
1087-
;; scribblings/main/private/utils for the code that
1088-
;; creates these cookies.)
1089-
[(eq? #t up-path) top-link]
1090-
[up-path (titled-url "up" up-path)]
1091-
[else "nonavigation"])
1092-
up-content)
1093-
sep-element
1094-
(make-element
1095-
(if next (titled-url "forward" next '[rel . "next"]) "nonavigation")
1096-
next-content)))))
1083+
(if (or (not (or parent up-path next family-nav?)) no-nav?)
1084+
""
1085+
`(span ([class "navright"])
1086+
,@(wrap-family
1087+
(render
1088+
;; put space here for text browsers and to avoid an Opera issue
1089+
sep-element
1090+
(make-element
1091+
(cond [(not parent) "nonavigation"]
1092+
[prev (titled-url "backward" prev '[rel . "prev"])]
1093+
[else (titled-url "backward" "index.html" '[rel . "prev"]
1094+
#:title-from
1095+
(and (part? parent) parent))])
1096+
prev-content)
1097+
sep-element
1098+
(make-element
1099+
(cond
1100+
[(and (part? parent) (toc-part? parent ri)
1101+
(part-parent parent ri))
1102+
(titled-url "up" parent)]
1103+
[parent
1104+
(titled-url "up" "index.html" #:title-from parent)]
1105+
;; up-path = #t => go up to the start page using
1106+
;; query or cookies to get to the user's version of it (see
1107+
;; scribblings/main/private/utils for the code that
1108+
;; creates these cookies.)
1109+
[(or (eq? #t up-path) family-nav?)
1110+
top-link]
1111+
[up-path (titled-url "up" up-path)]
1112+
[else "nonavigation"])
1113+
up-content)
1114+
sep-element
1115+
(make-element
1116+
(if next (titled-url "forward" next '[rel . "next"]) "nonavigation")
1117+
next-content))))))
10971118
(define navbar
10981119
`(div ([class ,(if top? "navsettop" "navsetbottom")])
10991120
,navleft ,navright nbsp)) ; need nbsp to make the navset bg visible
@@ -2167,3 +2188,10 @@
21672188
(string-append "file://" (path->string p))
21682189
(url->string (path->url p))))
21692190
(url->string (path->url p))))
2191+
2192+
(define (search-extras extras-tree key)
2193+
(cond
2194+
[(hash? extras-tree) (hash-ref extras-tree key #f)]
2195+
[(pair? extras-tree) (or (search-extras (car extras-tree) key)
2196+
(search-extras (cdr extras-tree) key))]
2197+
[else #f]))

scribble-lib/scribble/scribble-common.js

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,26 @@ function SetPLTRoot(ver, relative) {
9090
}
9191

9292
// adding index.html works because of the above
93-
function GotoPLTRoot(ver, relative) {
94-
var famroot = (GetPageArg("fam", false) ? GetPageArg("famroot", false) : false)
93+
function GotoPLTRoot(ver, root_relative, here_to_root_relative) {
94+
// the relative path is optional, default goes to the toplevel start page
95+
if (!root_relative) root_relative = "index.html";
96+
if (here_to_root_relative == undefined) here_to_root_relative = "../"
97+
var famroot = false;
98+
if (root_relative == "index.html") {
99+
famroot = (GetPageArg("fam", false) ? GetPageArg("famroot", false) : false)
100+
root_relative = famroot + "/index.html";
101+
}
102+
95103
var u = GetRootPath(ver);
96104
if (u == null) {
97-
// no cookie: use plain up link
98105
if (famroot) {
99-
location = MergePageArgsIntoUrl("../" + famroot + "/index.html");
100-
return false;
106+
location = MergePageArgsIntoUrl(here_to_root_relative + famroot + "/index.html");
107+
return false;
101108
}
109+
// no cookie and no famroot => follow href, instead
102110
return true;
103111
}
104-
// the relative path is optional, default goes to the toplevel start page
105-
if (!relative) relative = "index.html";
106-
if (relative == "index.html" && famroot) {
107-
relative = famroot + "/index.html";
108-
}
109-
location = MergePageArgsIntoUrl(u + relative);
112+
location = MergePageArgsIntoUrl(u + root_relative);
110113
return false;
111114
}
112115

@@ -200,3 +203,17 @@ AddOnLoad(function(){
200203
}
201204
}, false);
202205
});
206+
207+
AddOnLoad(function(){
208+
var es = document.getElementsByClassName("family-navigation");
209+
if (es.length > 0) {
210+
var fams = es[0].dataset.familynav.split(/,/);
211+
var fam = GetPageArg("famroot", false) && GetPageArg("fam", false);
212+
if (!fam) fam = "Racket";
213+
if (fams.indexOf(fam) == -1) {
214+
for (var i=0; i < es.length; i++) {
215+
es[i].style.display = "inline-block";
216+
}
217+
}
218+
}
219+
});

0 commit comments

Comments
 (0)