Mercurial > prosody-modules
comparison mod_ogp/test.lua @ 4255:38da10e4b593
mod_ogp: Update parsing logic to catch more cases
author | Seve Ferrer <seve@delape.net> |
---|---|
date | Wed, 18 Nov 2020 13:48:07 +0100 |
parents | a4e182d7ff0a |
children |
comparison
equal
deleted
inserted
replaced
4254:a4e182d7ff0a | 4255:38da10e4b593 |
---|---|
1 local html = [[ | 1 local html = [[ |
2 <meta property="og:title" content="Example 1"> | 2 <meta property="og:title" content="Example 1 A"> |
3 <meta property=og:title content="Example 2"> | 3 <meta property=og:title content="Example 2 B"> |
4 <meta property="og:title" content="Example 3" > | 4 <meta property="og:title" content="Example 3 C" > |
5 <meta property="og:title" content="Example 4" /> | 5 <meta property="og:title" content="Example 4 D" /> |
6 <meta property="og:title" content="Example 5"/> | 6 <meta property="og:title" content="Example 5 E"/> |
7 <meta property=og:title content=Example 6/> | 7 <meta property=og:title content=Example 6 F/> |
8 <meta property="og:title" content= "Example 7" /> | 8 <meta property="og:title" content= "Example 7 G" /> |
9 <meta property="og:title" itemprop="image primaryImageOfPage" content="Example 8" /> | 9 <meta property="og:title" itemprop="image primaryImageOfPage" content="Example 8 H" /> |
10 <meta content="Example 9" property="og:title" > | 10 <meta property='og:title' content='Example 9 I' /> |
11 <meta content="Example 10" property="og:title"> | 11 <meta content="Example 10 J" property="og:title" > |
12 <meta content="Example 11" property="og:title"/> | 12 <meta content="Example 11 K" property="og:title"> |
13 <meta content="Example 12" property="og:title" /> | 13 <meta content="Example 12 L" property="og:title"/> |
14 <meta content="Example 13" property=og:title > | 14 <meta content="Example 13 M" property="og:title" /> |
15 <meta content=Example 14 property=og:title > | 15 <meta content="Example 14 N" property=og:title > |
16 <meta content= "Example 15" property="og:title" /> | 16 <meta content=Example 15 O property=og:title > |
17 <meta content="Example 16" itemprop="image primaryImageOfPage" property="og:title" /> | 17 <meta content= "Example 16 P" property="og:title" /> |
18 <meta content="Example 17 Q" itemprop="image primaryImageOfPage" property="og:title" /> | |
19 <meta content= 'Example 18 R' property='og:title' /> | |
18 ]] | 20 ]] |
19 | 21 |
20 | 22 |
21 local ogp_pattern = [[<meta property=["']?(og:.-)["']? content=%s*["']?(.-)["']?%s-/?>]] | |
22 local ogp_pattern2 = [[<meta content=%s*["']?(.-)["']? property=["']?(og:.-)["']?%s-/?>]] | |
23 | 23 |
24 for property, content in html:gmatch(ogp_pattern) do | 24 local meta_pattern = [[<meta (.-)/?>]] |
25 print("Pattern 1|", property, content, "|Pattern 1") | 25 for match in html:gmatch(meta_pattern) do |
26 local property = match:match([[property=%s*["']?(og:.-)["']?%s]]) | |
27 if not property then | |
28 property = match:match([[property=["']?(og:.-)["']$]]) | |
29 end | |
30 | |
31 local content = match:match([[content=%s*["'](.-)["']%s]]) | |
32 if not content then | |
33 content = match:match([[content=["']?(.-)["']$]]) | |
34 end | |
35 if not content then | |
36 content = match:match([[content=(.-) property]]) | |
37 end | |
38 if not content then | |
39 content = match:match([[content=(.-)$]]) | |
40 end | |
41 | |
42 print(property, '\t', content, '\t', match .. "|") | |
26 end | 43 end |
27 print('-------------------------------------------------------------') | |
28 for content, property in html:gmatch(ogp_pattern2) do | |
29 print("Pattern 2|", property, content, "|Pattern 2") | |
30 end |