Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nginx / Lua based approach to Open Graph tags #422

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
client: og-tags fix for restricted posts
  • Loading branch information
robobenklein committed Jul 10, 2021
commit 38080611d5f52637835f1a8c9990b19ccce23cf4
9 changes: 7 additions & 2 deletions client/metatags.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ add_meta_tag("og:url", ngx.var.external_host_url .. ngx.var.request_uri)

if ngx.var.request_uri_path:match('^/post') then
local post_info = cjson.decode((ngx.location.capture("/_internal_api"..ngx.var.request_uri_path)).body)
add_meta_tag("og:image", ngx.var.external_host_url .. '/' .. post_info.contentUrl)
add_meta_tag("og:title", server_info.config.name .. " - Post " .. post_info.id)
-- If no permission to access, fields will be nil, thus cannot be concat'd
if post_info.contentUrl then
add_meta_tag("og:image", ngx.var.external_host_url .. '/' .. post_info.contentUrl)
end
if post_info.id then
add_meta_tag("og:title", server_info.config.name .. " - Post " .. post_info.id)
end
end

local final_response = page_html.body:gsub("{{ generated_head_tags }}", additional_tags)
Expand Down