client: initial og:title and og:image for posts

This commit is contained in:
Ben Klein 2021-07-10 01:46:18 -04:00
parent 1f3c6ca35f
commit 7d90a73b11
2 changed files with 12 additions and 2 deletions

View file

@ -22,7 +22,13 @@ end
-- Add the site name tag -- Add the site name tag
add_meta_tag("og:site_name", server_info.config.name) add_meta_tag("og:site_name", server_info.config.name)
add_meta_tag("og:url", ngx.var.scheme .. "://" .. ngx.var.http_host .. ngx.var.request_uri) 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)
end
local final_response = page_html.body:gsub("{{ generated_head_tags }}", additional_tags) local final_response = page_html.body:gsub("{{ generated_head_tags }}", additional_tags)

View file

@ -25,9 +25,12 @@ http {
server __BACKEND__:6666; server __BACKEND__:6666;
} }
map $request_uri $request_uri_path {
"~^(?P<path>[^?]*)(\?.*)?$" $path;
}
init_by_lua_block { init_by_lua_block {
cjson = require("cjson") cjson = require("cjson")
-- gumbo = require("gumbo")
} }
server { server {
@ -107,6 +110,7 @@ http {
location /_meta_tags_html { location /_meta_tags_html {
internal; internal;
root /var/www; root /var/www;
set $external_host_url "${scheme}://${http_host}";
content_by_lua_file /etc/nginx/metatags.lua; content_by_lua_file /etc/nginx/metatags.lua;
} }