teners/laravel-link-preview 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

teners/laravel-link-preview

Composer 安装命令:

composer require teners/laravel-link-preview

包简介

A Laravel package for extracting link previews with customizable parsers, and caching support

README 文档

README

Laravel Link Preview

A powerful and flexible Laravel package for extracting rich link previews with customizable parsers, intelligent caching, and support for Twitter/X, YouTube, and more. - Some use cases

Latest Version on Packagist Issues Stars License Total Downloads

Features

  • Smart Platform Detection - Automatically detects and handles Twitter/X, YouTube, Vimeo, and generic HTML
  • Flexible Caching - Database or Laravel cache system with configurable expiration
  • Highly Configurable - Extensive configuration options for timeouts, redirects, SSL verification
  • Mobile-Optimized - Smart user agent handling for better compatibility
  • Extensible Architecture - Easy to add custom parsers for new platforms
  • Rich Metadata - Extracts titles, descriptions, images, videos, authors, and more
  • Auto-Pruning - Automatic cleanup of expired cached entries

The package automatically detects different platforms and uses specialized parsers:

  • Twitter/X - Enhanced metadata extraction with fallback mechanisms
  • Generic HTML - Open Graph, Twitter Cards, and standard HTML meta tags
  • YouTube/Vimeo - Video-specific metadata (coming soon)

Installation

To install Laravel Link Preview via composer, run the following command in your terminal:

composer require teners/laravel-link-preview

Publish the package configuration file

php artisan vendor:publish --provider="Teners\LaravelLinkPreview\LaravelLinkPreviewServiceProvider" --tag="link-preview-config"

Run migrations to create the cache table (if using model-based caching):

php artisan migrate

Usage

use Teners\LaravelLinkPreview\LinkPreview;

// Get link preview for any URL
$preview = LinkPreview::getPreview('https://example.com');

// Returns an array with extracted metadata
/*
[
    'title' => 'Example Website',
    'description' => 'This is an example website description',
    'cover' => 'https://example.com/image.jpg',
    'author' => 'John Doe',
    'keywords' => 'example, website, demo',
    'icon' => 'https://example.com/favicon.ico',
    'video' => 'https://example.com/video.mp4',
    'video_type' => 'video/mp4'
]
*/

Using the Built-in Route

The package includes a convenient route for AJAX requests:

// GET request to /link-preview?url=https://example.com
fetch('/link-preview?url=' + encodeURIComponent(url))
    .then(response => response.json())
    .then(data => {
        console.log(data); // Link preview data
    });

Configuration

The package provides extensive configuration options in config/link-preview.php:

// Enable/disable caching
'enable_caching' => env('LINK_PREVIEW_ENABLE_CACHING', true),

// Cache duration in seconds (default: 1 week)
'cache_duration' => env('LINK_PREVIEW_CACHE_DURATION', 604800),

// Cache type: 'model' (database) or 'app' (Laravel cache)
'cache_type' => env('LINK_PREVIEW_CACHE_TYPE', 'model'),

// Request timeout
'timeout' => env('LINK_PREVIEW_TIMEOUT', 15),

// Connection timeout
'connect_timeout' => env('LINK_PREVIEW_CONNECT_TIMEOUT', 10),

// Maximum redirects
'max_redirects' => env('LINK_PREVIEW_MAX_REDIRECTS', 5),

// User agent
'user_agent' => env('LINK_PREVIEW_USER_AGENT', 'Teners/LinkPreview v2.0.0 (Compatible Bot)'),

// SSL verification
'verify_ssl' => env('LINK_PREVIEW_VERIFY_SSL', true),

Contributions

Contributions are welcome via Pull Requests on Github.

  • Please document any change you made as neccesary in the README.md.
  • Follow PSR-12 coding standards
  • Write tests for new features
  • Update documentation for any changes
  • Make one pull request per feature/fix
  • Ensure all tests pass

Roadmap Items (Help Wanted!)

  • Add Other Parsers to extrack videos
    • YouTube parser
    • Vimeo parser implementation
  • JavaScript/Puppeteer reader for dynamic content
  • Image size validation and quality checks
  • Global CDN cache option
  • Instagram parser
  • LinkedIn parser

Issues

Please report any issue you encounter in using the package through the Github Issues tab.

When reporting issues, please include:

  • Laravel version
  • PHP version
  • Package version
  • Code example
  • Error messages

Testing

composer test

Credits

Contributors list will be added here

License

The MIT License (MIT). Please see License File for more information.

Made with ❤️ by Teners - if this package helped you ⭐ Star us on GitHub

teners/laravel-link-preview 适用场景与选型建议

teners/laravel-link-preview 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.86k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2024 年 02 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「metadata」 「caching」 「parsing」 「laravel」 「HTML Parser」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 teners/laravel-link-preview 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 teners/laravel-link-preview 我们能提供哪些服务?
定制开发 / 二次开发

基于 teners/laravel-link-preview 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3.86k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-02-10