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

Method getMeta

src/service/ampdoc-impl.js:352–374  ·  view source on GitHub ↗

* Initializes (if necessary) cached map of an ampdoc's meta name values to * their associated content values and returns the map. * @return {!{[key: string]: string}}

()

Source from the content-addressed store, hash-verified

350 * @return {!{[key: string]: string}}
351 */
352 getMeta() {
353 if (this.meta_) {
354 return map(this.meta_);
355 }
356
357 this.meta_ = map();
358 const metaEls = dev()
359 .assertElement(this.win.document.head)
360 .querySelectorAll('meta[name]');
361 metaEls.forEach((metaEl) => {
362 const name = metaEl.getAttribute('name');
363 const content = metaEl.getAttribute('content');
364 if (!name || content === null) {
365 return;
366 }
367
368 // Retain only the first meta content value for a given name
369 if (this.meta_[name] === undefined) {
370 this.meta_[name] = content;
371 }
372 });
373 return map(this.meta_);
374 }
375
376 /**
377 * Returns the value of an ampdoc's meta tag content for a given name, or

Callers 1

getMetaByNameMethod · 0.95

Calls 5

mapFunction · 0.90
devFunction · 0.90
assertElementMethod · 0.80
getAttributeMethod · 0.80
forEachMethod · 0.45

Tested by

no test coverage detected