Skip to content

搞英语 → 看世界

翻译英文优质信息和名人推特

Menu
  • 首页
  • 作者列表
  • 独立博客
  • 专业媒体
  • 名人推特
  • 邮件列表
  • 关于本站
Menu

卡比路线和我的网址

Posted on 2023-11-30

如果将博客移回 Kirby,我想确保有效的一件事是 URL。在 Kirby 中,默认情况下这篇文章将列在“/posts/2023/11/kirby-routes-and-my-urls”中,但我希望它是“/2023/11/kirby-routes-and-my-urls” ”。我使用过的所有其他 CMS 都使这变得相对容易做到。在《星之卡比》中,这……没那么容易。

我需要在 Kirby 的 config.php 中添加几条路线,就像这样……

 [ // catch eg 2023/11/my-new-post-slug 'pattern' => '(:num)/(:num)/(:any)', 'action' => function($year, $month, $slug) { $uid = $year . '/' . $month . '/' . $slug; $page = page($uid); if(!$page) $page = page('posts/'. $uid); if(!$page) $page = site()->errorPage(); return site()->visit($page); } ], [ // catch the original url beginning with posts/ 'pattern' => 'posts/(:num)/(:num)/(:any)', 'action' => function($year, $month, $slug) { $uid = $year . '/' . $month . '/' . $slug; go($uid); } ]

这花了我太长时间才弄清楚。在我自己的拼写错误和假设所有内容都在 /blog/slug 而不是 /YYYY/MM/slug 的示例之间,我掉了一些头发。

另一方面,现在我开始理解它了,如果需要的话,我以后就可以做其他奇特的事情了。

另一件困扰我的事情是,即使路由正确处理了其中包含 /posts/… 的链接,我也不想在任何地方看到 /posts/ 。事实证明,通过为帖子创建自定义模型并覆盖默认的 url() 方法也是可行的。我是在论坛中找到Kev Quirk 的论坛帖子后了解到这一点的。我对其进行了调整以适应 /site/models/post.php 中我的 URL 格式:

 public function url($options = null): string { return '/' . $this->date()->toDate('Y/m') . '/' . $this->slug(); }

现在我的 URL 可以按照我想要的方式工作,因此,如果我决定将 baty.net 移回 Kirby,我就已经准备好了。

更新:你正在沉浸其中。

原文: https://baty.net/2023/11/kirby-routes-and-my-urls

本站文章系自动翻译,站长会周期检查,如果有不当内容,请点此留言,非常感谢。
  • Abhinav
  • Abigail Pain
  • Adam Fortuna
  • Alberto Gallego
  • Alex Wlchan
  • Answer.AI
  • Arne Bahlo
  • Ben Carlson
  • Ben Kuhn
  • Bert Hubert
  • Bits about Money
  • Brian Krebs
  • ByteByteGo
  • Chip Huyen
  • Chips and Cheese
  • Christopher Butler
  • Colin Percival
  • Cool Infographics
  • Dan Sinker
  • David Walsh
  • Dmitry Dolzhenko
  • Dustin Curtis
  • eighty twenty
  • Elad Gil
  • Ellie Huxtable
  • Ethan Marcotte
  • Exponential View
  • FAIL Blog
  • Founder Weekly
  • Geoffrey Huntley
  • Geoffrey Litt
  • Greg Mankiw
  • Henrique Dias
  • Hypercritical
  • IEEE Spectrum
  • Investment Talk
  • Jaz
  • Jeff Geerling
  • Jonas Hietala
  • Josh Comeau
  • Lenny Rachitsky
  • Liz Danzico
  • Lou Plummer
  • Luke Wroblewski
  • Matt Baer
  • Matt Stoller
  • Matthias Endler
  • Mert Bulan
  • Mostly metrics
  • News Letter
  • NextDraft
  • Non_Interactive
  • Not Boring
  • One Useful Thing
  • Phil Eaton
  • Product Market Fit
  • Readwise
  • ReedyBear
  • Robert Heaton
  • Rohit Patel
  • Ruben Schade
  • Sage Economics
  • Sam Altman
  • Sam Rose
  • selfh.st
  • Shtetl-Optimized
  • Simon schreibt
  • Slashdot
  • Small Good Things
  • Taylor Troesh
  • Telegram Blog
  • The Macro Compass
  • The Pomp Letter
  • thesephist
  • Thinking Deep & Wide
  • Tim Kellogg
  • Understanding AI
  • 英文媒体
  • 英文推特
  • 英文独立博客
©2025 搞英语 → 看世界 | Design: Newspaperly WordPress Theme