noticesys 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/noticesys.rb +255 -237
- data.tar.gz.sig +0 -0
- metadata +22 -22
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58a4c42c774e63c23276788b4e76d921aba7ee42cde31030d01679166b98d84b
|
4
|
+
data.tar.gz: 68fcc003ec9517e60382cbf58a5714c8601f533e970810955b21d0b6a80a6d08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a5e520011cbf281b60e6ba103baddda0988119d56cd79eb6156fd47d064e574e9b893ce20f225c5976f24675d6197cf7d49c8e44f91da328f75bd45a89a06f2
|
7
|
+
data.tar.gz: da96c94981cefa92794900c018c530496622b1b4817a3f17a4ea5dee159d25fb6f6d4c7299744a58064938366c4a3d47477c084fa810abc3d7e1a7f287fc0911
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/noticesys.rb
CHANGED
@@ -34,29 +34,29 @@ module NoticeSys
|
|
34
34
|
|
35
35
|
# save the file attachments containing the images etc.
|
36
36
|
|
37
|
-
files = (1..3).map do |n|
|
38
|
-
|
37
|
+
files = (1..3).map do |n|
|
38
|
+
|
39
39
|
f = params['file' + n.to_s]
|
40
|
-
next unless f
|
41
|
-
|
40
|
+
next unless f
|
41
|
+
|
42
42
|
original = f[:tempfile].to_path
|
43
|
-
|
43
|
+
|
44
44
|
scale_img original
|
45
|
-
|
46
|
-
end.compact
|
47
|
-
|
45
|
+
|
46
|
+
end.compact
|
47
|
+
|
48
48
|
msg = params['msg']
|
49
49
|
|
50
50
|
urls = msg.scan(/https:\/\/[^ ]+/)
|
51
|
-
|
51
|
+
|
52
52
|
if urls.any? then
|
53
53
|
|
54
54
|
h2 = OgExtractor.new(urls.last).to_h
|
55
|
-
|
55
|
+
|
56
56
|
puts 'h2: ' + h2.inspect if @debug
|
57
|
-
|
57
|
+
|
58
58
|
if h2 then
|
59
|
-
h = {msg: msg, files: files}
|
59
|
+
h = {msg: msg, files: files}
|
60
60
|
|
61
61
|
h[:site]= h2[:url][/https?:\/\/([^\/]+)/,1].sub(/^www\./,'')
|
62
62
|
|
@@ -64,55 +64,55 @@ module NoticeSys
|
|
64
64
|
tmpfile = Down.download h2[:img]
|
65
65
|
files2 = scale_img tmpfile.to_path
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
h[:files] = files2 || []
|
69
|
-
h[:card] = {h2[:card] => { title: h2[:title], desc: h2[:desc],
|
69
|
+
h[:card] = {h2[:card] => { title: h2[:title], desc: h2[:desc],
|
70
70
|
url: h2[:url]}}
|
71
71
|
h[:msg] = msg.sub(urls.last,'')
|
72
72
|
|
73
73
|
return "notice/%s/json: %s" % [@user, h.to_json]
|
74
|
-
|
74
|
+
|
75
75
|
end
|
76
|
-
|
77
|
-
end
|
78
76
|
|
79
|
-
|
77
|
+
end
|
78
|
+
|
79
|
+
return "notice/%s: %s" % [@user, msg]
|
80
|
+
|
81
|
+
end
|
80
82
|
|
81
|
-
end
|
82
|
-
|
83
83
|
private
|
84
84
|
|
85
|
-
def scale_img(raworiginal)
|
85
|
+
def scale_img(raworiginal)
|
86
86
|
|
87
87
|
original = if raworiginal =~ /\.\w+$/ then
|
88
|
-
|
88
|
+
|
89
89
|
raworiginal
|
90
|
-
|
90
|
+
|
91
91
|
else
|
92
|
-
|
92
|
+
|
93
93
|
neworiginal = raworiginal + '.jpg'
|
94
94
|
FileUtils.mv raworiginal, neworiginal
|
95
95
|
neworiginal
|
96
|
-
|
96
|
+
|
97
97
|
end
|
98
|
-
|
99
|
-
res = %w(240x240 360x360 *518x389 1280x720 2048x1080)
|
98
|
+
|
99
|
+
res = %w(240x240 360x360 *518x389 1280x720 2048x1080)
|
100
100
|
a = @rmagick.resize(original, res)
|
101
101
|
a2 = (a + [nil,nil,nil]).take(res.length)
|
102
102
|
|
103
103
|
oldfile = nil
|
104
104
|
sizes = %w(240x240 360x360 small medium large)
|
105
|
-
|
105
|
+
|
106
106
|
file_sizes = a2.zip(sizes).map.with_index do |x, i|
|
107
107
|
|
108
108
|
f, label = x
|
109
109
|
|
110
|
-
if f then
|
111
|
-
|
110
|
+
if f then
|
111
|
+
|
112
112
|
f2 = f.sub(/_(n\d+x\d+)\.\w+$/) {|x| x.sub($1, label)}
|
113
113
|
|
114
114
|
FileUtils.mv f, f2
|
115
|
-
oldfile = f2
|
115
|
+
oldfile = f2
|
116
116
|
|
117
117
|
elsif oldfile
|
118
118
|
|
@@ -123,12 +123,12 @@ module NoticeSys
|
|
123
123
|
FileUtils.cp oldfile, f2
|
124
124
|
|
125
125
|
end
|
126
|
-
|
127
|
-
|
126
|
+
|
127
|
+
|
128
128
|
f2
|
129
129
|
|
130
|
-
end
|
131
|
-
|
130
|
+
end
|
131
|
+
|
132
132
|
imgfile = original.sub(/\.\w+$/,'2\0')
|
133
133
|
FileUtils.mv original, imgfile
|
134
134
|
|
@@ -136,31 +136,31 @@ module NoticeSys
|
|
136
136
|
|
137
137
|
end
|
138
138
|
|
139
|
-
end
|
140
|
-
|
141
|
-
|
139
|
+
end
|
140
|
+
|
141
|
+
|
142
142
|
class CardView
|
143
|
-
|
143
|
+
|
144
144
|
def initialize(weblet)
|
145
|
-
|
145
|
+
|
146
146
|
@w = weblet
|
147
|
-
|
147
|
+
|
148
148
|
end
|
149
|
-
|
149
|
+
|
150
150
|
def render(dx, rx, card)
|
151
|
-
|
152
|
-
card2 = case card.keys.first
|
151
|
+
|
152
|
+
card2 = case card.keys.first
|
153
153
|
when :images
|
154
|
-
|
154
|
+
|
155
155
|
card[:images].map.with_index do |img, i|
|
156
|
-
|
157
|
-
href = [dx.link.sub(/\/$/,''), rx.topic, 'status', rx.id,
|
156
|
+
|
157
|
+
href = [dx.link.sub(/\/$/,''), rx.topic, 'status', rx.id,
|
158
158
|
'photo', (i+1).to_s ].join('/')
|
159
159
|
url, align = img[:url], img[:align]
|
160
160
|
"<a href='%s'><div class='top-crop %s'><img class='img1' src='%s'/></div></a>" % [href, align, url]
|
161
|
-
|
161
|
+
|
162
162
|
end.join
|
163
|
-
|
163
|
+
|
164
164
|
when :summary_large_image
|
165
165
|
|
166
166
|
h2 = card[:summary_large_image]
|
@@ -171,7 +171,7 @@ module NoticeSys
|
|
171
171
|
site = h2[:url][/https?:\/\/([^\/]+)/,1].sub(/^www\./,'')
|
172
172
|
title = h2[:title]
|
173
173
|
img = h2[:img]
|
174
|
-
url = h2[:url]
|
174
|
+
url = h2[:url]
|
175
175
|
|
176
176
|
@w.render('card', binding)
|
177
177
|
|
@@ -186,45 +186,46 @@ module NoticeSys
|
|
186
186
|
title = h2[:title].length > 46 ? h2[:title][0..46] + '...' : h2[:title]
|
187
187
|
img = h2[:img]
|
188
188
|
url = h2[:url]
|
189
|
-
|
190
|
-
img_element = if img then
|
189
|
+
|
190
|
+
img_element = if img then
|
191
191
|
"<img src='#{img}'>"
|
192
192
|
else
|
193
193
|
@w.render('svg/article')
|
194
194
|
end
|
195
195
|
|
196
|
-
@w.render('card2', binding)
|
197
|
-
|
196
|
+
@w.render('card2', binding)
|
197
|
+
|
198
198
|
end
|
199
|
-
end
|
199
|
+
end
|
200
200
|
end
|
201
|
-
|
201
|
+
|
202
202
|
class StatusView
|
203
|
-
|
203
|
+
include RXFHelperModule
|
204
|
+
|
204
205
|
def initialize(basepath, xslfile, css_url, weblet)
|
205
|
-
|
206
|
+
|
206
207
|
@basepath, @xslfile, @css_url = basepath, xslfile, css_url
|
207
|
-
@w = weblet
|
208
|
+
@w = weblet
|
208
209
|
@card = CardView.new(@w)
|
209
|
-
|
210
|
+
|
210
211
|
end
|
211
|
-
|
212
|
-
def render(topic, rawid, referer)
|
212
|
+
|
213
|
+
def render(topic, rawid, referer)
|
213
214
|
|
214
215
|
id = rawid[0..9].to_i
|
215
|
-
|
216
|
+
|
216
217
|
filepath = File.join(@basepath, 'u', topic)
|
217
218
|
a = [Time.at(id).strftime("%Y/%b/%-d").downcase, rawid]
|
218
219
|
xmlfile = File.join(filepath, "%s/%s/index.xml" % a)
|
219
220
|
xslfile = File.join(@basepath, "/xsl/notices/#{topic}.xsl")
|
220
|
-
|
221
|
+
|
221
222
|
unless File.exists? xslfile then
|
222
223
|
xslfile = @xslfile
|
223
224
|
end
|
224
225
|
|
225
226
|
dx = Dynarex.new(File.join(filepath, 'feed.xml'))
|
226
|
-
doc = Rexle.new(
|
227
|
-
|
227
|
+
doc = Rexle.new(FileX.read(xmlfile))
|
228
|
+
|
228
229
|
doc.root.element('summary/title').text = dx.title
|
229
230
|
e = doc.root.element('summary/image')
|
230
231
|
|
@@ -232,72 +233,72 @@ module NoticeSys
|
|
232
233
|
e = Rexle::Element.new 'image'
|
233
234
|
doc.root.element('summary').add e
|
234
235
|
end
|
235
|
-
|
236
|
+
|
236
237
|
doc.root.element('summary/image').text = dx.image
|
237
|
-
|
238
|
+
|
238
239
|
# remove the card from the description
|
239
240
|
desc = doc.root.element('body/description')
|
240
241
|
desc.xpath('img|div').each(&:delete)
|
241
242
|
|
242
243
|
doc = Nokogiri::XML(doc.root.xml)
|
243
|
-
xslt = Nokogiri::XSLT(
|
244
|
+
xslt = Nokogiri::XSLT(FileX.read(xslfile))
|
244
245
|
|
245
246
|
s = xslt.transform(doc)
|
246
247
|
doc = Rexle.new(s.to_s)
|
247
|
-
|
248
|
-
rx = Kvx.new(xmlfile)
|
248
|
+
|
249
|
+
rx = Kvx.new(xmlfile)
|
249
250
|
|
250
251
|
rawcard = rx.card
|
251
252
|
|
252
253
|
|
253
254
|
card2, meta = if rawcard and rawcard.length > 10 then
|
254
|
-
|
255
|
+
|
255
256
|
card = JSON.parse(rawcard, symbolize_names: true)
|
256
|
-
|
257
|
-
if card.is_a? Hash then
|
258
|
-
|
257
|
+
|
258
|
+
if card.is_a? Hash then
|
259
|
+
|
259
260
|
type = card.keys.first
|
260
261
|
h = card[type]
|
261
262
|
#img = h[:img].sub(/small(?=\.\w+$)/,'large')
|
262
263
|
img = h[:img]
|
263
264
|
metadata = @w.render(:meta, binding)
|
264
265
|
[@card.render(dx, rx, card), metadata]
|
265
|
-
|
266
|
+
|
266
267
|
end
|
267
268
|
else
|
268
269
|
'<span/>'
|
269
270
|
end
|
270
|
-
|
271
|
+
|
271
272
|
|
272
273
|
e = doc.root.at_css '#notice'
|
273
274
|
desc = e.at_css '#desc'
|
274
|
-
desc.add Rexle.new(card2).root
|
275
|
+
desc.add Rexle.new(card2).root
|
275
276
|
|
276
277
|
ref = referer
|
277
278
|
svg = @w.render 'svg/backarrow', binding
|
278
|
-
|
279
|
+
|
279
280
|
back = if ref then
|
280
281
|
"<div id='back'><a href='#{ref}' title='back'>#{svg}</a></div>"
|
281
282
|
else
|
282
|
-
''
|
283
|
+
"<div id='back'><a href='/' title='back'>#{svg}</a></div>"
|
283
284
|
end
|
284
|
-
|
285
|
+
|
285
286
|
@w.render :status, binding
|
286
287
|
|
287
288
|
end
|
288
|
-
|
289
|
+
|
289
290
|
end
|
290
|
-
|
291
|
+
|
291
292
|
class CssView
|
292
|
-
|
293
|
+
|
293
294
|
def initialize(weblet_file)
|
294
|
-
|
295
|
+
|
295
296
|
@weblet_file = weblet_file
|
296
|
-
|
297
|
+
|
297
298
|
end
|
298
|
-
|
299
|
+
|
299
300
|
def noticelist_css()
|
300
|
-
|
301
|
+
|
301
302
|
w = Weblet.new(@weblet_file)
|
302
303
|
|
303
304
|
lines = []
|
@@ -308,72 +309,72 @@ module NoticeSys
|
|
308
309
|
lines << w.render('main/noticelist')
|
309
310
|
lines << w.render('main/footer')
|
310
311
|
lines.join("\n")
|
311
|
-
|
312
|
+
|
312
313
|
end
|
313
|
-
|
314
|
+
|
314
315
|
def notice_css()
|
315
|
-
|
316
|
+
|
316
317
|
w = Weblet.new(@weblet_file)
|
317
318
|
|
318
319
|
lines = []
|
319
320
|
lines << w.render(:status)
|
320
321
|
lines << w.render(:cards)
|
321
322
|
lines.join("\n")
|
322
|
-
|
323
|
-
end
|
324
|
-
|
325
|
-
end
|
326
|
-
|
323
|
+
|
324
|
+
end
|
325
|
+
|
326
|
+
end
|
327
|
+
|
327
328
|
class NoticeView
|
328
|
-
|
329
|
+
|
329
330
|
def render()
|
330
331
|
end
|
331
|
-
|
332
|
+
|
332
333
|
end
|
333
334
|
|
334
|
-
|
335
|
+
|
335
336
|
class StatusListView
|
336
|
-
|
337
|
+
|
337
338
|
def initialize(basepath, css_url, static_urlbase, weblet)
|
338
|
-
|
339
|
+
|
339
340
|
@basepath, @css_url, @static_urlbase = basepath, css_url, static_urlbase
|
340
341
|
@w = weblet
|
341
342
|
@card = CardView.new(@w)
|
342
|
-
|
343
|
+
|
343
344
|
end
|
344
|
-
|
345
|
-
def render(username)
|
345
|
+
|
346
|
+
def render(username)
|
346
347
|
|
347
348
|
s = ''
|
348
|
-
|
349
|
+
|
349
350
|
dx = Dynarex.new(File.join(@basepath, 'u', username, 'feed.xml'))
|
350
|
-
|
351
|
+
|
351
352
|
s += @w.render 'user/ptop', binding
|
352
|
-
|
353
|
+
|
353
354
|
notices = dx.all.map do |rx|
|
354
|
-
|
355
|
+
|
355
356
|
card2 = ''
|
356
|
-
rawcard = rx.to_h[:card]
|
357
|
-
|
357
|
+
rawcard = rx.to_h[:card]
|
358
|
+
|
358
359
|
card2 = if rawcard and rawcard.length > 10 then
|
359
|
-
|
360
|
-
card = JSON.parse(rawcard, symbolize_names: true)
|
361
|
-
|
362
|
-
if card.is_a? Hash then
|
360
|
+
|
361
|
+
card = JSON.parse(rawcard, symbolize_names: true)
|
362
|
+
|
363
|
+
if card.is_a? Hash then
|
363
364
|
@card.render(dx, rx, card)
|
364
365
|
end
|
365
|
-
|
366
|
+
|
366
367
|
else
|
367
368
|
''
|
368
|
-
end
|
369
|
-
|
369
|
+
end
|
370
|
+
|
370
371
|
t2 = Time.at rx.id.to_s[0..9].to_i
|
371
372
|
relative_time = Unichron.new(t2).elapsed
|
372
|
-
|
373
|
+
|
373
374
|
d = t2.strftime("%I:%M%p %b %d %Y")
|
374
|
-
|
375
|
+
|
375
376
|
description = if rx.description.length > 1 then
|
376
|
-
doc = Rexle.new "<node>%s</node>" % rx.description.gsub(/<\/?p>/,'')
|
377
|
+
doc = Rexle.new "<node>%s</node>" % rx.description.gsub(/<\/?p>/,'')
|
377
378
|
doc.root.xpath('img|div').each(&:delete)
|
378
379
|
"<p>%s</p>" % doc.root.xml
|
379
380
|
else
|
@@ -382,39 +383,45 @@ module NoticeSys
|
|
382
383
|
|
383
384
|
utitle, uimage, ubio = dx.title, dx.image, dx.bio
|
384
385
|
@w.render :notice, binding
|
385
|
-
|
386
|
+
|
386
387
|
end
|
387
388
|
|
388
|
-
s += notices.join
|
389
|
-
s += @w.render 'user/rsslink', binding
|
389
|
+
s += notices.join
|
390
|
+
s += @w.render 'user/rsslink', binding
|
390
391
|
@w.render :user, binding
|
391
|
-
|
392
|
+
|
392
393
|
end
|
393
394
|
end
|
394
|
-
|
395
|
+
|
395
396
|
class HashtagQueryView
|
396
|
-
|
397
|
-
def initialize(basepath, css_url, weblet, static_urlbase,
|
398
|
-
|
397
|
+
|
398
|
+
def initialize(basepath, db_basepath, css_url, weblet, static_urlbase,
|
399
|
+
urlbase, debug: false)
|
400
|
+
|
399
401
|
@basepath, @css_url, @static_urlbase = basepath, css_url, static_urlbase
|
400
|
-
@w, @urlbase = weblet, urlbase
|
402
|
+
@db_basepath, @w, @urlbase, @debug = db_basepath, weblet, urlbase, debug
|
401
403
|
@card = CardView.new(@w)
|
402
|
-
|
404
|
+
|
403
405
|
end
|
404
|
-
|
405
|
-
def render(q, referer)
|
406
|
-
#q = args.first
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
406
|
+
|
407
|
+
def render(q, referer)
|
408
|
+
#q = args.first
|
409
|
+
dbindex_path = File.join(@db_basepath, '/hashtag/index.db')
|
410
|
+
puts 'dbindex_path: ' + dbindex_path.inspect if @debug
|
411
|
+
|
412
|
+
db = RecordxSqlite.new(dbindex_path, table: 'hashtags')
|
413
|
+
|
414
|
+
|
411
415
|
a = db.find_all_by_tag q
|
412
416
|
|
413
|
-
topics = a.map(&:topic).uniq.map do |topic|
|
417
|
+
topics = a.map(&:topic).uniq.map do |topic|
|
414
418
|
|
415
419
|
topicpath = File.join(@basepath, 'u', topic)
|
416
|
-
|
417
|
-
|
420
|
+
topic_db_path = File.join(@db_basepath, 'u', topic)
|
421
|
+
|
422
|
+
db_filepath = File.join(topic_db_path, "notices.db")
|
423
|
+
puts 'db_filepath: ' + db_filepath.inspect if @debug
|
424
|
+
db = RecordxSqlite.new(db_filepath, table: 'notices')
|
418
425
|
|
419
426
|
dx = Dynarex.new(File.join(topicpath, 'feed.xml'))
|
420
427
|
[topic, OpenStruct.new(title: dx.title, image: dx.image, db: db)]
|
@@ -427,92 +434,93 @@ module NoticeSys
|
|
427
434
|
r = topics[x.topic]
|
428
435
|
rx = r.db.find x.noticeid
|
429
436
|
link = "%s/%s/status/%s" % [@urlbase, x.topic, x.noticeid]
|
430
|
-
OpenStruct.new(rx.to_h.merge({topic: x.topic, title: r.title,
|
437
|
+
OpenStruct.new(rx.to_h.merge({topic: x.topic, title: r.title,
|
431
438
|
image: r.image, bio: r.bio, link: link}))
|
432
439
|
|
433
440
|
end
|
434
|
-
|
435
|
-
|
441
|
+
|
442
|
+
|
436
443
|
s = ''
|
437
|
-
|
444
|
+
|
438
445
|
notices = rows.sort_by {|x| -(x.id.to_i)}.take(20).map do |rx|
|
439
|
-
|
446
|
+
|
440
447
|
next unless rx.description
|
441
|
-
|
448
|
+
|
442
449
|
card2 = ''
|
443
|
-
rawcard = rx.to_h[:card]
|
444
|
-
|
450
|
+
rawcard = rx.to_h[:card]
|
451
|
+
|
445
452
|
card2 = if rawcard and rawcard.length > 10 then
|
446
|
-
|
447
|
-
card = JSON.parse(rawcard, symbolize_names: true)
|
448
|
-
|
449
|
-
if card.is_a? Hash then
|
453
|
+
|
454
|
+
card = JSON.parse(rawcard, symbolize_names: true)
|
455
|
+
|
456
|
+
if card.is_a? Hash then
|
450
457
|
@card.render(dx, rx, card)
|
451
458
|
end
|
452
|
-
|
459
|
+
|
453
460
|
else
|
454
461
|
''
|
455
|
-
end
|
456
|
-
|
462
|
+
end
|
463
|
+
|
457
464
|
t2 = Time.at rx.id.to_s[0..9].to_i
|
458
465
|
relative_time = Unichron.new(t2).elapsed
|
459
|
-
|
466
|
+
|
460
467
|
d = t2.strftime("%I:%M%p %b %d %Y")
|
461
|
-
|
468
|
+
|
462
469
|
description = if rx.description.length > 1 then
|
463
|
-
doc = Rexle.new "<node>%s</node>" % rx.description.gsub(/<\/?p>/,'')
|
470
|
+
doc = Rexle.new "<node>%s</node>" % rx.description.gsub(/<\/?p>/,'')
|
464
471
|
doc.root.xpath('img|div').each(&:delete)
|
465
472
|
"<p>%s</p>" % doc.root.xml
|
466
473
|
else
|
467
474
|
''
|
468
|
-
end
|
475
|
+
end
|
469
476
|
|
470
477
|
utitle, uimage, ubio = rx.title, rx.image, rx.bio
|
471
478
|
@w.render :notice, binding
|
472
|
-
|
473
|
-
end
|
474
|
-
|
479
|
+
|
480
|
+
end
|
481
|
+
|
475
482
|
s += if notices.any? then
|
476
|
-
notices.compact.join
|
483
|
+
notices.compact.join
|
477
484
|
else
|
478
485
|
"<p>No results for #{q}</p>"
|
479
486
|
end
|
480
|
-
|
487
|
+
|
481
488
|
ref = referer
|
482
|
-
ref = '../' if ref =~ /(?:status|hashtag)\/\d+/
|
483
|
-
|
489
|
+
ref = '../' if ref =~ /(?:status|hashtag)\/\d+/
|
490
|
+
|
484
491
|
svg = @w.render 'svg/backarrow', binding
|
485
492
|
back = ref ? "<a href='#{ref}'>#{svg}</a>" : ''
|
486
|
-
|
493
|
+
|
487
494
|
@w.render :search_pg, binding
|
488
|
-
|
495
|
+
|
489
496
|
end
|
490
|
-
|
491
|
-
|
497
|
+
|
498
|
+
|
492
499
|
end
|
493
|
-
|
500
|
+
|
494
501
|
class SearchQueryView
|
495
|
-
|
496
|
-
def initialize(basepath, css_url, weblet, static_urlbase, urlbase)
|
497
|
-
|
502
|
+
|
503
|
+
def initialize(basepath, db_basepath, css_url, weblet, static_urlbase, urlbase)
|
504
|
+
|
498
505
|
@basepath, @css_url, @static_urlbase = basepath, css_url, static_urlbase
|
499
|
-
@w, @urlbase = weblet, urlbase
|
506
|
+
@db_basepath, @w, @urlbase = db_basepath, weblet, urlbase
|
500
507
|
@card = CardView.new(@w)
|
501
|
-
|
508
|
+
|
502
509
|
end
|
503
|
-
|
504
|
-
def render(q, referer)
|
505
|
-
|
510
|
+
|
511
|
+
def render(q, referer)
|
512
|
+
|
506
513
|
|
507
514
|
users = Dir.glob(File.join(@basepath, 'u', '*')).map do |x|
|
508
515
|
File.basename(x)
|
509
516
|
end
|
510
517
|
|
511
|
-
topics = users.map do |topic|
|
518
|
+
topics = users.map do |topic|
|
512
519
|
|
513
520
|
topicpath = File.join(@basepath, 'u', topic)
|
514
|
-
|
515
|
-
|
521
|
+
topic_db_path = File.join(@db_basepath, 'u', topic)
|
522
|
+
db_filepath = File.join(topic_db_path, "notices.db")
|
523
|
+
db = RecordxSqlite.new(db_filepath, table: 'notices')
|
516
524
|
|
517
525
|
dx = Dynarex.new(File.join(topicpath, 'feed.xml'))
|
518
526
|
[topic, OpenStruct.new(title: dx.title, image: dx.image, bio: dx.bio, db: db)]
|
@@ -522,114 +530,125 @@ module NoticeSys
|
|
522
530
|
#return topics.inspect
|
523
531
|
rows = topics.flat_map do |topic, r|
|
524
532
|
|
525
|
-
a = r.db.all.select {|x| x.description =~ /#{q}/i}
|
533
|
+
a = r.db.all.select {|x| x.description =~ /#{q.gsub('$',"\\$")}/i}
|
526
534
|
a.map do |rx|
|
527
535
|
link = "%s/%s/status/%s" % [@urlbase, topic, rx.noticeid]
|
528
536
|
OpenStruct.new(rx.to_h.merge({topic: topic, title: r.title, image: r.image, link: link}))
|
529
537
|
end
|
530
538
|
|
531
539
|
end
|
532
|
-
|
533
|
-
|
534
|
-
#return rows.inspect
|
540
|
+
|
541
|
+
|
542
|
+
#return rows.inspect
|
535
543
|
s = ''
|
536
|
-
|
544
|
+
|
537
545
|
notices = rows.sort_by {|x| -(x.id.to_i)}.take(20).map do |rx|
|
538
|
-
|
539
|
-
|
546
|
+
|
547
|
+
|
540
548
|
card2 = ''
|
541
|
-
rawcard = rx.to_h[:card]
|
542
|
-
|
549
|
+
rawcard = rx.to_h[:card]
|
550
|
+
|
543
551
|
card2 = if rawcard and rawcard.length > 10 then
|
544
|
-
|
545
|
-
card = JSON.parse(rawcard, symbolize_names: true)
|
546
|
-
|
547
|
-
if card.is_a? Hash then
|
552
|
+
|
553
|
+
card = JSON.parse(rawcard, symbolize_names: true)
|
554
|
+
|
555
|
+
if card.is_a? Hash then
|
548
556
|
@card.render(dx, rx, card)
|
549
557
|
end
|
550
|
-
|
558
|
+
|
551
559
|
else
|
552
560
|
''
|
553
|
-
end
|
554
|
-
|
561
|
+
end
|
562
|
+
|
555
563
|
#rx.description
|
556
564
|
t2 = Time.at rx.id.to_s[0..9].to_i
|
557
565
|
relative_time = Unichron.new(t2).elapsed
|
558
|
-
|
566
|
+
|
559
567
|
d = t2.strftime("%I:%M%p %b %d %Y")
|
560
|
-
|
568
|
+
|
561
569
|
#desc = rx.description.gsub(/<\/?p>/,'').gsub('<','<').gsub('>','>')
|
562
|
-
|
570
|
+
|
563
571
|
topic = rx.topic
|
564
572
|
title, image, bio = %i(title image bio).map do |x|
|
565
573
|
topics[topic].method(x).call
|
566
574
|
end
|
567
|
-
|
575
|
+
|
568
576
|
description = if rx.description.length > 1 then
|
569
|
-
doc = Rexle.new "<node>%s</node>" % rx.description.gsub(/<\/?p>/,'')
|
577
|
+
doc = Rexle.new "<node>%s</node>" % rx.description.gsub(/<\/?p>/,'')
|
570
578
|
doc.root.xpath('img|div').each(&:delete)
|
571
579
|
"<p>%s</p>" % doc.root.xml
|
572
580
|
else
|
573
581
|
''
|
574
|
-
end
|
575
|
-
|
582
|
+
end
|
583
|
+
|
576
584
|
utitle, uimage, ubio = title, image, bio
|
577
585
|
@w.render :notice, binding
|
578
586
|
|
579
587
|
|
580
588
|
end
|
581
589
|
#return notices.inspect
|
582
|
-
|
590
|
+
|
583
591
|
s += if notices.any? then
|
584
|
-
notices.join
|
592
|
+
notices.join
|
585
593
|
else
|
586
594
|
"<p>No results for #{q}</p>"
|
587
595
|
end
|
588
|
-
|
596
|
+
|
589
597
|
#ref = @env["HTTP_REFERER"]
|
590
598
|
ref = referer
|
591
599
|
ref = '../' if ref =~ /(?:status\/\d+|search)/
|
592
600
|
svg = @w.render 'svg/backarrow', binding
|
593
|
-
back = ref ? "<a href='#{ref}'>#{svg}</a>" : ''
|
594
|
-
|
601
|
+
back = ref ? "<a href='#{ref}'>#{svg}</a>" : "<a href='/'>#{svg}</a>"
|
602
|
+
|
595
603
|
@w.render :search_pg, binding
|
596
|
-
|
597
|
-
|
604
|
+
|
605
|
+
|
598
606
|
end
|
599
|
-
|
600
|
-
|
601
|
-
end
|
602
|
-
|
607
|
+
|
608
|
+
|
609
|
+
end
|
610
|
+
|
603
611
|
class Main
|
604
|
-
|
605
|
-
def initialize(basepath, xslfile, statuscss_url,
|
606
|
-
weblet_file, static_urlbase,
|
607
|
-
|
608
|
-
|
612
|
+
|
613
|
+
def initialize(basepath, db_basepath, xslfile, statuscss_url,
|
614
|
+
statuslistcss_url, weblet_file, static_urlbase,
|
615
|
+
urlbase, weblet_cssfile, debug: false)
|
616
|
+
|
617
|
+
weblet_file ||= File.join(File.dirname(__FILE__), '..',
|
618
|
+
'data', 'microblog.txt')
|
619
|
+
|
620
|
+
weblet = Weblet.new(weblet_file)
|
621
|
+
|
609
622
|
@status = StatusView.new(basepath, xslfile, statuscss_url, weblet)
|
610
|
-
|
623
|
+
|
624
|
+
@statuslist = StatusListView.new(basepath, statuslistcss_url,
|
611
625
|
static_urlbase, weblet)
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
static_urlbase, urlbase)
|
616
|
-
|
626
|
+
|
627
|
+
@hashtag = HashtagQueryView.new(basepath, db_basepath,
|
628
|
+
statuslistcss_url, weblet,
|
629
|
+
static_urlbase, urlbase, debug: debug)
|
630
|
+
|
631
|
+
@search = SearchQueryView.new(basepath, db_basepath, statuslistcss_url,
|
632
|
+
weblet, static_urlbase, urlbase)
|
633
|
+
|
634
|
+
weblet_cssfile ||= File.join(File.dirname(__FILE__), '..',
|
635
|
+
'data', 'css.txt')
|
617
636
|
@css = CssView.new(weblet_cssfile)
|
618
|
-
|
637
|
+
|
619
638
|
end
|
620
|
-
|
639
|
+
|
621
640
|
def notice_css()
|
622
641
|
@css.notice_css()
|
623
642
|
end
|
624
|
-
|
643
|
+
|
625
644
|
def noticelist_css()
|
626
645
|
@css.noticelist_css()
|
627
646
|
end
|
628
|
-
|
647
|
+
|
629
648
|
def status(topic, rawid, referer)
|
630
649
|
@status.render topic, rawid, referer
|
631
650
|
end
|
632
|
-
|
651
|
+
|
633
652
|
def status_list(username)
|
634
653
|
@statuslist.render username
|
635
654
|
end
|
@@ -637,13 +656,12 @@ module NoticeSys
|
|
637
656
|
def hashtag_query(s, referer)
|
638
657
|
@hashtag.render s, referer
|
639
658
|
end
|
640
|
-
|
659
|
+
|
641
660
|
def search_query(s, referer)
|
642
661
|
@search.render s, referer
|
643
662
|
end
|
644
663
|
|
645
|
-
|
646
|
-
|
664
|
+
|
647
665
|
end
|
648
|
-
|
649
|
-
end
|
666
|
+
|
667
|
+
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: noticesys
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -35,28 +35,28 @@ cert_chain:
|
|
35
35
|
iGAgDWBQqM/kdjDslqjBGtyWyFyuYHzXMU1gO/P0aE3rh1enqahZ8BqY+gxXLGrR
|
36
36
|
sU+WFV9qPqoqNOG0tOknOZXN
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date:
|
38
|
+
date: 2022-01-15 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: down
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
|
-
- - ">="
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 5.2.0
|
47
44
|
- - "~>"
|
48
45
|
- !ruby/object:Gem::Version
|
49
46
|
version: '5.2'
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 5.2.4
|
50
50
|
type: :runtime
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
|
-
- - ">="
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: 5.2.0
|
57
54
|
- - "~>"
|
58
55
|
- !ruby/object:Gem::Version
|
59
56
|
version: '5.2'
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 5.2.4
|
60
60
|
- !ruby/object:Gem::Dependency
|
61
61
|
name: weblet
|
62
62
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
version: '0.3'
|
67
67
|
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: 0.3.
|
69
|
+
version: 0.3.5
|
70
70
|
type: :runtime
|
71
71
|
prerelease: false
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '0.3'
|
77
77
|
- - ">="
|
78
78
|
- !ruby/object:Gem::Version
|
79
|
-
version: 0.3.
|
79
|
+
version: 0.3.5
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: dynarex
|
82
82
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,22 +101,22 @@ dependencies:
|
|
101
101
|
name: unichron
|
102
102
|
requirement: !ruby/object:Gem::Requirement
|
103
103
|
requirements:
|
104
|
-
- - "~>"
|
105
|
-
- !ruby/object:Gem::Version
|
106
|
-
version: '0.3'
|
107
104
|
- - ">="
|
108
105
|
- !ruby/object:Gem::Version
|
109
|
-
version: 0.
|
106
|
+
version: 0.4.0
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0.4'
|
110
110
|
type: :runtime
|
111
111
|
prerelease: false
|
112
112
|
version_requirements: !ruby/object:Gem::Requirement
|
113
113
|
requirements:
|
114
|
-
- - "~>"
|
115
|
-
- !ruby/object:Gem::Version
|
116
|
-
version: '0.3'
|
117
114
|
- - ">="
|
118
115
|
- !ruby/object:Gem::Version
|
119
|
-
version: 0.
|
116
|
+
version: 0.4.0
|
117
|
+
- - "~>"
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0.4'
|
120
120
|
- !ruby/object:Gem::Dependency
|
121
121
|
name: ogextractor
|
122
122
|
requirement: !ruby/object:Gem::Requirement
|
@@ -126,7 +126,7 @@ dependencies:
|
|
126
126
|
version: '0.1'
|
127
127
|
- - ">="
|
128
128
|
- !ruby/object:Gem::Version
|
129
|
-
version: 0.1.
|
129
|
+
version: 0.1.4
|
130
130
|
type: :runtime
|
131
131
|
prerelease: false
|
132
132
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -136,7 +136,7 @@ dependencies:
|
|
136
136
|
version: '0.1'
|
137
137
|
- - ">="
|
138
138
|
- !ruby/object:Gem::Version
|
139
|
-
version: 0.1.
|
139
|
+
version: 0.1.4
|
140
140
|
- !ruby/object:Gem::Dependency
|
141
141
|
name: recordx_sqlite
|
142
142
|
requirement: !ruby/object:Gem::Requirement
|
@@ -146,7 +146,7 @@ dependencies:
|
|
146
146
|
version: '0.3'
|
147
147
|
- - ">="
|
148
148
|
- !ruby/object:Gem::Version
|
149
|
-
version: 0.3.
|
149
|
+
version: 0.3.3
|
150
150
|
type: :runtime
|
151
151
|
prerelease: false
|
152
152
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -156,7 +156,7 @@ dependencies:
|
|
156
156
|
version: '0.3'
|
157
157
|
- - ">="
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: 0.3.
|
159
|
+
version: 0.3.3
|
160
160
|
description:
|
161
161
|
email: digital.robertson@gmail.com
|
162
162
|
executables: []
|
metadata.gz.sig
CHANGED
Binary file
|