Open Graph Metatags for every URL instead of page

我的未来我决定 提交于 2019-12-13 02:31:07

问题


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

  1. 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>
    
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!