定制 log1x/laravel-webfonts 二次开发

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

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

log1x/laravel-webfonts

Composer 安装命令:

composer require log1x/laravel-webfonts

包简介

Download, install, and preload over 1500 Google fonts locally in your Laravel project

README 文档

README

Latest Stable Version Total Downloads Build Status

Laravel Webfonts allows you to easily download, install, and preload over 1500 Google fonts locally in your Laravel project.

Demo

Features

  • 🔍️ Search and install over 1500 Google fonts from the public google-webfonts-helper API.
  • ⚡️ Automatically generate @font-face CSS at-rules when installing fonts using CLI.
  • 🧑‍💻 Supports Vite out of the box with zero configuration.
  • ⚡️ Provides an easy-to-use @preloadFonts Blade directive to preload fonts found in the Vite manifest.
  • 🚀 Automatically injects font preload markup into wp_head on WordPress sites running Acorn.

Requirements

Installation

Install via Composer:

$ composer require log1x/laravel-webfonts

Usage

If you already have fonts locally installed in your project, skip to Preloading Fonts.

Adding Fonts

Laravel Webfonts provides a very easy way to install new webfonts to your project using command line:

artisan webfonts:add

By default, installing a font will trigger the following things to happen:

  • Download the font archive to a temporary directory in local storage.
  • Extract the font archive.
  • Move downloaded fonts to resources/fonts.
  • Clean up the temporary directory.
  • Generate and prepend @font-face at-rules to a fonts stylesheet.

The fonts stylesheet will reside at the root of your stylesheet directory located in resources/. If the font stylesheet does not already exist, it will be created using the most common stylesheet extension (css, scss, ...) found among your styles.

By default, the resources/css and resources/styles directories are automatically scanned for existing files to find the appropriate place to write the fonts stylesheet.

The generated @font-face at-rules will look like this:

@font-face {
  font-display: swap;
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 400;
  src: url('../fonts/roboto-v30-latin-regular.woff2') format('woff2');
}

@font-face {
  font-display: swap;
  font-family: 'Roboto';
  font-style: italic;
  font-weight: 400;
  src: url('../fonts/roboto-v30-latin-italic.woff2') format('woff2');
}

Adding additional fonts will cause them to be prepended to the existing fonts stylesheet.

Importing Fonts

When fonts are installed for the first time, a fonts stylesheet is created in your project's stylesheet folder. In a vanilla Laravel project, this is typically resources/css/fonts.css.

You must import the generated fonts file into your project's primary stylesheet (e.g. app.css). If you're using Tailwind, it would look something like:

@import 'fonts';

@tailwind base;
@tailwind components;
@tailwind utilities;

Preloading Fonts

Note

If you are using WordPress alongside Acorn, you can ignore this section as preloading is automatically handled for you inside of wp_head if an asset manifest containing valid fonts is detected.

Laravel Webfonts primary functionality while in production is to provide a simple way to preload your locally hosted webfonts.

This is done by reading the compiled woff2 fonts from your Vite manifest and generating the appropriate markup for you to place inside of <head>.

In most cases, you can simply use the @preloadFonts Blade directive to handle building and echoing the font preload HTML markup.

Alternatively to the Blade directive, you can access the PreloadFonts class directly using the Webfonts Facade:

use Log1x\LaravelWebfonts\Facades\Webfonts;

// Retrieve an array of compiled font paths.
$fonts = Webfonts::fonts();

// Build the font preload HTML markup.
$html = Webfonts::preload()->build();

Allowing/excluding certain fonts from being preloaded can be done inside register() of a service provider:

use Log1x\LaravelWebfonts\Webfonts;

// Allow specific fonts.
Webfonts::only(['inter-v13-latin-regular']);

// Exclude specific fonts.
Webfonts::except(['inter-v13-latin-500']);

Bug Reports

If you discover a bug in Laravel Webfonts, please open an issue.

Contributing

Contributing whether it be through PRs, reporting an issue, or suggesting an idea is encouraged and appreciated.

License

Laravel Webfonts is provided under the MIT License.

log1x/laravel-webfonts 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 141
  • Watchers: 2
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-01-18