diff options
author | pdp8 <pdp8@pdp8.info> | 2023-12-22 17:41:49 +0100 |
---|---|---|
committer | pdp8 <pdp8@pdp8.info> | 2023-12-22 17:41:49 +0100 |
commit | 17fe7f0d25bc99285ddc3dbc153f1f3af9dca335 (patch) | |
tree | a660f2748a73f7e1b521dbf4a72c4f5d9929a5ae | |
parent | 88518c5a4fa4fa9d841bb0d1c8add9fa2234530c (diff) |
create.rb: parse plain text
-rw-r--r-- | client.rb | 26 | ||||
-rw-r--r-- | create.rb | 27 |
2 files changed, 14 insertions, 39 deletions
diff --git a/client.rb b/client.rb index e0a5746..d19c6fc 100644 --- a/client.rb +++ b/client.rb @@ -1,20 +1,4 @@ # client-server -# ['/inbox/object', '/outbox/object'].each do |path| -# get path do -# protected! -# Dir[File.join(path.sub('/', ''), '*', '*.json')].collect { |f| JSON.load_file(f) }.to_json -# end -# end - -# post '/delete' do -# protected! -# params['id'].each do |id| -# file, object = find_object id -# halt 404 unless file and File.exist?(file) -# FileUtils.rm(file) -# end -# 200 -# end post '/follow' do protected! @@ -41,19 +25,9 @@ end post '/announce' do # TODO protected! - # src, object = find_object params['id'] - # object = JSON.load_file(src) - # to = ['https://www.w3.org/ns/activitystreams#Public', FOLLOWERS_URL] - # to << object['attributedTo'] - # create_activity 'Announce', object, to - # src, object = find_object params['id'] - # object = JSON.load_file(src) to = ['https://www.w3.org/ns/activitystreams#Public', FOLLOWERS_URL] to << params['attributedTo'] create_activity 'Announce', params['id'], to - # dest = src.sub('inbox/', 'outbox/') - # FileUtils.mkdir_p File.dirname(dest) - # FileUtils.rm src 200 end diff --git a/create.rb b/create.rb index dc1daab..40bfbb8 100644 --- a/create.rb +++ b/create.rb @@ -1,10 +1,10 @@ TO_REGEXP = /^to:\s+/i +CC_REGEXP = /^cc:\s+/i REPLY_REGEXP = /^inreplyto:\s+/i ATTACH_REGEXP = /^attach:\s+/i URL_REGEXP = %r{\Ahttps?://\S+\Z} MENTION_REGEXP = /\A@\w+@\S+\Z/ HASHTAG_REGEXP = /\A#\w+\Z/ -# COMMENT_REGEXP = /^<!*--/ post '/create' do protected! @@ -19,10 +19,6 @@ post '/create' do request.body.read.each_line do |line| line.chomp! case line - when /^<!--$/ - next - when /^-->$/ - next when TO_REGEXP line.sub(TO_REGEXP, '').split(/\s+/).each do |word| case word @@ -40,14 +36,14 @@ post '/create' do url, description = line.sub(ATTACH_REGEXP, '').split(/\s+/, 2) attachment << { 'type' => 'Document', - 'mediaType' => media_type(url), + 'mediaType' => media_type(url), # TODO: query with curl HEAD 'url' => url, 'name' => description } + when "\n" + "<p>\n" else # create links - # single quotes in html invalidate digest, reason unknown - line.split(/\s+/).each do |word| - word = word.gsub('<p>', '').gsub('</p>', '') + content << line.split(/\s+/).collect do |word| case word when HASHTAG_REGEXP tag_url = File.join('https://social.pdp8.info', 'tags', word.sub('#', '')) @@ -56,6 +52,7 @@ post '/create' do 'href' => tag_url, 'name' => word } + "<a href=\"#{tag_url}\">#{word}</a>" when MENTION_REGEXP actor = actor(word) tag << { @@ -63,9 +60,13 @@ post '/create' do 'href' => actor, 'name' => word } + to << actor + "<a href=\"#{actor}\">#{word}</a>" + else + word end - end - content << line + end.join(' ') + # content << line end end @@ -89,9 +90,9 @@ post '/create' do object['attachment'] = attachment unless attachment.empty? object['tag'] = tag unless tag.empty? # p to - # jj object + jj object - create_activity 'Create', object, to + # create_activity 'Create', object, to 200 end |