feat(sticky): make excerpt optional in sticky (#4016)

This commit is contained in:
Chisato Nishikigi 2024-10-22 02:09:48 +08:00 committed by GitHub
parent b86a4a0fe0
commit a0311dfb2b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 25 additions and 9 deletions

View File

@ -31,6 +31,10 @@ return [
new Extend\Locales(__DIR__.'/locale'),
(new Extend\Settings())
->serializeToForum('excerptDisplayEnabled', 'flarum-sticky.enable_display_excerpt', 'boolval')
->default('flarum-sticky.enable_display_excerpt', true),
(new Extend\Model(Discussion::class))
->cast('is_sticky', 'bool'),

View File

@ -15,11 +15,22 @@ export default [
'moderate',
95
)
.setting(() => ({
.setting(
() => ({
setting: 'flarum-sticky.only_sticky_unread_discussions',
name: 'onlyStickyUnreadDiscussions',
type: 'boolean',
label: app.translator.trans('flarum-sticky.admin.settings.only_sticky_unread_discussions_label'),
help: app.translator.trans('flarum-sticky.admin.settings.only_sticky_unread_discussions_help'),
})),
}),
90
)
.setting(
() => ({
type: 'switch',
setting: 'flarum-sticky.enable_display_excerpt',
label: app.translator.trans('flarum-sticky.admin.settings.enable_display_excerpt'),
}),
100
),
];

View File

@ -8,7 +8,7 @@ import { truncate } from 'flarum/common/utils/string';
export default function addStickyExcerpt() {
extend(DiscussionListState.prototype, 'requestParams', function (params) {
if (app.current.matches(IndexPage) || app.current.matches(DiscussionPage)) {
if (app.forum.attribute('excerptDisplayEnabled') && (app.current.matches(IndexPage) || app.current.matches(DiscussionPage))) {
params.include.push('firstPost');
}
});
@ -16,7 +16,7 @@ export default function addStickyExcerpt() {
extend(DiscussionListItem.prototype, 'infoItems', function (items) {
const discussion = this.attrs.discussion;
if (discussion.isSticky() && !this.attrs.params.q && !discussion.lastReadPostNumber()) {
if (app.forum.attribute('excerptDisplayEnabled') && discussion.isSticky() && !this.attrs.params.q && !discussion.lastReadPostNumber()) {
const firstPost = discussion.firstPost();
if (firstPost) {

View File

@ -7,6 +7,7 @@ flarum-sticky:
# Translations in this namespace are used by the admin interface.
admin:
settings:
enable_display_excerpt: Show an excerpt of the first post when a sticky discussion is unread
only_sticky_unread_discussions_label: Only sticky unread discussions
only_sticky_unread_discussions_help: On the All Discussions page, unread sticky discussions pin to the top, while read sticky discussions follow the regular order.