【问题标题】:Open Graph Metatags for every URL instead of page为每个 URL 而不是页面打开 Graph Meta Tags
【发布时间】:2017-11-27 04:30:53
【问题描述】:

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

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

meta标签对每个post都是通用的,如何为每个url(post)分配meta标签?

提前致谢!!

【问题讨论】:

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


    【解决方案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. 我已经使用 tukey 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>
      

    【讨论】:

      猜你喜欢
      • 2011-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-26
      相关资源
      最近更新 更多