view app/helpers/application_helper.rb @ 257:c6a50441a58d

It's now X
author nanaya <me@nanaya.net>
date Sun, 15 Dec 2024 22:48:25 +0900
parents 3ac13a9e593d
children e2150dce4e90
line wrap: on
line source

module ApplicationHelper
  include Twitter::TwitterText::Autolink

  def atom_id(id)
    "tag:rsstweet@nanaya.pro,2014:#{id}"
  end

  def expand_url(text, urls)
    text.gsub /https?:\/\/t\.co\/[A-Za-z0-9]+/ do |url|
      expanded = urls[url]

      case expanded
        when nil then url
        when Hash then expanded[:url]
        else expanded
      end
    end
  end

  def status_url(tweet)
    status_url_base tweet[:user][:username], tweet[:id]
  end

  def status_url_base(username, id)
    "https://x.com/#{username.presence || '_'}/status/#{id}"
  end
end