UNPKG

gpreview

Version:

Preview Ghost themes locally without a full Ghost installation

119 lines 5.08 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ghostHeadHelper = ghostHeadHelper; const handlebars_1 = __importDefault(require("handlebars")); function ghostHeadHelper(_options) { const site = this.site || this['@site']; const post = this.post || this['@post']; const page = this.page || this['@page']; const tag = this.tag || this['@tag']; const author = this.author || this['@author']; const head = []; let canonicalUrl = site?.url || ''; if (post) { canonicalUrl += post.url; } else if (page) { canonicalUrl += page.url; } else if (tag) { canonicalUrl += tag.url; } else if (author) { canonicalUrl += author.url; } head.push(`<link rel="canonical" href="${canonicalUrl}" />`); let metaTitle = site?.title || ''; let metaDescription = site?.description || ''; if (post || page) { const content = post || page; metaTitle = content?.meta_title || content?.title || metaTitle; metaDescription = content?.meta_description || content?.custom_excerpt || content?.excerpt || metaDescription; } else if (tag) { metaTitle = tag.meta_title || `${tag.name} - ${site?.title}`; metaDescription = tag.meta_description || tag.description || metaDescription; } else if (author) { metaTitle = author.meta_title || `${author.name} - ${site?.title}`; metaDescription = author.meta_description || author.bio || metaDescription; } head.push(`<meta name="description" content="${metaDescription}" />`); head.push(`<meta property="og:site_name" content="${site?.title}" />`); head.push(`<meta property="og:type" content="${post ? 'article' : 'website'}" />`); head.push(`<meta property="og:title" content="${metaTitle}" />`); head.push(`<meta property="og:description" content="${metaDescription}" />`); head.push(`<meta property="og:url" content="${canonicalUrl}" />`); if (post?.feature_image || page?.feature_image) { const image = post?.feature_image || page?.feature_image; head.push(`<meta property="og:image" content="${image}" />`); } head.push(`<meta name="twitter:card" content="summary${(post?.feature_image || page?.feature_image) ? '_large_image' : ''}" />`); head.push(`<meta name="twitter:title" content="${metaTitle}" />`); head.push(`<meta name="twitter:description" content="${metaDescription}" />`); head.push(`<meta name="twitter:url" content="${canonicalUrl}" />`); if (site?.twitter) { head.push(`<meta name="twitter:site" content="${site.twitter}" />`); } if (post?.feature_image || page?.feature_image) { const image = post?.feature_image || page?.feature_image; head.push(`<meta name="twitter:image" content="${image}" />`); } if (post) { head.push(`<meta property="article:published_time" content="${post.published_at}" />`); head.push(`<meta property="article:modified_time" content="${post.updated_at}" />`); if (post.tags && post.tags.length > 0) { post.tags.forEach((tag) => { head.push(`<meta property="article:tag" content="${tag.name}" />`); }); } if (post.authors && post.authors.length > 0) { post.authors.forEach((author) => { head.push(`<meta property="article:author" content="${author.name}" />`); }); } } const schema = { '@context': 'https://schema.org', '@type': post ? 'Article' : 'WebSite', publisher: { '@type': 'Organization', name: site?.title, logo: { '@type': 'ImageObject', url: site?.logo || site?.icon, } }, url: canonicalUrl, description: metaDescription, }; if (post) { schema.headline = post.title; schema.datePublished = post.published_at; schema.dateModified = post.updated_at; if (post.authors && post.authors.length > 0) { schema.author = { '@type': 'Person', name: post.authors[0].name, url: site?.url + post.authors[0].url, }; } if (post.feature_image) { schema.image = post.feature_image; } } head.push(`<script type="application/ld+json">${JSON.stringify(schema)}</script>`); head.push(`<meta name="generator" content="Ghost Theme Preview" />`); head.push(`<link rel="alternate" type="application/rss+xml" title="${site?.title}" href="${site?.url}/rss/" />`); if (post?.codeinjection_head) { head.push(post.codeinjection_head); } else if (page?.codeinjection_head) { head.push(page.codeinjection_head); } return new handlebars_1.default.SafeString(head.join('\n ')); } //# sourceMappingURL=ghostHead.js.map