summaryrefslogtreecommitdiffstats
path: root/plugins/meta.lua
blob: 449174d23a26bf2c2a8d38e5bf506328a5d10f4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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)
  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

HTML.delete(description)

timestamps = HTML.select_one(page, "#timestamps")

if timestamps then
  HTML.delete(timestamps)
  target = HTML.select_one(page, "#whoami")
  HTML.insert_after(target, timestamps)
end