This commit is contained in:
BoHung Chiu 2023-05-14 10:59:17 +08:00
parent cfd1aa85b7
commit 7608bab38f
1 changed files with 2 additions and 2 deletions

View File

@ -6,7 +6,7 @@ class PageContentsController < OrbitAdminController
page = WikiPage.where(:uid => params["wiki"].to_s).first page = WikiPage.where(:uid => params["wiki"].to_s).first
page.view_count += 1 page.view_count += 1
page.save page.save
name = page.title rescue "" name = page.name rescue ""
html = page.content rescue "" html = page.content rescue ""
url_to_edit = OrbitHelper.user_can_edit?(page) ? "/admin/wiki_pages/#{page.id}/edit?page_id=#{page.page.id.to_s}" : "" url_to_edit = OrbitHelper.user_can_edit?(page) ? "/admin/wiki_pages/#{page.id}/edit?page_id=#{page.page.id.to_s}" : ""
else else
@ -19,7 +19,7 @@ class PageContentsController < OrbitAdminController
meta_desc = html.nil? ? "" : ActionView::Base.full_sanitizer.sanitize(html)[0..200] meta_desc = html.nil? ? "" : ActionView::Base.full_sanitizer.sanitize(html)[0..200]
doc = Nokogiri::HTML( html ) doc = Nokogiri::HTML( html )
img_srcs = doc.css('img').map{ |i| i['src'] } img_srcs = doc.css('img').map{ |i| i['src'] }
metas = [{"property" => "og:title", "content" => name},{"property" => "og:site_name", "content" => Site.first.title},{"property" => "og:url", "content" => request.original_url},{"property" => "og:description", "content" => meta_desc},{"property" => "og:type", "content" => "Article"}] metas = [{"property" => "og:description", "content" => meta_desc},{"property" => "og:type", "content" => "Article"}]
if img_srcs.count > 0 if img_srcs.count > 0
metas << {"property" => "og:image", "content" => URI.join(request.base_url, URI.encode(img_srcs[0])).to_s} metas << {"property" => "og:image", "content" => URI.join(request.base_url, URI.encode(img_srcs[0])).to_s}
end end