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