问题
I have developed a page similar to facebook wall which have list of post in Angular (SPA). Every post have unique url to reach exactly to that post. I am new to open graph metatags. I have inserted metatags in head tag.
<meta property="og:url" content="#####"/>
<meta property="og:type" content="website"/>
<meta property="og:title" content="####"/>
<meta property="og:description"
content="######"/>
<meta property="og:image" content="/images/####.png"/>
The meta tags are common for every post, how to assign meta tags for every url (post)?
Thanks in advance!!
回答1:
I have implemented it as per suggested in this blog
I built a non-public, minimal jsp page with all og tags necessary. OG Tags were generated after query database, so they are dynamic.
<!doctype html> <html lang="en"> <head> <sql:query dataSource="jdbc/localMysql" var="result"> ---- Query ------- </sql:query> <c:forEach var="row" items="${result.rows}"> <meta property="og:type" content="website" /> <meta name= "twitter:card" content="summary" /> <meta name= "twitter:site" content="@#####" /> <meta property="og:title" content='<c:out value=" ${row.######} "/>' /> <meta name="og:description" content='<c:out value=" ${Jsoup.parse(row.######).text()} "/>' /> <meta name="twitter:card" content='<c:out value=" ${Jsoup.parse(row.######).text()} "/>' /> <c:if test="${not empty row.#####}"> <meta property="og:image" content='/UserImages/<c:out value=" ${fn:trim(row.####)} "/>' /> <meta name= "twitter:card" content="summary_large_image" /> </c:if> </c:forEach> </head> <body> </body> </html>
I have built a crawler detection module using tuckey urlrewrite, if its user I show normal page while if its crawler a non public jsp page is shown.
<rule> <condition name="user-agent" next="or">facebookexternalhit/* </condition> <condition name="user-agent" next="or">Facebot</condition> <condition name="user-agent">Twitterbot/*</condition> <from>/wall/*</from> <set name="postUrl">$1</set> <to>/crawler-index.jsp</to> </rule> <rule> <from>/wall/*</from> <to>/index.jsp</to> </rule>
来源:https://stackoverflow.com/questions/44724048/open-graph-metatags-for-every-url-instead-of-page