Skip to content

Commit

Permalink
add indirection for user-scope searches
Browse files Browse the repository at this point in the history
When viewing documenation for a user-scoped package, the search box in
the top left was originally meant to find the documentation entry
point using a `PLT_Root...` cookie, which migrated to mean
`PLT_Root...` local storage. The local-storage approach stopped
working years ago, as browsers made different file count as different
domains.

This change enables a layer like `racket-index` to define cause
`user_doc_root` to be defined, which it can do as part of the
`local-redirect` layer that is alreayd in place. And that makes the
top-left search box work again.
  • Loading branch information
mflatt committed Oct 18, 2024
1 parent 7233e27 commit 18dc382
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions scribble-lib/scribble/scribble-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,24 @@ function SetPLTRoot(ver, relative) {

// adding index.html works because of the above
function GotoPLTRoot(ver, relative) {
var u = GetCookie("PLT_Root."+ver, null);
var u = GetRootPath(ver);
if (u == null) return true; // no cookie: use plain up link
// the relative path is optional, default goes to the toplevel start page
if (!relative) relative = "index.html";
location = u + relative;
return false;
}

function GetRootPath(ver) {
var u = GetCookie("PLT_Root."+ver, null);
if (u != null)
return u;
// use root specified by local-redirect wrapper, if present
if (typeof user_doc_root != "undefined")
return user_doc_root;
return null;
}

// Utilities ------------------------------------------------------------------

var normalize_rxs = [/\/\/+/g, /\/\.(\/|$)/, /\/[^\/]*\/\.\.(\/|$)/];
Expand All @@ -97,7 +107,7 @@ function NormalizePath(path) {
function DoSearchKey(event, field, ver, top_path) {
var val = field.value;
if (event && event.key === 'Enter') {
var u = GetCookie("PLT_Root."+ver, null);
var u = GetRootPath(ver);
if (u == null) u = top_path; // default: go to the top path
u += "search/index.html?q=" + encodeURIComponent(val);
u = MergePageArgsIntoUrl(u);
Expand Down

0 comments on commit 18dc382

Please sign in to comment.