Uploads for admin site settings (#4913)
* Improve OpenGraph tags for about pages * Add thumbnail admin setting * Fix error * Fix upmain
parent
06f26e09b4
commit
9239e4ce4d
Before Width: | Height: | Size: 25 KiB |
After Width: | Height: | Size: 285 KiB |
@ -0,0 +1,44 @@
|
||||
# frozen_string_literal: true
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: site_uploads
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# var :string default(""), not null
|
||||
# file_file_name :string
|
||||
# file_content_type :string
|
||||
# file_file_size :integer
|
||||
# file_updated_at :datetime
|
||||
# meta :json
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
class SiteUpload < ApplicationRecord
|
||||
has_attached_file :file
|
||||
|
||||
validates_attachment_content_type :file, content_type: /\Aimage\/.*\z/
|
||||
validates :var, presence: true, uniqueness: true
|
||||
|
||||
before_save :set_meta
|
||||
after_commit :clear_cache
|
||||
|
||||
def cache_key
|
||||
"site_uploads/#{var}"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_meta
|
||||
tempfile = file.queued_for_write[:original]
|
||||
|
||||
return if tempfile.nil?
|
||||
|
||||
geometry = Paperclip::Geometry.from_file(tempfile)
|
||||
self.meta = { width: geometry.width.to_i, height: geometry.height.to_i }
|
||||
end
|
||||
|
||||
def clear_cache
|
||||
Rails.cache.delete(cache_key)
|
||||
end
|
||||
end
|
@ -0,0 +1,10 @@
|
||||
- thumbnail = @instance_presenter.thumbnail
|
||||
= opengraph 'og:site_name', t('about.hosted_on', domain: site_hostname)
|
||||
= opengraph 'og:url', about_url
|
||||
= opengraph 'og:type', 'website'
|
||||
= opengraph 'og:title', @instance_presenter.site_title
|
||||
= opengraph 'og:description', strip_tags(@instance_presenter.site_description.presence || t('about.about_mastodon_html'))
|
||||
= opengraph 'og:image', full_asset_url(thumbnail&.file&.url || asset_pack_path('preview.jpg', protocol: :request))
|
||||
= opengraph 'og:image:width', thumbnail ? thumbnail.meta['width'] : '1200'
|
||||
= opengraph 'og:image:height', thumbnail ? thumbnail.meta['height'] : '630'
|
||||
= opengraph 'twitter:card', 'summary_large_image'
|
@ -0,0 +1,10 @@
|
||||
class CreateSiteUploads < ActiveRecord::Migration[5.1]
|
||||
def change
|
||||
create_table :site_uploads do |t|
|
||||
t.string :var, default: '', null: false, index: { unique: true }
|
||||
t.attachment :file
|
||||
t.json :meta
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,3 @@
|
||||
Fabricator(:site_upload) do
|
||||
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe SiteUpload, type: :model do
|
||||
|
||||
end
|
Loading…
Reference in new issue