/
githubmirror
/
amphtml
Обзор
Документация
Войти
/
githubmirror
/
amphtml
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/preact/utils/docInfo.js
47 строк
986 B
Jake Fried
typecheck: src/preact/components (#37463)
04 фев 2022, 23:59
Не верифицирован
04 фев 2022, 23:59
2004c91
Код
Авторство
О чём код?
import {urlUtils} from './url'; export const docInfo = { /** * @param {string} metaName * @return {string|null} */ getMetaByName(metaName) { const metas = self.document.head.querySelectorAll('meta[name]'); return ( Array.from(metas) .find( (meta) => meta.getAttribute('name') === metaName && meta.getAttribute('content') ) ?.getAttribute('content') || null ); }, /** * @return {string} */ get sourceUrl() { return self.location.href; }, /** * @return {string} */ get canonicalUrl() { const rootNode = self.document; const canonicalUrl = rootNode?.AMP?.canonicalUrl; if (canonicalUrl) { return canonicalUrl; } /** @type {HTMLLinkElement | null} */ const canonicalTag = rootNode.querySelector('link[rel=canonical]'); if (canonicalTag) { return urlUtils.parse(canonicalTag.href).href; } return this.sourceUrl; }, };