UNPKG

pixel-forge

Version:

A comprehensive generator for social media previews, favicons, and visual assets across all platforms

107 lines (106 loc) 4.33 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.FacebookGenerator = void 0; const path_1 = __importDefault(require("path")); const image_processor_1 = require("../../core/image-processor"); class FacebookGenerator { constructor(sourceImage, config) { this.config = config; this.sourceImage = sourceImage; } /** * Generate Facebook-optimized images */ async generate(options = {}) { const { includeStandard = true, includeSquare = false, title, description, template = 'basic' } = options; if (includeStandard) { await this.generateStandardImage(title, description, template); } if (includeSquare) { await this.generateSquareImage(title, description, template); } } /** * Generate standard Facebook image (1200x630) */ async generateStandardImage(title, description, template) { const processor = new image_processor_1.ImageProcessor(this.sourceImage); const outputPath = path_1.default.join(this.config.output.path, 'facebook-og.png'); const socialFile = await processor.createSocialPreview({ width: image_processor_1.ImageSizes.social.facebook.width, height: image_processor_1.ImageSizes.social.facebook.height, title, description, template, background: this.config.backgroundColor }); const finalProcessor = new image_processor_1.ImageProcessor(socialFile); await finalProcessor.save(outputPath); await processor.cleanup(); } /** * Generate square Facebook image (1200x1200) */ async generateSquareImage(title, description, template) { const processor = new image_processor_1.ImageProcessor(this.sourceImage); const outputPath = path_1.default.join(this.config.output.path, 'facebook-square.png'); const socialFile = await processor.createSocialPreview({ width: image_processor_1.ImageSizes.social.facebookSquare.width, height: image_processor_1.ImageSizes.social.facebookSquare.height, title, description, template, background: this.config.backgroundColor }); const finalProcessor = new image_processor_1.ImageProcessor(socialFile); await finalProcessor.save(outputPath); await processor.cleanup(); } /** * Get HTML meta tags for Facebook */ getMetaTags() { const prefix = this.config.output.prefix || '/'; return [ `<meta property="og:image" content="${prefix}facebook.png">`, `<meta property="og:image:width" content="${image_processor_1.ImageSizes.social.facebook.width}">`, `<meta property="og:image:height" content="${image_processor_1.ImageSizes.social.facebook.height}">`, `<meta property="og:image:type" content="image/png">`, `<meta property="og:title" content="${this.config.appName}">`, `<meta property="og:description" content="${this.config.description || ''}">`, `<meta property="og:type" content="website">`, `<meta property="fb:app_id" content="">`, // Can be configured later ]; } /** * Get Next.js metadata configuration for Facebook */ getNextMetadata() { const prefix = this.config.output.prefix || '/'; return { openGraph: { title: this.config.appName, description: this.config.description, images: [ { url: `${prefix}facebook.png`, width: image_processor_1.ImageSizes.social.facebook.width, height: image_processor_1.ImageSizes.social.facebook.height, alt: this.config.appName, } ], type: 'website', }, }; } /** * Get list of generated files */ getGeneratedFiles() { return ['facebook.png', 'facebook-square.png']; } } exports.FacebookGenerator = FacebookGenerator;