为每个URL而不是页面打开图形元标记

时间:2017-06-23 14:35:57

标签: angularjs ajax phantomjs single-page-application facebook-opengraph

我开发了类似于facebook墙的页面,其中包含Angular(SPA)中的帖子列表。每个帖子都有唯一的网址,以准确到达该帖子。我是新手打开图形元标记。我在头标签中插入了元标记。

 <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"/>

元标记对于每个帖子都很常见,如何为每个网址分配元标记(帖子)?

提前致谢!!

1 个答案:

答案 0 :(得分:1)

我已根据此blog

中的建议实施了它
  1. 我构建了一个非公开的,最小的jsp页面,其中包含所有必需的og标记。 OG标签是在查询数据库之后生成的,因此它们是动态的。

            <!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. 我已经使用tuckey urlrewrite构建了一个爬虫检测模块,如果其用户我显示正常页面,而它的爬虫是否显示非公共jsp页面。

    <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>