-
Notifications
You must be signed in to change notification settings - Fork 785
/
index.html.erb
376 lines (348 loc) · 15 KB
/
index.html.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
<%# locals: () -%>
<div class="box">
<%= form_with url: '/search', method: :get do |f| %>
<div class="boxline">
<%= f.text_field "q", { :value => @search.q, :size => 40 }.
merge(@search.q.present? ? {} : { :autofocus => "autofocus" }) %>
<input type="submit" value="Search">
</div>
<div class="boxline">
<label class="required">Search:</label>
<%= f.radio_button "what", "stories", :checked => @search.what == :stories %>
<label for="what_stories" class="normal">Stories</label>
<%= f.radio_button "what", "comments", :checked => @search.what == :comments %>
<label for="what_comments" class="normal">Comments</label>
<br>
<label class="required">Order By:</label>
<%= f.radio_button "order", "newest", :checked => @search.order == :newest %>
<label for="order_newest" class="normal">Newest</label>
<%= f.radio_button "order", "relevance", :checked => @search.order == :relevance %>
<label for="order_relevance" class="normal">Relevance</label>
<%= f.radio_button "order", "score", :checked => @search.order == :score %>
<label for="order_score" class="normal">Score</label>
</div>
<% end %>
</div>
<% if @search.results_count > -1 %>
<div class="box searchresults">
<details <%= "open" if @search.results_count == 0 %>>
<summary>
<span class="heading"><%= @search.results_count %> result<%= @search.results_count == 1 ? "" : "s" %> for </span>
<span class="searchq"><%= @search.q %></span>
</summary>
<% if @search.invalid_because %>
<div class="flash-error"><%= @search.invalid_because %></div>
<% end %>
<p>
Search query parsed to:
</p>
<dl class="search_parse">
<%
@search.parse_tree.each do |node|
type, value = node.first
case type
when :commenter %>
<dt><span class="searchq">commenter:<%= value %></span></dt>
<dd>Comment by: <%= link_to value, user_path(value) %></dd>
<% when :domain %>
<dt><span class="searchq">domain:<%= value %></span></dt>
<dd>Domain: <%= link_to value, domain_path(value) %></dd>
<% when :submitter %>
<dt><span class="searchq">submitter:<%= value %></span></dt>
<dd>Story submitted by: <%= link_to value, user_path(value) %></dd>
<% when :tag %>
<dt><span class="searchq">tag:<%= value %></span></dt>
<dd>Tag: <%= link_to value, tag_path(value) %></dd>
<% when :title %>
<dt><span class="searchq">title:<%= @search.flatten_title(value) %></span></dt>
<dd>Title: <%= @search.flatten_title(value) %></dd>
<% when :user %>
<dt><span class="searchq">@<%= value %></span></dt>
<dd><%= @search.searched_model.name %> by: <%= link_to value, user_path(value) %></dd>
<% when :negated %>
<% when :quoted %>
<dt><span class="searchq">"<%= value %>"</span></dt>
<dd>
Quote: <span class="searchq">"<%= @search.strip_operators(value) %>"</span>
<% if !value.to_s.include?(' ') %>
<br>Quoting a single word is redundant, terms are exact.
<% end %>
<% if value.to_s != @search.strip_operators(value) %>
<br>Punctuation that might have been taken as a <a href="https://mariadb.com/kb/ru/full-text-index-overview/#in-boolean-mode">SQL search operator</a> was stripped.
<% end %>
</dd>
<% when :term %>
<dt><span class="searchq"><%= value %></span></dt>
<dd>
Term: <span class="searchq"><%= @search.strip_short_terms(@search.strip_operators(value)) %></span>
<% if value.to_s != @search.strip_operators(value) %>
<br>Punctuation that might have been taken as a <a href="https://mariadb.com/kb/ru/full-text-index-overview/#in-boolean-mode">SQL search operator</a> was stripped.
<% end %>
<% if value.to_s != @search.strip_short_terms(value) %>
<br>1 and 2 character terms are not indexed.
<% if value.to_s.downcase =~ /\b(d\b|go\b|ml\b|c([+][+]|\b)?)/ %>
<% lang = $& %>
<br>For the
<% if value.to_s.downcase =~ /\bgo\b/ %>
terribly-named
<% end %>
language, use <span class="searchq">tag:<%= lang %></span>
<% end %>
<% if value.to_s.downcase =~ /\b(ai|ml)\b/ %>
<br>Use <span class="searchq">tag:ai</span> for artificial intelligence/machine learning
<% end %>
<% end %>
</dd>
<% when :catchall %>
<dt><span class="searchq"><%= value %></span></dt>
<dd>
Catchall: <span class="searchq"><%= @search.strip_operators(value) %></span>
If you were trying to use a search operator, it wasn't recognized.
</dd>
<% end %>
<% end %>
</dl>
</details>
</div>
<% if @search.what == :stories %>
<ol class="stories list">
<% @search.results.each do |story| %>
<%#heinous_inline_partial(stories/_listdetail.html.erb)%>
<%# Do not edit, the content before /heinous_inline_partial comes from the named partial %>
<%# locals: (story:, single_story: false) -%>
<%
# partial inputs:
single_story ||= false
# single_story: at the top of a single story page, eg /s/abc123, this
# controls rendering additional info like list of merged stories, preview,
# users hiding, and flag summary
%>
<%#
The h-entry, u-report-of, u-url and h-card css classes are necessary
for the webmentions support. http://microformats.org/wiki/h-entry
This has apparently useless <span> tags explained in a comment in CSS
around .negative_1 in CSS (introduced same commit as this comment).
%>
<li id="story_<%= story.short_id %>" data-shortid="<%= story.short_id %>"
class="story <%= story.current_upvoted? ? "upvoted" : "" %>
<%= story.current_flagged? ? "flagged" : "" %>
<%= story.score <= -1 ? "negative_1" : "" %>
<%= story.score <= -3 ? "negative_3" : "" %>
<%= story.score <= -5 ? "negative_5" : "" %>
<%= story.is_hidden_by_cur_user ? "hidden" : "" %>
<%= story.is_saved_by_cur_user ? "saved" : "" %>
<%= story.is_deleted? ? "deleted" : "" %>">
<div class="story_liner h-entry">
<div class="voters">
<% if @user %>
<a class="upvoter" title="Add upvote"></a>
<% else %>
<%= link_to "", login_path, :class => "upvoter" %>
<% end %>
<div class="score"><%= story.show_score_to_user?(@user) ? story.score : '~' %></div>
</div>
<div class="details">
<span role="heading" aria-level="1" class="link h-cite u-repost-of">
<% if story.merged_story_id %>
<span class="merge"></span>
<% end %>
<% if story.can_be_seen_by_user?(@user) %>
<a class="u-url" href="<%= story.url_or_comments_path %>" rel="ugc <%= story.send_referrer? ? '' : 'noreferrer' %>"><%= story.title %></a>
<% end %>
<% if story.is_gone? %>
[Story removed by <%= story.is_moderated? ? "moderator" :
"submitter" %>]
<% end %>
</span>
<% if story.markeddown_description.present? %>
<a class="description_present" title="<%= truncate(story.description,
:length => 500) %>" href="<%= story.comments_path %>">☶</a>
<% end %>
<% if story.can_be_seen_by_user?(@user) %>
<span class="tags">
<% story.tags.each do |tag| %>
<%= tag_link(tag) %>
<% end %>
</span>
<% if story.domain.present? %>
<a class="domain" href="<%= domain_path(story.domain) %>"><%= story.domain.domain %></a>
<% end %>
<% if single_story %>
<% story.merged_stories.not_deleted(nil).includes(:domain, :user, :tags).each do |ms| %>
<br>
<span class="merge"></span>
<span class="link">
<a href="<%= ms.url_or_comments_path %>" rel="ugc <%= ms.send_referrer? ? '' : 'noreferrer' %>"%><%= ms.title %></a>
</span>
<span class="tags">
<% ms.tags.each do |tag| %>
<a href="<%= tag_path(tag) %>"
class="<%= tag.css_class %>"
title="<%= tag.description %>"><%= tag.tag %></a>
<% end %>
</span>
<% if ms.domain_id.present? %>
<a class="domain" href="<%= domain_path(ms.domain) %>"><%= ms.domain.domain %></a>
<% end %>
<span class="byline">
<% if (@user && @user.show_avatars?) || !@user %>
<%= link_to avatar_img(ms.user, 16), ms.user %>
<% end %>
<% if ms.user_is_author? %>
<span> authored by </span>
<% else %>
<span> via </span>
<% end %>
<%= styled_user_link ms.user, story, class: ['u-author', 'h-card'] %>
<%= time_ago_in_words_label(ms.created_at) %>
<% if ms.is_editable_by_user?(@user) %>
<span> | </span>
<a href="<%= edit_story_path(ms.short_id) %>">edit</a>
<% end %>
</span>
<% end %>
<% end %>
<% end %>
<% if !single_story && @user && @user.show_story_previews? %>
<% if (sc = story.description_or_story_text(500)).present? %>
<div class="story_content">
<%= sc %>
</div>
<% end %>
<% end %>
<div class="byline">
<% if (@user && @user.show_avatars?) || !@user %>
<%= link_to avatar_img(story.user, 16), story.user %>
<% end %>
<% if story.previewing %>
<% if story.user_is_author? %>
<span> authored by </span>
<% else %>
<span> via </span>
<% end %>
<%= styled_user_link story.user, story, class: ['u-author', 'h-card'] %>
<span> just now </span>
<% else %>
<% if story.user_is_author? %>
<span> authored by </span>
<% else %>
<span> via </span>
<% end %>
<%= styled_user_link story.user, story, class: ['u-author', 'h-card'] %>
<%= time_ago_in_words_label(story.created_at) %>
<% if story.is_editable_by_user?(@user) %>
<span> | </span>
<a href="<%= edit_story_path(story.short_id) %>" class="<%=
story.has_suggestions? ? "story_has_suggestions" : "" %>">edit</a>
<% end %>
<% if story.can_have_suggestions_from_user?(@user) %>
<span> | </span><%= link_to "suggest", story_suggest_path(story.short_id),
:class => "suggester" %>
<% end %>
<% if !story.is_gone? && @user %>
<% if @user && story.current_flagged? %>
<span> | </span><a class="flagger">unflag (<%=
Vote::STORY_REASONS[story.current_vote[:reason]].to_s.downcase %>)</a>
<% elsif @user && @user.can_flag?(story) %>
<span> | </span>
<span class="dropdown_parent">
<a class="flagger">flag</a>
</span>
<% end %>
<% if story.is_hidden_by_cur_user %>
<span> | </span><%= link_to "unhide", story_unhide_path(story.short_id),
:class => "hider" %>
<% else %>
<span> | </span><%= link_to "hide", story_hide_path(story.short_id),
:class => "hider" %>
<% end %>
<% if single_story && story.hider_count > 0 %>
(hidden by <%= pluralize(story.hider_count, "user") %>)
<% end %>
<% if !story.is_saved_by_cur_user %>
<span> | </span><%= link_to "save", story_save_path(story.short_id),
:class => "saver" %>
<% end %>
<% end %>
<% if story.is_saved_by_cur_user %>
<span> | </span><%= link_to "unsave", story_unsave_path(story.short_id),
:class => "saver" %>
<% end %>
<% if story.url.present? %>
<span> | </span>
<span class="dropdown_parent">
<input id="archive_<%= story.short_id %>" class="archive_button" type="checkbox">
<label for="archive_<%= story.short_id %>">archive</label>
<div class="archive-dropdown">
<a href="<%= story.archiveorg_url %>">Archive.org</a>
<a href="<%= story.archivetoday_url %>">Archive.today</a>
<a href="<%= story.ghost_url %>">Ghostarchive</a>
</div>
</span>
<% end %>
<% if !story.is_gone? || @user.try(:is_moderator?) %>
<span class="comments_label">
<span> | </span>
<a role="heading" aria-level="2" href="<%= story.comments_path %>">
<% if story.comments_count == 0 %>
no comments</a>
<% else %>
<%= story.comments_count %> <%= 'comment'.pluralize(story.comments_count) %></a>
<% end %>
</span>
<% end %>
<% if single_story &&
((story.flags > 0 && @user && @user.is_moderator?) ||
(story.flags >= 3 || story.score <= 0)) %>
<span> | <%= story.vote_summary_for(@user).downcase %> </span>
<% end %>
<% end %>
</div>
</div>
</div>
<a href="<%= story.comments_path %>" class="mobile_comments <%= story.comments_count == 0 ? "zero" : "" %>" style="display: none;">
<span><%= story.comments_count %></span>
</a>
</li>
<%#/heinous_inline_partial(stories/_listdetail.html.erb)%>
<% end %>
</ol>
<% elsif @search.what == :comments %>
<ol class="comments comments1">
<% @search.results.each do |res| %>
<li><%= render "comments/comment", :comment => res, :show_story => true %></li>
<% end %>
</ol>
<% end %>
<% if @search.results_count > @search.per_page %>
<div class="page_link_buttons">
Page:
<% page_numbers_for_pagination(@search.page_count, @search.page).each do |p| %>
<% if p.is_a?(Integer) %>
<%= link_to p, search_path(@search.to_param.merge(page: p)), class: (@search.page == p ? 'cur' : '') %>
<% else %>
<span>...</span>
<% end %>
<% end %>
</div>
<% elsif @search.results_count == 1 %>
<div class="page_link_buttons">
<p>Hapax legomenon</p>
</div>
<% end %>
<% else %>
<div class="help">
Search hints:
<ul>
<li>Search terms are required. Use quote marks if you want <span class="searchq">"words together"</span></li>
<li>Terms are exact, so <span class="searchq">code</span> doesn't match <span class="searchq">coder</span> or <span class="searchq">coding</span>. You can approximate stemming with <span class="searchq">cod*</span></li>
<li>Search titles with <span class="searchq">title:kernel</span> or <span class="searchq">title:"linux kernel"</span></li>
<li>Search by domain with <span class="searchq">domain:example.com</span></li>
<li>Search by story submitter with <span class="searchq">submitter:alice</span></li>
<li>Search by <%= link_to 'tag', tags_path %> with <code>tag:meta</span></li>
</ul>
</div>
<% end %>