This is how I added a link from ERDDAP dataset pages to the results of the IOOS Compliance checker for that page.
Example: https://data.cioospacific.ca/erddap/tabledap/BCSOP_daily.html, see "Compliance Results" link in top right corner
Editing erddap's setup.xml file, this goes in <startHeadHtml5>/<head>
:
<script>
// Show an element
var show = function (elem) {
elem.style.display = 'block';
};
// Hide an element
var hide = function (elem) {
elem.style.display = 'none';
};
document.addEventListener("DOMContentLoaded", function () {
const datasetID = location.href.split('/').pop().split('.')[0];
const hostname = location.hostname;
// Show this link only on dataset pages
// Note: This doesn't include the metadata page (yet)
const reg = new RegExp('/erddap/(table|grid)dap/([^.]+)\.(html|subset|graph)');
const a = document.getElementById('complianceLink');
// These pages match the url of regular dataset pages.
// Hope there are no datasets named "index"
const notDatasets = ['allDatasets', 'index']
const showComplianceLink = (reg.test(location.href) && !notDatasets.includes(datasetID))
const url = "https://cioos-siooc.github.io/erddap-compliance-runner/" + hostname + "/" +
datasetID +
".html";
if (showComplianceLink) {
a.href = url;
show(a)
} else {
hide(a)
}
});
</script>
This goes wherever you want it in the section:
<a id="complianceLink" href="" style="display:none">Compliance Results</a>
See these links for more info: https://github.com/cioos-siooc/erddap-compliance-runner