define(["exports", "core/pubsubhub"], function (exports, _pubsubhub) {
  "use strict";

  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.name = undefined;
  exports.run = run;
  var name = exports.name = "w3c/seo"; // Module w3c/seo
  // Manages SEO information for documents
  // e.g. set the canonical URL for the document if configured
  function run(conf, doc, cb) {
    var trLatestUri = conf.shortName ? "https://www.w3.org/TR/" + conf.shortName + "/" : null;
    switch (conf.canonicalURI) {
      case "edDraft":
        if (conf.edDraftURI) {
          conf.canonicalURI = new URL(conf.edDraftURI, doc.location).href;
        } else {
          (0, _pubsubhub.pub)("warn", "Canonical URI set to edDraft, " + "but no edDraftURI is set in configuration");
          conf.canonicalURI = null;
        }
        break;
      case "TR":
        if (trLatestUri) {
          conf.canonicalURI = trLatestUri;
        } else {
          (0, _pubsubhub.pub)("warn", "Canonical URI set to TR, but " + "no shortName is set in configuration");
          conf.canonicalURI = null;
        }
        break;
      default:
        if (conf.canonicalURI) {
          try {
            conf.canonicalURI = new URL(conf.canonicalURI, doc.location).href;
          } catch (err) {
            (0, _pubsubhub.pub)("warn", "CanonicalURI is an invalid URL: " + err.message);
            conf.canonicalURI = null;
          }
        } else if (trLatestUri) {
          conf.canonicalURI = trLatestUri;
        }
    }
    if (conf.canonicalURI) {
      var linkElem = doc.createElement("link");
      linkElem.setAttribute("rel", "canonical");
      linkElem.setAttribute("href", conf.canonicalURI);
      doc.head.appendChild(linkElem);
    }
    cb();
  }
});
//# sourceMappingURL=seo.js.map