Skip to content

Instantly share code, notes, and snippets.

@lijunle
Last active November 12, 2022 06:46
Show Gist options
  • Save lijunle/e0d211500bf878770113264d2998f9ac to your computer and use it in GitHub Desktop.
Save lijunle/e0d211500bf878770113264d2998f9ac to your computer and use it in GitHub Desktop.
Enable open graph metadata for PiGallery2
<html>
<head>
<script src="open-graph-metadata.js"></script>
</head>
<body>Index file.</body>
</html>
(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