Commit 01cf0efe authored by Robert Knight's avatar Robert Knight

Add test page for JSTOR content banner

Add a test page at http://localhost:3000/pdf/jstor that shows the JSTOR
content banner.
parent 897dcf6d
{
"clientConfig": {
"contentPartner": "jstor"
}
}
...@@ -18,7 +18,7 @@ const TEMPLATE_PATH = `${__dirname}/templates/`; ...@@ -18,7 +18,7 @@ const TEMPLATE_PATH = `${__dirname}/templates/`;
/** /**
* @typedef Config * @typedef Config
* @prop {string} clientUrl - The URL of the client's boot script * @prop {string} clientUrl - The URL of the client's boot script
* @prop {object} clientConfig * @prop {object} clientConfig - Additional configuration for the Hypothesis client
*/ */
/** /**
...@@ -49,20 +49,15 @@ function renderScript(context) { ...@@ -49,20 +49,15 @@ function renderScript(context) {
function templateContext(config) { function templateContext(config) {
// Just the config by itself, in contrast with `hypothesisScript`, which // Just the config by itself, in contrast with `hypothesisScript`, which
// combines this config with a <script> that adds the embed script // combines this config with a <script> that adds the embed script
let hypothesisConfig = fs.readFileSync( const configTemplate = fs.readFileSync(
`${TEMPLATE_PATH}client-config.js.mustache`, `${TEMPLATE_PATH}client-config.js.mustache`,
'utf-8' 'utf-8'
); );
const hypothesisConfig = Mustache.render(configTemplate, {
if (config.clientConfig) { exampleConfig: config.clientConfig
const clientConfigScript = `<script type="application/json" class="js-hypothesis-config">${JSON.stringify( ? JSON.stringify(config.clientConfig)
config.clientConfig : null,
)}</script>`; });
hypothesisConfig = `
${hypothesisConfig}
${clientConfigScript}
`;
}
return { return {
hypothesisConfig, hypothesisConfig,
...@@ -131,6 +126,7 @@ function serveDev(port, config) { ...@@ -131,6 +126,7 @@ function serveDev(port, config) {
const suffix = req.params.suffix ? `?suffix=${req.params.suffix}` : ''; const suffix = req.params.suffix ? `?suffix=${req.params.suffix}` : '';
const fullUrl = `${req.protocol}://${req.hostname}:${port}${req.originalUrl}${suffix}`; const fullUrl = `${req.protocol}://${req.hostname}:${port}${req.originalUrl}${suffix}`;
// Read custom client configuration for this test document.
const configPath = pdfPath.replace(/\.pdf$/, '.config.json'); const configPath = pdfPath.replace(/\.pdf$/, '.config.json');
const extraConfig = fs.existsSync(configPath) const extraConfig = fs.existsSync(configPath)
? JSON.parse(fs.readFileSync(configPath)) ? JSON.parse(fs.readFileSync(configPath))
......
...@@ -31,6 +31,11 @@ ...@@ -31,6 +31,11 @@
// Open the sidebar when the page loads // Open the sidebar when the page loads
openSidebar: true, openSidebar: true,
{{#exampleConfig}}
// Additional configuration for the current test document
...{{{exampleConfig}}},
{{/exampleConfig}}
}; };
}; };
</script> </script>
\ No newline at end of file
...@@ -64,6 +64,7 @@ ...@@ -64,6 +64,7 @@
visit</a></li> visit</a></li>
<li><a href="/pdf/painting">PDF without selectable text</a></li> <li><a href="/pdf/painting">PDF without selectable text</a></li>
<li><a href="/pdf/gatsby">The Great Gatsby</a> (A long document)</li> <li><a href="/pdf/gatsby">The Great Gatsby</a> (A long document)</li>
<li><a href="/pdf/jstor">PDF with JSTOR banner</a></li>
</ul> </ul>
<h2>Page feature tests</h2> <h2>Page feature tests</h2>
......
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