Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: it replaces most relevant post content when searching #14

Merged
merged 1 commit into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 4
[*.{js,ts,jsx,tsx,yml}]
indent_size = 2
[*.md]
indent_size = 2
trim_trailing_whitespace = false
4 changes: 3 additions & 1 deletion extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
->default('ianm-synopsis.excerpt_length', 200)
->default('ianm-synopsis.rich-excerpts', false)
->default('ianm-synopsis.excerpt-type', 'first')
->default('ianm-synopsis.disable-when-searching', true)
->serializeToForum('synopsis.excerpt_length', 'ianm-synopsis.excerpt_length', 'intVal')
->serializeToForum('synopsis.rich_excerpts', 'ianm-synopsis.rich-excerpts', 'boolVal')
->serializeToForum('synopsis.excerpt_type', 'ianm-synopsis.excerpt-type'),
->serializeToForum('synopsis.excerpt_type', 'ianm-synopsis.excerpt-type')
->serializeToForum('synopsis.disable_when_searching', 'ianm-synopsis.disable-when-searching', 'boolval'),

(new Extend\ApiController(ListDiscussionsController::class))
->prepareDataForSerialization(LoadRelations::class),
Expand Down
6 changes: 6 additions & 0 deletions js/src/admin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ app.initializers.add('ianm-synopsis', () => {
setting: 'ianm-synopsis.excerpt-type',
options: typeOptions(),
type: 'select',
})
.registerSetting({
label: app.translator.trans('ianm-synopsis.admin.settings.disable-when-searching.label'),
help: app.translator.trans('ianm-synopsis.admin.settings.disable-when-searching.help'),
setting: 'ianm-synopsis.disable-when-searching',
type: 'switch',
});

extendEditTagModal();
Expand Down
4 changes: 4 additions & 0 deletions js/src/forum/addSummaryExcerpt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export default function addSummaryExcerpt() {
});

extend(DiscussionListItem.prototype, 'infoItems', function (items: ItemList) {
// Skip if we are searching to preserve most relevant post content as excerpt,
// that way we also preserve highlighting of search terms in the most relevant post.
if (app.forum.attribute('synopsis.disable_when_searching') && app.discussions.params.q) return;

const discussion = this.attrs.discussion;

if (app.session.user && !app.session.user.preferences().showSynopsisExcerpts) {
Expand Down
5 changes: 4 additions & 1 deletion resources/locale/en.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
ianm-synopsis:
admin:
settings:
disable-when-searching:
label: Disable synopsis when searching
help: When enabled, the default most relevant post excerpt will be used instead of the synopsis
excerpt-length:
label: Summary excerpt length in characters
help: How many characters should be displayed from the post.
rich-excerpts:
label: Display excerpts using rich content
help: When enabled, images, embeds and other non text elements may be included in the synopsis
excerpt-type:
excerpt-type:
label: Which post should be displayed as the excerpt?
help: Select if the first or last post be used for synopsis content
first-label: First post
Expand Down