我用的是原版的flarum 想要 http://discuss.flarum.org.cn/d/325/ 的效果(本论坛) 而不是 https://discuss.flarum.org/d/377-url-parameters/ (原版论坛) 如何操作?
伪静态设置
Cosmo 伪静态还能改网页内容?
Golden 报错了,bate12版本
routes.js:39 Uncaught TypeError: Cannot read property 'trim' of undefined at Function.t.route.discussion (routes.js:39) at e.n.view (DiscussionListItem.js:110) at e.render (Component.js:102) at Object.o [as view] (Component.js:189) at M (mithril.js:806) at mithril.js:822 at A (mithril.js:847) at I (mithril.js:1000) at D (mithril.js:630) at I (mithril.js:989) t.route.discussion @ color-thief.min.js:18 n.view @ color-thief.min.js:18 e.render @ forum-ac3c5341.js:1 o @ forum-ac3c5341.js:1 M @ forum-ac3c5341.js:1 (anonymous) @ forum-ac3c5341.js:1 A @ forum-ac3c5341.js:1 I @ forum-ac3c5341.js:1 D @ forum-ac3c5341.js:1 I @ forum-ac3c5341.js:1 (anonymous) @ forum-ac3c5341.js:1 A @ forum-ac3c5341.js:1 I @ forum-ac3c5341.js:1 D @ forum-ac3c5341.js:1 I @ forum-ac3c5341.js:1 (anonymous) @ forum-ac3c5341.js:1 A @ forum-ac3c5341.js:1 I @ forum-ac3c5341.js:1 D @ forum-ac3c5341.js:1 I @ forum-ac3c5341.js:1 (anonymous) @ forum-ac3c5341.js:1 A @ forum-ac3c5341.js:1 I @ forum-ac3c5341.js:1 D @ forum-ac3c5341.js:1 I @ forum-ac3c5341.js:1 (anonymous) @ forum-ac3c5341.js:1 A @ forum-ac3c5341.js:1 I @ forum-ac3c5341.js:1 D @ forum-ac3c5341.js:1 I @ forum-ac3c5341.js:1 (anonymous) @ forum-ac3c5341.js:1 A @ forum-ac3c5341.js:1 I @ forum-ac3c5341.js:1 D @ forum-ac3c5341.js:1 I @ forum-ac3c5341.js:1 (anonymous) @ forum-ac3c5341.js:1 A @ forum-ac3c5341.js:1 I @ forum-ac3c5341.js:1 D @ forum-ac3c5341.js:1 I @ forum-ac3c5341.js:1 (anonymous) @ forum-ac3c5341.js:1 A @ forum-ac3c5341.js:1 I @ forum-ac3c5341.js:1 g.render @ forum-ac3c5341.js:1 (anonymous) @ forum-ac3c5341.js:1 v @ forum-ac3c5341.js:1 ct @ forum-ac3c5341.js:1 requestAnimationFrame (async) g.redraw @ forum-ac3c5341.js:1 g.endComputation @ forum-ac3c5341.js:1 lt @ forum-ac3c5341.js:1 (anonymous) @ forum-ac3c5341.js:1 g.mount.g.module @ forum-ac3c5341.js:1 (anonymous) @ addBestAnswerNotification.js:4 t.<computed> @ forum-ac3c5341.js:1 n.mount @ color-thief.min.js:18 e.boot @ forum-ac3c5341.js:1 (anonymous) @ task:107
HackerYunen 尴尬,这是没有清理缓存缘故,执行php flarum cache:clear即可。
php flarum cache:clear
Golden 应该还需要:
sed -i -r 's#(discussion->id).*$#\1#' \ vendor/flarum/tags/views/frontend/content/tag.blade.php
现在有更长久、更简单的方法: 先安装 URL 音译插件:URL Transliterator by FriendsOfFlarum 再通过 Flarum 安装目录的 extend.php 中增加 new 一个 extend,最终文件看起来是这样的:
extend.php
<?php return [ (new \FoF\Transliterator\Extend()) ->add('blank', function (string $str) { return ''; }) ];
Golden 谢谢, 已经迁移过来了. 但还是发现了一个小问题: sitemap.xml中的url会多一个-, https://akr-developers.com/sitemap.xml
sitemap.xml
-
而貌似/d/<id>-*都会重定向到/d/<id>, 所以说也没啥实际影响吧.
wloot 看来 sitemap 还是得手动修改
# 阻止 flagrow/sitemap 生成 slug sed -i 's# . '-' . $discussion->slug##' \ vendor/fof/sitemap/src/SitemapGenerator.php sed -i 's# . '-' . $page->slug##' \ vendor/fof/sitemap/src/SitemapGenerator.php
Golden 是fof/split吗, 我没装这插件…
Golden 在这个commit之后已经不适用了, 新版貌似应该修改:
https://github.com/FriendsOfFlarum/sitemap/blob/master/src/Resources/Discussion.php#L20
EDIT: 将这一行修改成
return $this->generateUrl("d/{$model->id}");
亲测有效😋
wloot 发错了。。。23333,我改一下
wloot 具体实现方法想请问一下是装composer require fof/transliterator这个插件在修改哪个文件?
yuliuren 安装你提到的这个音译插件。然后在 Flarum 根目录的 extend.php 的 return 中加入以下内容:
(new \FoF\Transliterator\Extend()) ->add('blank', function (string $str) { return ''; })
最后去音译插件的设置,选择最后一个 blank 选项,点击转译以往的主题即可。
Golden 已经成功解决!谢谢
音译插件(URL Transliterator by FriendsOfFlarum)目前并不兼容flarum v1.x版本,并且在2021年6月宣布停止维护了。
介绍一个零配置,能实现id作为slug的插件 - pipecraft/flarum-ext-id-slug 更多内容参考: https://discuss.flarum.org.cn/d/2799