定制 laravel-freelancer-nl/laravel-index-now 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

laravel-freelancer-nl/laravel-index-now

Composer 安装命令:

composer require laravel-freelancer-nl/laravel-index-now

包简介

Alert search engines of content changes.

README 文档

README

Latest Version on Packagist Code Quality Tests Code Coverage License Total Downloads

This packages provides a wrapper to use the IndexNow api in Laravel. This makes indexing new webpages in (some) search engines easy and fast. It makes for a nice little addition to sitemaps.

IndexNow is an API created by Microsoft Bing & Yandex to allow you to submit page changes to their search engines quickly. A submission to one search engine will automatically pass the submission on to the others.

At the time of this writing Google is considering supporting the API and has announced it will be testing it.

Installation

You can install the package via composer:

composer require laravel-freelancer-nl/laravel-index-now

You can publish the config file with:

php artisan vendor:publish --tag="index-now-config"

This is the contents of the published config file:

return [
    'host' => parse_url((string) env('APP_URL', 'http://localhost'), PHP_URL_HOST) ?? 'localhost',
    'key' => env('INDEXNOW_KEY', ''),
    'key-location' => env('INDEXNOW_KEY_LOCATION', ''),
    'log-failed-submits' => env('INDEXNOW_LOG_FAILED_SUBMITS', true),
    'production-env' => env('INDEXNOW_PRODUCTION_ENV', 'production'),
    'search-engine' => env('INDEXNOW_SEARCH_ENGINE', 'api.indexnow.org'),
    'delay' => env('INDEXNOW_SUBMIT_DELAY', 600),
];
  • host: the hostname for which you will submit pages to the search engine, without scheme or path
  • key: the unique key for this domain (you will generate one in the next step)
  • key-location: the directory and/or prefix to the key file within your public site; the package derives the public keyLocation URL from APP_URL, or falls back to https://<host> when APP_URL is empty
  • log-failed-submits: whether to log skipped submit attempts when the current environment does not match _production-env_
  • production-env: the name of the production environment;
  • search-engine: the domain of the specific search engine you wish to submit too.
  • delay: the delay in seconds for delayed page submissions.

Generate a new key

The IndexNow API matches the request key to a key file within the host domain. To generate the keyfile you use the following artisan command:

php artisan index-now:generate-key

This will create a keyfile in the public_dir() of your project and output the key. Copy the displayed key and place it in your .env file.

If you've set a key location in the config it will be prefixed to the file, and the package will derive the public keyLocation URL from your APP_URL, or fall back to https://<host> when APP_URL is empty.

Running this command multiple times will generate a new key and key file.

Only submit pages for your production environment

You probably don't want to submit pages in any environment other than production.

By default, this package assumes that your production environment is called 'production' and will only submit when it matches the configured name in the package.

In the case of an environment mismatch it will log a submission 'attempt' instead of actually submitting the page to the search engines.

If you use an alternative name for your production environment you can set INDEXNOW_PRODUCTION_ENV in your .env to match.

You can disable this by setting INDEXNOW_PRODUCTION_ENV to false.

If you want to keep the environment check but suppress those log entries, set INDEXNOW_LOG_FAILED_SUBMITS to false.

Usage

You can submit one or more pages per request by calling the facade and passing the url(s) to the submit method.

Note that the urls must be fully qualified without query parameters and without a fragment.

Submit a single page

use LaravelFreelancerNL\LaravelIndexNow\Facades\IndexNow;

IndexNow::submit('https://dejacht.nl/jagen');

Submit a multiple pages

To submit multiple pages at once just add an array of urls.

use LaravelFreelancerNL\LaravelIndexNow\Facades\IndexNow;

IndexNow::submit([
    'https://dejacht.nl',
    'https://dejacht.nl/fotoquiz/',
    'https://dejacht.nl/jagen/',
    'https://dejacht.nl/jachtvideos/',
]);

Prevent spam: delay page submissions

You can delay page submissions by using the delaySubmission method. This dispatches the IndexNowSubmitJob with a delay in seconds as configured. The job is unique by payload, so multiple submissions of the same urls won't push a job to the queue before the current one is handled.

use LaravelFreelancerNL\LaravelIndexNow\Facades\IndexNow;

IndexNow::delaySubmission('https://devechtschool.nl');

You can override the configured default delay by adding your own.

use LaravelFreelancerNL\LaravelIndexNow\Facades\IndexNow;

IndexNow::delaySubmission('https://devechtschool.nl', 100);

When to delay submits

It isn't uncommon for people to make additional edits after creating or updating a page. On these actions it is a good idea to delay the submission.

When deleting pages you can just submit the urls immediately.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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

laravel-freelancer-nl/laravel-index-now 适用场景与选型建议

laravel-freelancer-nl/laravel-index-now 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15.42k 次下载、GitHub Stars 达 52, 最近一次更新时间为 2022 年 06 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 laravel-freelancer-nl/laravel-index-now 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 15.42k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 52
  • 点击次数: 22
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 52
  • Watchers: 1
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-06-16