Add "General" filter category for filters that apply to multiple fields given by type option. #1124

This commit is contained in:
ccd0 2017-07-14 19:20:53 -07:00
parent 19ecaf7624
commit 9cd449cb61
5 changed files with 23 additions and 5 deletions

View File

@ -11,7 +11,6 @@ Filter =
sfwBoards = BoardConfig.sfwBoards(true).join(',')
for key of Config.filter
@filters[key] = []
for line in Conf[key].split '\n'
continue if line[0] is '#'
@ -75,11 +74,20 @@ Filter =
top = filter.match(/top:(yes|no)/)?[1] or 'yes'
top = top is 'yes' # Turn it into a boolean
@filters[key].push @createFilter regexp, boards, excludes, op, stub, hl, top
# Fields that this filter applies to (for 'general' filters)
if key is 'general'
if (types = filter.match /(?:^|;)\s*type:([^;]*)/)
types = types[1].split(',').filter (x) ->
x of Config.filter and x isnt 'general'
else
types = ['subject', 'name', 'filename', 'comment']
# Only execute filter types that contain valid filters.
unless @filters[key].length
delete @filters[key]
filter = @createFilter regexp, boards, excludes, op, stub, hl, top
if key is 'general'
for type in types
(@filters[type] or= []).push filter
else
(@filters[key] or= []).push filter
return unless Object.keys(@filters).length
Callbacks.Post.push

View File

@ -461,6 +461,8 @@ Settings =
ta.value = item[name]
$.add div, ta
return
filterTypes = Object.keys(Config.filter).filter((x) -> x isnt 'general').map (x, i) ->
<%= html('?{i}{,}<wbr>${x}') %>
$.extend div, <%= readHTML('Filter-guide.html') %>
$('.warning', div).hidden = Conf['Filter']

View File

@ -30,6 +30,11 @@
Highlighted OPs will have their threads put on top of the board index by default.<br>
For example: <code>top:yes;</code> or <code>top:no;</code>.
</li>
<li>
Filters in the "General" section apply to multiple fields, by default <code>subject,name,filename,comment</code>.<br>
The fields can be specified with the <code>type</code> option, separated by commas.<br>
For example: <code>type:@{filterTypes};</code>.
</li>
</ul>
<p>
Note: If you&#039;re using the native catalog rather than <%= meta.name %>&#039;s catalog, <%= meta.name %>&#039;s filters do not apply there.<br>

View File

@ -1,5 +1,6 @@
<select name="filter">
<option value="guide">Guide</option>
<option value="general">General</option>
<option value="postID">Post number</option>
<option value="name">Name</option>
<option value="uniqueID">Unique ID</option>

View File

@ -675,6 +675,8 @@ Config =
]
filter:
general: ''
postID: """
# Highlight dubs on [s4s]:
#/(\\d)\\1$/;highlight;top:no;boards:s4s