forked from kriasoft/react-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move head tag utlis from src/client.js to src/core/DOMUtlis.js
- Loading branch information
Showing
3 changed files
with
46 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* React Starter Kit (https://www.reactstarterkit.com/) | ||
* | ||
* Copyright © 2014-present Kriasoft, LLC. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE.txt file in the root directory of this source tree. | ||
*/ | ||
|
||
export function updateTag(tagName, keyName, keyValue, attrName, attrValue) { | ||
const node = document.head.querySelector(`${tagName}[${keyName}="${keyValue}"]`); | ||
if (node && node.getAttribute(attrName) === attrValue) return; | ||
|
||
// Remove and create a new tag in order to make it work with bookmarks in Safari | ||
if (node) { | ||
node.parentNode.removeChild(node); | ||
} | ||
if (typeof attrValue === 'string') { | ||
const nextNode = document.createElement(tagName); | ||
nextNode.setAttribute(keyName, keyValue); | ||
nextNode.setAttribute(attrName, attrValue); | ||
document.head.appendChild(nextNode); | ||
} | ||
} | ||
|
||
export function updateMeta(name, content) { | ||
updateTag('meta', 'name', name, 'content', content); | ||
} | ||
|
||
export function updateCustomMeta(property, content) { | ||
updateTag('meta', 'property', property, 'content', content); | ||
} | ||
|
||
export function updateLink(rel, href) { | ||
updateTag('link', 'rel', rel, 'href', href); | ||
} |