murdercode / laravel-shortcode-plus
一个允许您使用自定义短代码的包
Requires
- php: ^8.1|^8.2|^8.3
- ext-curl: *
- guzzlehttp/guzzle: ^7.7
- illuminate/contracts: ^9.0|^10.0|^11.0
- spatie/laravel-package-tools: ^1.13.0
- webwizo/laravel-shortcodes: 1.0.*
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
- spatie/laravel-ray: ^1.31
- dev-main
- v5.1.15
- v5.1.14
- v5.1.13
- v5.1.12
- v5.1.11
- v5.1.10
- v5.1.9
- v5.1.8
- v5.1.7
- v5.1.6
- v5.1.5
- v5.1.4
- v5.1.3
- v5.1.2
- v5.1.1
- v5.1.0
- v5.0.12
- v5.0.11
- v5.0.10
- v5.0.9
- v5.0.8
- v5.0.7
- v5.0.6
- v5.0.5
- v5.0.4
- v5.0.3
- v5.0.2
- v5.0.1
- v5.0.0
- v4.2.5
- v4.2.4
- v4.2.3
- v4.2.2
- v4.2.1
- v4.2.0
- v4.1.11
- v4.1.10
- v4.1.9
- v4.1.8
- v4.1.7
- v4.1.6
- v4.1.5
- v4.1.4
- v4.1.3
- v4.1.2
- v4.1.1
- v4.1.0
- v4.0.2
- v4.0.1
- v4.0.0
- v3.0.12
- v3.0.11
- v3.0.10
- v3.0.9
- v3.0.8
- v3.0.7
- v3.0.6
- v3.0.5
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v2.1.8
- v2.1.7
- v2.1.6
- v2.1.5
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.2.5
- v1.2.4
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.0
- v1.0.0
- v0.0.5
- v0.0.4
- v0.0.3
- v0.0.2
- v0.0.1
- dev-dependabot/npm_and_yarn/rollup-3.29.5
- dev-force-url-per-forzare-un-link-in-uscita
- dev-fix-widgetbay-heights
- dev-dependabot/github_actions/dependabot/fetch-metadata-2.2.0
- dev-dependabot/github_actions/amancevice/setup-code-climate-2
- dev-dependabot/github_actions/ramsey/composer-install-3
- dev-61-carosello-immagini-modifica-layout
- dev-54-widgetbay-from-iframe-to-api
- dev-widgetbay-link-widgetbox
- dev-dependabot/github_actions/stefanzweifel/git-auto-commit-action-5
- dev-add-shape-images
- dev-dependabot/github_actions/actions/checkout-4
- dev-36-add-carousel-in-photo
- dev-tmdb-shortcode
- dev-new-asset
This package is auto-updated.
Last update: 2024-09-26 17:32:34 UTC
README
为什么选择 Shortcode+?
此包允许您在应用程序中使用短代码,类似于 WordPress / BBS 风格的网站。
在我们这个时代,短代码是保护我们网站上发布的内容(如博客或论坛)中数据完整性的绝佳方式,而无需每次都重写格式。
使用 Laravel Shortcode+,我们有能力将标准的短代码转变为可以随时间更新的动态资源(新的 HTML 标准、cookie 允许、AMP 版本等)!
警告:这是一个非常有偏见的包,并不打算用于多用途。
工作原理
例如,您可以使用以下短代码嵌入 YouTube 视频
[youtube url="https://www.youtube.com/watch?v=dQw4w9WgXcQ"]
它将呈现为
<iframe src="https://www.youtube-nocookie.com/embed/dQw4w9WgXcQ&autoplay=1" srcdoc="<style>*{padding:0;margin:0;overflow:hidden}html,body{height:100%}img,span{position:absolute;width:100%;top:0;bottom:0;margin:auto}span{height:1.5em;text-align:center;font:48px/1.5 sans-serif;color:white;text-shadow:0 0 0.5em black}</style><a href=https://www.youtube-nocookie.com/embed/dQw4w9WgXcQ?autoplay=1><img style='object-fit:cover;height:100%;' loading='lazy' src=https://img.youtube.com/vi/123456789/hqdefault.jpg alt='dQw4w9WgXcQ' loading=lazy><span>▶</span></a>" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen title="dQw4w9WgXcQ" ></iframe>
如你所见,我们不仅生成 iframe,还使其易于访问、性能优异,并符合最佳 SEO 实践。
安装
您可以通过 composer 安装此包
composer require murdercode/laravel-shortcode-plus
您可以通过发布资产使用短代码 CSS
php artisan vendor:publish --tag="shortcode-plus-assets"
您可以使用以下命令发布和运行迁移
php artisan vendor:publish --tag="shortcode-plus-migrations"
php artisan migrate
您可以使用以下命令发布配置文件
php artisan vendor:publish --tag="shortcode-plus-config"
如果您想每次更新资产时都升级,请将以下内容添加到 composer.json 中
"scripts": { "post-update-cmd": [ "@php artisan vendor:publish --tag=shortcode-plus-assets --ansi --force",
可选地,您可以使用以下命令发布视图
php artisan vendor:publish --tag="shortcode-plus-views"
使用方法
Laravel Shortcode Plus 随带默认的 CSS 和 JS,以提供更好的用户体验。您可以在 resources/css/app.css 中添加 CSS 文件
@import url("/public/vendor/shortcode-plus/app.css");
并在 resources/js/app.js 中添加 JS 文件
import '/public/vendor/shortcode-plus/app2.js';
现在您可以按照以下方式解析源代码
use Murdercode\LaravelShortcodePlus\Facades\LaravelShortcodePlus; $html = "I want to parse this twitter tag: [twitter url=\"https://twitter.com/elonmusk/status/1585841080431321088\"]"; return LaravelShortcodePlus::source($html)->parseAll();
使用 Iubenda Cookie
在您的 iubenda cookie 脚本中添加以下代码:(/organisms/cookie-solution.blade.php)
if (purposeId === "3") { var elements = document.getElementsByClassName('shortcode_nocookie'); for (var i = 0; i < elements.length; i++) { elements[i].style.display = 'none'; } }
索引功能
如果您想使用 [index]
短代码,您可以在解析之前将 withAutoHeadingIds()
方法添加到您的源代码中。它将为您的源代码中的每个标题(h2、h3、h4 等)添加自动 ID
return LaravelShortcodePlus::source($html)->withAutoHeadingIds()->parseAll();
这将为您源代码中的每个标题(h2、h3、h4 等)添加 ID。
解析器
以下是可用的解析器列表
针对 Facebook 的说明
请记住在 </body>
之前调用 SDK
<div id="fb-root"></div> <script async defer crossorigin="anonymous" src="https://#/en_US/sdk.js#xfbml=1&version=v15.0" nonce="UcAjseAO" ></script>
针对 Twitter 的说明
请记住在 </body>
之前调用 SDK
<script type="text/javascript"> window.twttr = (function (d, s, id) { var js, fjs = d.getElementsByTagName(s)[0], t = window.twttr || {}; if (d.getElementById(id)) return t; js = d.createElement(s); js.id = id; js.src = "https://platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs); t._e = []; t.ready = function (f) { t._e.push(f); }; return t; }(document, "script", "twitter-wjs")); </script>
针对 Reddit 的说明
请记住在 </body>
之前调用 SDK
<script async src="https://embed.reddit.com/widgets.js" charset="UTF-8"></script>
针对 Justwatch 的说明
请记住在 </body>
之前调用 SDK
<script async src="https://widget.justwatch.com/justwatch_widget.js" type="text/javascript"></script>
针对 Parse 链接的说明
请记住在配置文件中添加要解析的链接
'linksToParse' => [ 'sponsored' => [ '#https://www\\.amazon\\.[A-Za-z]+#i', '#https://www\\.ebay\\.[A-Za-z]+#i', 'https://www.instant-gaming.com', ], 'dofollow' => [ 'https://forum.tomshw.it/', ], 'nofollow' => [ 'https://www.youtube.com', 'https://multiplayer.it', 'https://www.everyeye.it', ], ],
您可以使用正则表达式或字符串来解析链接。
在解析内容时,您可以使用 forceRel()
$content = LaravelShortcodePlus::source($content) ->forceRel() ->parseAll();
测试
composer test
变更日志
有关最近更改的更多信息,请参阅 CHANGELOG
贡献
有关详细信息,请参阅 CONTRIBUTING
安全漏洞
请参阅 我们的安全策略 了解如何报告安全漏洞。
鸣谢
许可
MIT 许可证(MIT)。有关更多信息,请参阅 许可文件