Last active
November 12, 2022 06:46
-
-
Save lijunle/e0d211500bf878770113264d2998f9ac to your computer and use it in GitHub Desktop.
Enable open graph metadata for PiGallery2
This file contains hidden or 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
<html> | |
<head> | |
<script src="open-graph-metadata.js"></script> | |
</head> | |
<body>Index file.</body> | |
</html> |
This file contains hidden or 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
(function() { | |
function addProperty(property, content) { | |
var meta = document.createElement('meta'); | |
meta.setAttribute('property', property); | |
meta.setAttribute('content', content); | |
document.head.appendChild(meta); | |
} | |
function setMetadatas() { | |
var name = document.querySelector('.breadcrumb-item:last-child'); | |
if (name) { | |
addProperty('og:type', 'website'); | |
addProperty('og:title', name.textContent); | |
} | |
} | |
window.addEventListener('load', function () { | |
setTimeout(setMetadatas, 5000); | |
}); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment