client: og:site_name served via lua content script
This commit is contained in:
parent
b2800ad779
commit
44d28f3f63
4 changed files with 39 additions and 18 deletions
|
@ -18,6 +18,7 @@ COPY docker-start.sh /
|
|||
|
||||
WORKDIR /etc/nginx
|
||||
COPY nginx.conf.docker ./nginx.conf
|
||||
COPY metatags.lua .
|
||||
|
||||
WORKDIR /var/www
|
||||
COPY --from=builder /opt/app/public/ .
|
||||
|
@ -26,7 +27,8 @@ COPY --from=builder /opt/app/public/ .
|
|||
FROM openresty/openresty:alpine-fat as release
|
||||
|
||||
RUN apk --no-cache add dumb-init
|
||||
RUN /usr/local/openresty/luajit/bin/luarocks install gumbo
|
||||
RUN opm get bungle/lua-resty-template
|
||||
# RUN /usr/local/openresty/luajit/bin/luarocks install gumbo
|
||||
COPY --from=approot / /
|
||||
|
||||
CMD ["/docker-start.sh"]
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
<link rel='apple-touch-startup-image' href='img/apple-touch-startup-image-1668x2224.png' media='(min-device-width: 834px) and (max-device-width: 834px) and (-webkit-min-device-pixel-ratio: 2) and (orientation: portrait)'/>
|
||||
<link rel='apple-touch-startup-image' href='img/apple-touch-startup-image-2048x2732.png' media='(min-device-width: 1024px) and (max-device-width: 1024px) and (-webkit-min-device-pixel-ratio: 2) and (orientation: portrait)'/>
|
||||
<link rel='manifest' href='manifest.json'/>
|
||||
{{ generated_head_tags }}
|
||||
</head>
|
||||
<body>
|
||||
<div id='top-navigation-holder'></div>
|
||||
|
|
32
client/metatags.lua
Normal file
32
client/metatags.lua
Normal file
|
@ -0,0 +1,32 @@
|
|||
ngx.req.read_body()
|
||||
|
||||
local page_html = ngx.location.capture("/index.htm")
|
||||
|
||||
ngx.req.set_header("Accept", "application/json")
|
||||
local server_info = cjson.decode((ngx.location.capture("/_internal_api/info")).body)
|
||||
|
||||
-- local document = gumbo.parse(page_html.body)
|
||||
--
|
||||
-- function add_meta_tag (property, content)
|
||||
-- local new_element = document:createElement("meta")
|
||||
-- document.head:appendChild(new_element)
|
||||
-- new_element:setAttribute("property", property)
|
||||
-- new_element:setAttribute("content", content)
|
||||
-- end
|
||||
|
||||
local additional_tags = ""
|
||||
|
||||
local function add_meta_tag (property, content)
|
||||
additional_tags = additional_tags .. "<meta property=\"" .. property .. "\" content=\"" .. content:gsub('"', '\\"') .. "\" />"
|
||||
end
|
||||
|
||||
-- Add the site name tag
|
||||
add_meta_tag("og:site_name", server_info.config.name)
|
||||
|
||||
local final_response = page_html.body:gsub("{{ generated_head_tags }}", additional_tags)
|
||||
|
||||
-- Set the content type back to HTML
|
||||
ngx.header.content_type = 'text/html';
|
||||
|
||||
-- ngx.say(page_html.body)
|
||||
ngx.say(final_response)
|
|
@ -27,7 +27,7 @@ http {
|
|||
|
||||
init_by_lua_block {
|
||||
cjson = require("cjson")
|
||||
gumbo = require("gumbo")
|
||||
-- gumbo = require("gumbo")
|
||||
}
|
||||
|
||||
server {
|
||||
|
@ -81,7 +81,7 @@ http {
|
|||
|
||||
location / {
|
||||
root /var/www;
|
||||
try_files $uri /index.htm;
|
||||
try_files $uri /_og_tags_html;
|
||||
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
|
@ -104,23 +104,9 @@ http {
|
|||
proxy_pass http://backend/$1;
|
||||
}
|
||||
|
||||
location ~ ^/_internal_tag_generator/(.*)$ {
|
||||
content_by_lua_block {
|
||||
ngx.say("")
|
||||
}
|
||||
}
|
||||
location /_og_tags_html {
|
||||
root /var/www;
|
||||
content_by_lua_block {
|
||||
ngx.req.read_body()
|
||||
|
||||
local page_html = ngx.location.capture("/index.htm")
|
||||
ngx.say(page_html.body)
|
||||
|
||||
ngx.req.set_header("Accept", "application/json")
|
||||
local server_info = cjson.decode((ngx.location.capture("/_internal_api/info")).body)
|
||||
ngx.say(server_info.config.name)
|
||||
}
|
||||
content_by_lua_file /etc/nginx/metatags.lua;
|
||||
}
|
||||
|
||||
location @unauthorized {
|
||||
|
|
Loading…
Reference in a new issue