sergeybruhin/page-meta 问题修复 & 功能扩展

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

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

sergeybruhin/page-meta

Composer 安装命令:

composer require sergeybruhin/page-meta

包简介

Laravel Page Meta Package

README 文档

README

Latest Version on Packagist Total Downloads

Basic and simple package to help you generate page meta inside your blade layout.

Installation

You can install the package via composer:

composer require sergeybruhin/page-meta

Head Meta

Generates standard HTML <head> meta tags: title, description, author, keywords, robots directives, and canonical URL.

Controller

$headMeta = PageMeta::headMeta(
    title: 'My Article',
    description: 'Short page description',
);

$headMeta->setTitle('My Article', ' | ')  // appends site name: "My Article | Site Name"
         ->setCanonical(route('blog.show', $post))
         ->setAuthor('Sergey Bruhin')
         ->setKeywords(['laravel', 'php', 'seo'])
         ->noIndex()
         ->noFollow();

Render

@include('page-meta::head-meta')

Template renders when $headMeta is set in the view.

Output

<title>My Article | Site Name</title>
<meta name="description" content="Short page description">
<meta name="author" content="Sergey Bruhin">
<meta name="keywords" content="laravel, php, seo">
<meta name="robots" content="noindex, nofollow">
<link rel="canonical" href="https://example.com/blog/my-article">

Available methods

Method Description
setTitle(string, ?string $separator) Page title. Pass a separator (e.g. ' | ') to append globalSiteName from config.
setDescription(string) Meta description.
setAuthor(string) Meta author.
setCanonical(string) Canonical URL. Only rendered when set.
setKeywords(string|array) Meta keywords.
setRobots(string) Raw robots string, e.g. 'noindex, nofollow'.
noIndex() Adds noindex to robots.
noFollow() Adds nofollow to robots.
noArchive() Adds noarchive to robots.
noSnippet() Adds nosnippet to robots.

Configuration

Publish the config to set your site name:

php artisan vendor:publish --provider="SergeyBruhin\PageMeta\Providers\PageMetaServiceProvider" --tag="config"
// config/page-meta.php
return [
    'globalSiteName' => 'Your Site Name',
];

Open Graph

Controller

$openGraph = PageMeta::openGraphArticle(
    route('home'),
    $page->name,
    $page->description,
    'Your site name',
);

$openGraph->addImage(
    'https://example.com/image/url.png',
    100,
    100,
    Image::TYPE_WEBP
);

$openGraph->addTags([
    'Some tag',
    'And',
    'Another Tag'
]);

$openGraph->addAuthors([
    'https://example.com/author/some-author',
    'https://example.com/author/another',
]);

Render

@include('page-meta::open-graph')

Template renders when $openGraph is set in the view.

Schema.org (JSON-LD)

Unlike Head Meta / Open Graph / Twitter (which render tag-by-tag from a Blade partial), Schema.org nodes are plain data objects that serialize to a nested array via toArray()/JsonSerializable, then get JSON-encoded once as a single <script type="application/ld+json"> tag.

Controller

$organization = PageMeta::schemaOrganization('Your Site', route('home'))
    ->setDescription('Short site description')
    ->setTelephone('+1 555 0100')
    ->setEmail('hello@example.com')
    ->setAddress(
        (new PostalAddress())
            ->setStreetAddress('123 Main St')
            ->setAddressLocality('Springfield')
            ->setAddressCountry('US')
    )
    ->addSameAsMany([
        'https://www.instagram.com/yoursite/',
        'https://www.facebook.com/yoursite/',
    ]);

$website = PageMeta::schemaWebsite('Your Site', route('home'))
    ->setPublisher($organization);

$article = PageMeta::schemaArticle($post->name)
    ->setDescription($post->description)
    ->setImage(new ImageObject($post->cover->url, 1200, 630))
    ->setDatePublished($post->published_at)
    ->setUrl(route('blog.show', $post))
    ->addKeywords($post->tags->pluck('name')->all());

$breadcrumbs = PageMeta::schemaBreadcrumbList($post->breadcrumbs);

$schema = PageMeta::schemaGraph($organization, $website, $article, $breadcrumbs);

schemaGraph() always wraps its nodes in a single {"@context": "https://schema.org", "@graph": [...]} document — even for a single node — so there's one entry point regardless of how many nodes a page needs.

Render

@include('page-meta::schema')

Template renders when $schema is set in the view.

Available types

Factory Type Notes
PageMeta::schemaOrganization(name, url, type = 'Organization') Organization Pass Organization::TYPE_LOCAL_BUSINESS for a LocalBusiness-flavored node.
PageMeta::schemaWebsite(name, url) WebSite setPublisher(Organization).
PageMeta::schemaArticle(headline) Article setImage, setDatePublished/setDateModified, setAuthor(Person), setPublisher(Organization), addKeywords.
PageMeta::schemaBreadcrumbList(array $breadcrumbs = []) BreadcrumbList Accepts [['url' => .., 'name' => ..], ...] directly.

Value objects live under Meta\Schema\Partials: PostalAddress, ImageObject, Person, ListItem.

Every property is stripped from the output when null/empty, so it's safe to build a node from partially-available data.

Testing (Not yet 💁‍♂️)

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email sundaycreative@gmail.com instead of using the issue tracker.

Credits

License

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

sergeybruhin/page-meta 适用场景与选型建议

sergeybruhin/page-meta 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 126 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 01 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 sergeybruhin/page-meta 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 126
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-01-08