Skip to content

Instantly share code, notes, and snippets.

@joelgriffith
Created January 15, 2018 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelgriffith/8f1cf0a4c4ac748ba79780348bcaa60a to your computer and use it in GitHub Desktop.
Save joelgriffith/8f1cf0a4c4ac748ba79780348bcaa60a to your computer and use it in GitHub Desktop.
Get's a site description
function getDescription() {
if (document.querySelector('meta[property="og:description"]')) {
return document.querySelector('meta[property="og:description"]').content;
}
if (document.querySelector('[itemprop="description"]')) {
return document.querySelector('[itemprop="description"]').text;
}
if (document.querySelector('meta[name="description"]')) {
return document.querySelector('meta[name="description"]').content;
}
return document.body.innerText.substring(0, 180) + '...';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment