diff options
author | Thomas Letan <lthms@soap.coffee> | 2023-05-20 11:56:53 +0200 |
---|---|---|
committer | Thomas Letan <lthms@soap.coffee> | 2023-05-20 11:56:53 +0200 |
commit | 5017d00a9a87b1e4f577c01d6ddd492ee1e995f3 (patch) | |
tree | b968d989f9478dcca386163a29b5e5dfe4a5cd00 | |
parent | Small rewording in latest retrospective (diff) |
Support Twitter cards and potentially more
-rw-r--r-- | plugins/meta.lua | 60 | ||||
-rw-r--r-- | soupault.toml | 1 | ||||
-rw-r--r-- | templates/main.html | 10 |
3 files changed, 67 insertions, 4 deletions
diff --git a/plugins/meta.lua b/plugins/meta.lua index d16f6b7..449174d 100644 --- a/plugins/meta.lua +++ b/plugins/meta.lua @@ -1,9 +1,63 @@ -description = HTML.select_one(page, "#meta-tags .description") +base_url = config['site_base_url'] .. + soupault_config['widgets']['urls-rewriting']['prefix_url'] + +head = HTML.select_one(page, "head") + +title = HTML.select_one(page, 'h1') +if title then + HTML.append_child( + head, + HTML.parse( + '<meta property="og:title" content="' .. HTML.strip_tags(title) .. '" />' + ) + ) + HTML.append_child( + head, + HTML.parse( + '<meta name="twitter:title" content="' .. HTML.strip_tags(title) .. '" />' + ) + ) +end +HTML.append_child( + head, + HTML.parse( + '<meta property="og:url" content ="' .. base_url .. page_url .. '" />' + ) +) +HTML.append_child( + head, + HTML.parse( + '<meta property="twitter:url" content ="' .. base_url .. page_url .. '" />' + ) +) + +description = HTML.select_one(page, "#meta-tags .description") if description then description_contents = HTML.strip_tags(description) - head = HTML.select_one(page, "head") - HTML.append_child(head, HTML.parse('<meta name="description" content="' .. description_contents .. '">')) + description_contents = Regex.replace_all(description_contents, "\n", " ") + + HTML.append_child( + head, + HTML.parse( + '<meta name="description" content="' + .. description_contents .. '">' + ) + ) + HTML.append_child( + head, + HTML.parse( + '<meta property="og:description" content="' + .. description_contents .. '">' + ) + ) + HTML.append_child( + head, + HTML.parse( + '<meta name="twitter:description" content="' + .. description_contents .. '">' + ) + ) else Log.warning("Missing description in " .. page_file) end diff --git a/soupault.toml b/soupault.toml index d536d4e..9cf3f41 100644 --- a/soupault.toml +++ b/soupault.toml @@ -65,6 +65,7 @@ [widgets.meta] after = "urls-rewriting" widget = "meta" + site_base_url = "https://soap.coffee/" [widgets.move-tags] widget = "move-tags" diff --git a/templates/main.html b/templates/main.html index db272a6..88b935e 100644 --- a/templates/main.html +++ b/templates/main.html @@ -1,4 +1,4 @@ -<html lang="en"> +<html lang="en" prefix="og: https://ogp.me/ns#"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> @@ -6,6 +6,14 @@ <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="author" content="Thomas Letan"> <meta name="twitter:creator" content="@_lthms_" /> + <meta name="twitter:site" content="@_lthms_" /> + <meta property="og:image" content="https://soap.coffee/~lthms/img/thinking.png" /> + <meta property="og:type" content="article" /> + <meta property="og:locale" content="en_US"> + <meta property="og:site_name" content="Thomas Letan’s website"> + <meta property="twitter:domain" content="soap.coffee/~lthms"> + <meta property="twitter:image" content="https://soap.coffee/~lthms/img/thinking.png" /> + <meta name="twitter:card" content="summary"> <link href="https://soap.coffee/+vendor/katex/0.16.4/katex.min.css" rel="stylesheet" media="none" onload="if(media!='all')media='all'"> <link href="/styles/highlight.css" rel="stylesheet"> <link rel="icon" type="image/png" href="/img/thinking.png" /> |