UNPKG

gpreview

Version:

Preview Ghost themes locally without a full Ghost installation

30 lines 1.19 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.excerptHelper = excerptHelper; const handlebars_1 = __importDefault(require("handlebars")); function excerptHelper(options) { const post = this.post || this; const words = options.hash?.words ? parseInt(String(options.hash.words), 10) : 50; const characters = options.hash?.characters ? parseInt(String(options.hash.characters), 10) : undefined; let excerpt = post.custom_excerpt || post.excerpt || ''; if (!excerpt && post.html) { excerpt = post.html.replace(/<[^>]*>/g, '').trim(); } if (characters) { excerpt = excerpt.slice(0, characters); if (excerpt.length === characters) { excerpt += '...'; } } else { const excerptWords = excerpt.split(/\s+/); if (excerptWords.length > words) { excerpt = excerptWords.slice(0, words).join(' ') + '...'; } } return new handlebars_1.default.SafeString(excerpt); } //# sourceMappingURL=excerpt.js.map