Commit 33067d0d authored by Lyza Danger Gardner's avatar Lyza Danger Gardner Committed by Lyza Gardner

Add config support for Notebook feature

Add env NOTEBOOK_APP_URL and support for it in
build and config for annotator.
parent fdc5a1bd
......@@ -224,6 +224,10 @@ let isFirstBuild = true;
function generateBootScript(manifest, { usingDevServer = false } = {}) {
const { version } = require('./package.json');
const defaultNotebookAppUrl = process.env.NOTEBOOK_APP_URL
? `${process.env.NOTEBOOK_APP_URL}`
: '{current_scheme}://{current_host}:5000/notebook';
const defaultSidebarAppUrl = process.env.SIDEBAR_APP_URL
? `${process.env.SIDEBAR_APP_URL}`
: '{current_scheme}://{current_host}:5000/app.html';
......@@ -239,6 +243,7 @@ function generateBootScript(manifest, { usingDevServer = false } = {}) {
if (isFirstBuild) {
log(`Sidebar app URL: ${defaultSidebarAppUrl}`);
log(`Notebook app URL: ${defaultNotebookAppUrl}`);
log(`Client asset root URL: ${defaultAssetRoot}`);
isFirstBuild = false;
}
......@@ -247,6 +252,7 @@ function generateBootScript(manifest, { usingDevServer = false } = {}) {
.src('build/scripts/boot.bundle.js')
.pipe(replace('__MANIFEST__', JSON.stringify(manifest)))
.pipe(replace('__ASSET_ROOT__', defaultAssetRoot))
.pipe(replace('__NOTEBOOK_APP_URL__', defaultNotebookAppUrl))
.pipe(replace('__SIDEBAR_APP_URL__', defaultSidebarAppUrl))
// Strip sourcemap link. It will have been invalidated by the previous
// replacements and the bundle is so small that it isn't really valuable.
......
......@@ -39,6 +39,7 @@ export default function configFrom(window_) {
requestConfigFromFrame: settings.hostPageSetting('requestConfigFromFrame'),
services: settings.hostPageSetting('services'),
showHighlights: settings.showHighlights,
notebookAppUrl: settings.notebookAppUrl,
sidebarAppUrl: settings.sidebarAppUrl,
// Subframe identifier given when a frame is being embedded into
// by a top level client
......
......@@ -8,33 +8,33 @@ export default function settingsFrom(window_) {
const configFuncSettings = configFuncSettingsFrom(window_);
/**
* Return the href URL of the first annotator sidebar link in the given document.
* Return the href of the first annotator link in the given
* document with this `rel` attribute.
*
* Return the value of the href attribute of the first
* `<link type="application/annotator+html" rel="sidebar">` element in the given document.
*
* This URL is used as the src of the sidebar's iframe.
*
* @return {string} - The URL to use for the sidebar's iframe.
*
* @throws {Error} - If there's no annotator link or the first annotator has
* no href.
*
* `<link type="application/annotator+html" rel="${rel}">`
* element in the given document. This URL is used as the `src` for sidebar
* or notebook iframes.
*
* @param {string} rel - The `rel` attribute to match
* @return {string} - The URL to use for the iframe
* @throws {Error} - If there's no link with the `rel` indicated, or the first
* matching link has no `href`
*/
function sidebarAppUrl() {
function urlFromLinkTag(rel) {
const link = window_.document.querySelector(
'link[type="application/annotator+html"][rel="sidebar"]'
`link[type="application/annotator+html"][rel="${rel}"]`
);
if (!link) {
throw new Error(
'No application/annotator+html (rel="sidebar") link in the document'
`No application/annotator+html (rel="${rel}") link in the document`
);
}
if (!link.href) {
throw new Error(
'application/annotator+html (rel="sidebar") link has no href'
`application/annotator+html (rel="${rel}") link has no href`
);
}
......@@ -45,13 +45,13 @@ export default function settingsFrom(window_) {
* Return the href URL of the first annotator client link in the given document.
*
* Return the value of the href attribute of the first
* `<link type="application/annotator+html" rel="hypothesis-client">` element in the given document.
* `<link type="application/annotator+javascript" rel="hypothesis-client">`
* element in the given document.
*
* This URL is used to identify where the client is from and what url should be
* used inside of subframes
* This URL is used to identify where the client is from and what url should
* be used inside of subframes.
*
* @return {string} - The URL that the client is hosted from
*
* @throws {Error} - If there's no annotator link or the first annotator has
* no href.
*
......@@ -177,7 +177,7 @@ export default function settingsFrom(window_) {
const coerceValue =
typeof options.coerce === 'function' ? options.coerce : name => name;
if (!allowInBrowserExt && isBrowserExtension(sidebarAppUrl())) {
if (!allowInBrowserExt && isBrowserExtension(urlFromLinkTag('sidebar'))) {
return hasDefaultValue ? options.defaultValue : null;
}
......@@ -206,11 +206,14 @@ export default function settingsFrom(window_) {
get group() {
return group();
},
get notebookAppUrl() {
return urlFromLinkTag('notebook');
},
get showHighlights() {
return showHighlights();
},
get sidebarAppUrl() {
return sidebarAppUrl();
return urlFromLinkTag('sidebar');
},
get query() {
return query();
......
This diff is collapsed.
......@@ -21,6 +21,7 @@ const commonPolyfills = [
/**
* @typedef AnnotatorConfig
* @prop {string} assetRoot - The root URL to which URLs in `manifest` are relative
* @prop {string} notebookAppUrl - The URL of the sidebar's notebook
* @prop {string} sidebarAppUrl - The URL of the sidebar's HTML page
* @prop {Object.<string,string>} manifest -
* A mapping from canonical asset path to cache-busted asset path
......@@ -101,6 +102,13 @@ export function bootHypothesisClient(doc, config) {
sidebarUrl.type = 'application/annotator+html';
doc.head.appendChild(sidebarUrl);
// Register the URL of the notebook app which the Hypothesis client should load.
const notebookUrl = doc.createElement('link');
notebookUrl.rel = 'notebook';
notebookUrl.href = config.notebookAppUrl;
notebookUrl.type = 'application/annotator+html';
doc.head.appendChild(notebookUrl);
// Register the URL of the annotation client which is currently being used to drive
// annotation interactions.
const clientUrl = doc.createElement('link');
......
......@@ -26,10 +26,18 @@ if (isBrowserSupported()) {
if (document.querySelector('hypothesis-app')) {
bootSidebarApp(document, { assetRoot, manifest });
} else {
const notebookAppUrl = processUrlTemplate(
settings.notebookAppUrl || '__NOTEBOOK_APP_URL__'
);
const sidebarAppUrl = processUrlTemplate(
settings.sidebarAppUrl || '__SIDEBAR_APP_URL__'
);
bootHypothesisClient(document, { assetRoot, manifest, sidebarAppUrl });
bootHypothesisClient(document, {
assetRoot,
manifest,
notebookAppUrl,
sidebarAppUrl,
});
}
} else {
// Show a "quiet" warning to avoid being disruptive on non-Hypothesis sites
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment