MCPcopy Create free account
hub / github.com/ampproject/amphtml / addViewerIntegrationScript

Function addViewerIntegrationScript

build-system/server/app.js:1503–1528  ·  view source on GitHub ↗

* @param {string} ampJsVersionString * @param {string} file * @return {string}

(ampJsVersionString, file)

Source from the content-addressed store, hash-verified

1501 * @return {string}
1502 */
1503function addViewerIntegrationScript(ampJsVersionString, file) {
1504 const ampJsVersion = parseFloat(ampJsVersionString);
1505 if (!ampJsVersion) {
1506 return file;
1507 }
1508 let viewerScript;
1509 // eslint-disable-next-line local/no-es2015-number-props
1510 if (Number.isInteger(ampJsVersion)) {
1511 // Viewer integration script from gws, such as
1512 // https://cdn.ampproject.org/viewer/google/v7.js
1513 viewerScript =
1514 '<script async src="https://cdn.ampproject.org/viewer/google/v' +
1515 ampJsVersion +
1516 '.js"></script>';
1517 } else {
1518 // Viewer integration script from runtime, such as
1519 // https://cdn.ampproject.org/v0/amp-viewer-integration-0.1.js
1520 viewerScript =
1521 '<script async ' +
1522 'src="https://cdn.ampproject.org/v0/amp-viewer-integration-' +
1523 ampJsVersion +
1524 '.js" data-amp-report-test="viewer-integr.js"></script>';
1525 }
1526 file = file.replace('</head>', viewerScript + '</head>');
1527 return file;
1528}
1529
1530/**
1531 * @param {express.Request} req

Callers 1

app.jsFile · 0.85

Calls 1

replaceMethod · 0.45

Tested by

no test coverage detected