
- Google AMP 教程
- Google AMP - 首頁
- Google AMP - 概述
- Google AMP - 簡介
- Google AMP - 圖片
- Google AMP - 表單
- Google AMP - 內嵌框架
- Google AMP - 影片
- Google AMP - 按鈕
- Google AMP - Timeago
- Google AMP - Mathml
- Google AMP - 適應文字
- Google AMP - 日期倒計時
- Google AMP - 日期選擇器
- Google AMP - 故事
- Google AMP - 選擇器
- Google AMP - 連結
- Google AMP - 字型
- Google AMP - 列表
- Google AMP - 使用者通知
- Google AMP - 下一頁
- Google AMP - 屬性
- 樣式和自定義 CSS
- Google AMP - 動態 CSS 類
- Google AMP - 操作和事件
- Google AMP - 動畫
- Google AMP - 資料繫結
- Google AMP - 佈局
- Google AMP - 廣告
- Google AMP - 分析
- Google AMP - 社交部件
- Google AMP - 媒體
- HTML 頁面到 AMP 頁面
- Google AMP - 基本語法
- Google AMP - 驗證
- Google AMP - 快取
- Google AMP - 自定義 JavaScript
- Google AMP - CORS
- Google AMP 有用資源
- Google AMP - 快速指南
- Google AMP - 有用資源
- Google AMP - 討論
Google AMP - 社交部件
AMP 提供支援,可以在頁面上顯示社交部件,而無需載入任何外部庫。在本章中,我們將討論此處列出的一些流行的社交部件:
Google AMP - Facebook
Google AMP - Twitter
Google AMP - Pinterest
Google Amp - Facebook
使用 amp-facebook 元件,我們可以連線到 Facebook 並顯示帖子、影片、評論在 AMP 頁面中。
要使用 amp-facebook,我們需要將以下指令碼新增到頁面中:
<script async custom-element = "amp-facebook" src = "https://cdn.ampproject.org/v0/amp-facebook-0.1.js"> </script>
Amp-facebook 標籤格式
<amp-facebook width = "552" height = "310" layout = "responsive" data-href = "https://#/tutorialspointindia/ posts/1784197988358159"> </amp-facebook>
此處顯示了一個 amp-facebook 的工作示例:
示例:顯示來自 Facebook 的帖子
<!doctype html> <html amp lang = "en"> <head> <meta charset = "utf-8"> <script async src = "https://cdn.ampproject.org/v0.js"> </script> <title>Google AMP - Amp Facebook</title> <link rel = "canonical" href = "http://example.ampproject.org/article-metadata.html"> <meta name = "viewport" content = "width = device-width, minimum-scale = 1,initial-scale = 1"> <style amp-boilerplate> body{ -webkit-animation: -amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation: -amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation: -amp-start 8s steps(1,end) 0s 1 normal both;animation: -amp-start 8s steps(1,end) 0s 1 normal both } @-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}} </style> <noscript> <style amp-boilerplate> body{ -webkit-animation:none; -moz-animation:none; -ms-animation:none; animation:none} </style> </noscript> <script async custom-element = "amp-facebook" src = "https://cdn.ampproject.org/v0/amp-facebook-0.1.js"> </script> </head> <body> <h3>Google AMP - Amp Facebook</h3> <h2>Learn Python webscrapping</h2> <amp-facebook width = "552" height = "310" layout = "responsive" data-href = "https://#/tutorialspointindia/posts/1784197988358159"> </amp-facebook> </body> </html>
輸出

示例:顯示來自 Facebook 的影片
<!doctype html> <html amp lang = "en"> <head> <meta charset = "utf-8"> <script async src = "https://cdn.ampproject.org/v0.js"> </script> <title>Google AMP - Amp Facebook>/title> <link rel = "canonical" href = "http://example.ampproject.org/article-metadata.html"> <meta name = "viewport" content = "width = device-width, minimum-scale = 1,initial-scale = 1"> <style amp-boilerplate> body{ -webkit-animation: -amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation: -amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation: -amp-start 8s steps(1,end) 0s 1 normal both;animation: -amp-start 8s steps(1,end) 0s 1 normal both } @-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}} </style> <noscript> <style amp-boilerplate> body{ -webkit-animation:none; -moz-animation:none; -ms-animation:none; animation:none} </style> </noscript> <script async custom-element = "amp-facebook" src = "https://cdn.ampproject.org/v0/amp-facebook-0.1.js"> </script> </head> <body> <h3<Google AMP - Amp Facebook Video</h3> <h2<Learn Python</h2> <amp-facebook width = "476" height = "316" layout = "responsive" data-embed-as = "video" data-href = "https://#/thetutorialkings/videos/701545820223256"> </amp-facebook> </body> </html>
輸出

示例:顯示 Facebook 帖子的評論
<!doctype html> <html amp lang = "en"> <head> <meta charset = "utf-8"> <script async src = "https://cdn.ampproject.org/v0.js"> </script> <title>Google AMP - Amp Facebook</title> <link rel = "canonical" href = "http://example.ampproject.org/article-metadata.html"> <meta name = "viewport" content = "width = device-width, minimum-scale = 1,initial-scale = 1"> <style amp-boilerplate> body{ -webkit-animation: -amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation: -amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation: -amp-start 8s steps(1,end) 0s 1 normal both;animation: -amp-start 8s steps(1,end) 0s 1 normal both } @-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}} </style> <noscript> <style amp-boilerplate> body{ -webkit-animation:none; -moz-animation:none; -ms-animation:none; animation:none} </style> </noscript> <script async custom-element = "amp-facebook" src = "https://cdn.ampproject.org/v0/amp-facebook-0.1.js"> </script> </head> <body> <h3>Google AMP - Amp Facebook comment for post</h3> <h2>Learn Microprocessor</h2> <amp-facebook width = "552" height = "500" layout = "responsive" data-embed-type = "comment" data-href = "https://#/tutorialspointindia/posts/1744145745696717? comment_id=1744179789026646&include_parent=false"> </amp-facebook> </body> </html>
輸出

amp-facebook 上可用的屬性為
data-href(必填) - 在此處,您需要指定 Facebook URL。
data-embed-as - 可用的選項為帖子、影片和評論。預設情況下,它是帖子。
data-locale(必填) - 它以本地語言顯示,您可以根據自己的選擇進行更改。
data-include-comment-parent - 它接受 true 或 false 值。預設情況下為 false。當您將 data-embed-as 選項用作評論時,如果您需要對評論的父回覆,則可以將此選項設定為 true。
到目前為止,我們已經瞭解瞭如何將帖子/影片和評論新增到 AMP 頁面。如果我們需要新增 Facebook 頁面,AMP 有一個名為 amp-facebook-page 的元件。
AMP Facebook 頁面外掛
Amp-facebook-page 元件為我們提供了我們想要的 Facebook 頁面詳細資訊。要使用 amp-facebook-page,我們需要新增以下指令碼:
<script async custom-element = "amp-facebook-page" src = " https://cdn.ampproject.org/v0/amp-facebook-page-0.1.js"> </script>
此處顯示了一個使用 amp-facebook-page 的工作示例:
示例
<!doctype html> <html amp lang = "en"> <head> <meta charset = "utf-8"> <script async src = "https://cdn.ampproject.org/v0.js"> </script> <title>Google AMP - Amp Facebook</title> <link rel = "canonical" href = "http://example.ampproject.org/article-metadata.html"> <meta name = "viewport" content = "width = device-width, minimum-scale = 1,initial-scale = 1"> <style amp-boilerplate> body{ -webkit-animation: -amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation: -amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation: -amp-start 8s steps(1,end) 0s 1 normal both;animation: -amp-start 8s steps(1,end) 0s 1 normal both } @-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}} </style> <noscript> <style amp-boilerplate> body{ -webkit-animation:none; -moz-animation:none; -ms-animation:none; animation:none} </style> </noscript> <script async custom-element = "amp-facebook-page" src = "https://cdn.ampproject.org/v0/amp-facebook-page-0.1.js"> </script> </head> <body> <h3>Google AMP - Amp Facebook Page</h3> <h3>Welcome to Tutorialspoint Facebook Page</h3> <amp-facebook-page width = "340" height = "130" layout = "responsive" data-href = "https://#/tutorialspointindia/"> </amp-facebook-page> </body> </html>
輸出

Amp-facebook-like
要嵌入 Facebook 頁面喜歡按鈕外掛,我們可以使用 amp-facebook-like 元件。要使用 amp-facebook-like,我們需要新增以下指令碼:
"<script async custom-element = "amp-facebook-like" src = "https://cdn.ampproject.org/v0/amp-facebook-like-0.1.js"> </script>
示例
<!doctype html> <html amp lang = "en"> <head> <meta charset = "utf-8"> <script async src = "https://cdn.ampproject.org/v0.js"> </script> <title>Google AMP - Amp Facebook</title> <link rel = "canonical" href = "http://example.ampproject.org/article-metadata.html"> <meta name = "viewport" content = "width = device-width, minimum-scale = 1,initial-scale = 1"> <style amp-boilerplate> body{ -webkit-animation: -amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation: -amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation: -amp-start 8s steps(1,end) 0s 1 normal both;animation: -amp-start 8s steps(1,end) 0s 1 normal both } @-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}} </style> <noscript> <style amp-boilerplate> body{ -webkit-animation:none; -moz-animation:none; -ms-animation:none; animation:none} </style> </noscript> <script async custom-element = "amp-facebook-like" src = "https://cdn.ampproject.org/v0/amp-facebook-like-0.1.js"> </script> <style amp-custom> amp-facebook-like { margin: 1rem } </style> </head> <body> <h3>Google AMP - Amp Facebook Likes</h3> <h3>Welcome to Tutorialspoint Facebook Likes</h3> <amp-facebook-like width = "110" height = "20" layout = "fixed" data-layout = "button_count" data-href = "https://#/tutorialspointindia"> </amp-facebook-like> </body> </html>
輸出

AMP Facebook 評論外掛
Amp-facebook-comments 元件將提供給定頁面的評論。
要使用 amp-facebook-comments,我們需要新增以下指令碼:
<script async custom-element = "amp-facebook-comments" src = "https://cdn.ampproject.org/v0/amp-facebook-comments-0.1.js"> </script>
示例
<!doctype html> <html amp lang = "en"> <head> <meta charset = "utf-8"> <script async src = "https://cdn.ampproject.org/v0.js"> </script> <title>Google AMP - Amp Facebook</title> <link rel = "canonical" href = "http://example.ampproject.org/article-metadata.html"> <meta name = "viewport" content = "width = device-width, minimum-scale = 1,initial-scale = 1"> <style amp-boilerplate> body{ -webkit-animation: -amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation: -amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation: -amp-start 8s steps(1,end) 0s 1 normal both;animation: -amp-start 8s steps(1,end) 0s 1 normal both } @-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}} </style> <noscript> <style amp-boilerplate> body{ -webkit-animation:none; -moz-animation:none; -ms-animation:none; animation:none} </style> </noscript> <script async custom-element = "amp-facebook-comments" src = "https://cdn.ampproject.org/v0/amp-facebook-comments-0.1.js"> </script> <style amp-custom> amp-facebook-like { margin: 1rem } </style> </head> <body> <h3>Google AMP - Amp Facebook Likes</h3> <amp-facebook-comments width = 486 height = 657 layout = "responsive" data-numposts = "2" data-href = "https://developers.facebook.com/docs/plugins/comments"> </amp-facebook-comments> </body> </html>
輸出

屬性 data-numposts 決定螢幕上顯示的評論數量。如果您想獲取所有評論,則可以刪除該屬性。
Google AMP - Pinterest
AMP 使用 amp-pinterest 元件提供 Pinterest 小部件。我們可以使用此元件來顯示 Pinterest 小部件、Pinterest 儲存按鈕和 Pinterest 關注按鈕。
要開始使用 amp-pinterest,我們需要新增以下指令碼:
<script async custom-element="amp-pinterest" src="https://cdn.ampproject.org/v0/amp-pinterest-0.1.js"> </script>
Amp-pinterest 標籤
<amp-pinterest width = 300 height = 450 data-do = "embedPin" data-url = "https://in.pinterest.com/pin/856739529089490354/"> </amp-pinterest>
Pinterest 小部件
示例
要顯示 Pinterest 小部件,我們需要使用屬性 data-do="embedPin"。此處顯示了一個相同的工作示例:
<!doctype html> <html amp lang = "en"> <head> <meta charset = "utf-8"> <script async src = "https://cdn.ampproject.org/v0.js"> </script> <title>Google AMP - Amp Pinterest Widget</title> <link rel = "canonical" href = "http://example.ampproject.org/article-metadata.html"> <meta name = "viewport" content = "width = device-width, minimum-scale = 1,initial-scale = 1"> <style amp-boilerplate> body{ -webkit-animation: -amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation: -amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation: -amp-start 8s steps(1,end) 0s 1 normal both;animation: -amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start 8s steps(1,end) 0s 1 normal both } @-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}} </style> <noscript> <style amp-boilerplate> body{ -webkit-animation:none; -moz-animation:none; -ms-animation:none; animation:none} </style> </noscript> <script async custom-element = "amp-pinterest" src = "https://cdn.ampproject.org/v0/amp-pinterest-0.1.js"> </script> <style amp-custom> amp-facebook-like { margin: 1rem } </style> </head> <body> <h3>Google AMP - Amp Pinterest Widget</h3> <amp-pinterest width = 300 height = 450 data-do = "embedPin" data-url = "https://in.pinterest.com/pin/856739529089490354/"> </amp-pinterest> </body> </html>
輸出

Pinterest 儲存按鈕
要顯示 Pinterest 的儲存按鈕,我們需要使用屬性 data-do="buttonPin"。此處顯示了一個 Pinterest 儲存按鈕的工作示例:
示例
<!doctype html> <html amp lang = "en"> <head> <meta charset = "utf-8"> <script async src = "https://cdn.ampproject.org/v0.js"> </script> <title>Google AMP - Amp Pinterest Widget</title> <link rel = "canonical" href = "http://example.ampproject.org/article-metadata.html"> <meta name = "viewport" content = "width = device-width, minimum-scale = 1,initial-scale = 1"> <style amp-boilerplate> body{ -webkit-animation: -amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation: -amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation: -amp-start 8s steps(1,end) 0s 1 normal both;animation: -amp-start 8s steps(1,end) 0s 1 normal both } @-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}} </style> <noscript> <style amp-boilerplate> body{ -webkit-animation:none; -moz-animation:none; -ms-animation:none; animation:none} </style> </noscript> <script async custom-element = "amp-pinterest" src = "https://cdn.ampproject.org/v0/amp-pinterest-0.1.js"> </script> <style amp-custom> amp-facebook-like { margin: 1rem } </style> </head> <body> <h3>Google AMP - Amp Pinterest Save Button</h3> <h3>TutorialsPoint - ReactJS</h3> <amp-img src = "images/reactjs.png" width = "100" height = "100" alt = "blockchain image"> </amp-img> <amp-pinterest height = "18" width = "56" data-do = "buttonPin" data-url = "https://tutorialspoint.tw/" data-media = "https://tutorialspoint.tw/images/tp-logo-diamond.png" data-description = "amp-pinterest in action"> </amp-pinterest> </body> </html>
輸出

Pinterest 關注按鈕
要顯示 Pinterest 的儲存關注按鈕,我們需要使用屬性 data-do="buttonFollow"。此處顯示了一個 Pinterest 儲存按鈕的工作示例:
示例
<!doctype html> <html amp lang = "en"> <head> <meta charset = "utf-8"> <script async src = "https://cdn.ampproject.org/v0.js"> </script> <title>Google AMP - Amp Pinterest Widget</title> <link rel = "canonical" href = "http://example.ampproject.org/article-metadata.html"> <meta name = "viewport" content = "width = device-width, minimum-scale = 1,initial-scale = 1"> <style amp-boilerplate> body{ -webkit-animation: -amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation: -amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation: -amp-start 8s steps(1,end) 0s 1 normal both;animation: -amp-start 8s steps(1,end) 0s 1 normal both } @-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}} </style> <noscript> <style amp-boilerplate> body{ -webkit-animation:none; -moz-animation:none; -ms-animation:none; animation:none} </style> </noscript> <script async custom-element = "amp-pinterest" src = "https://cdn.ampproject.org/v0/amp-pinterest-0.1.js"> </script> <style amp-custom> amp-facebook-like { margin: 1rem } </style> </head> <body> <h3>Google AMP - Amp Pinterest Follow Button</h3> <amp-pinterest height = 50 width = 130 data-do = "buttonFollow" data-href = "https://in.pinterest.com/wedgehairstyles/" data-label = "wedgehairstyles"> </amp-pinterest> </body> </html>
輸出

Google Amp - Twitter
AMP 有一個元件可以使用 amp-twitter 顯示 Twitter 提要。
要使用 amp-twitter,我們需要新增以下指令碼:
<script async custom-element = "amp-twitter" src = "https://cdn.ampproject.org/v0/amp-twitter-0.1.js"> </script>
Amp-twitter 標籤
<amp-twitter width = "375" height = "472" layout = "responsive" data-tweetid = "885634330868850689"> </amp-twitter>
此處顯示了一個顯示推文的工作示例
示例
<!doctype html> <html amp lang = "en"> <head> <meta charset = "utf-8"> <script async src = "https://cdn.ampproject.org/v0.js"> </script> <title>Google AMP - Amp Twitter</title> <link rel = "canonical" href = "http://example.ampproject.org/article-metadata.html"> <meta name = "viewport" content = "width = device-width, minimum-scale = 1,initial-scale = 1"> <style amp-boilerplate> body{ -webkit-animation: -amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation: -amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation: -amp-start 8s steps(1,end) 0s 1 normal both;animation: -amp-start 8s steps(1,end) 0s 1 normal both } @-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}} </style> <noscript> <style amp-boilerplate> body{ -webkit-animation:none; -moz-animation:none; -ms-animation:none; animation:none} </style> </noscript> <script async custom-element = "amp-twitter" src = "https://cdn.ampproject.org/v0/amp-twitter-0.1.js"> </script> <style amp-custom> amp-facebook-like { margin: 1rem } </style> </head> <body> <h3>Google AMP - Amp Twitter</h3> <amp-twitter width = "375" height = "472" layout = "responsive" data-tweetid = "885634330868850689"> </amp-twitter> </body> </html>
輸出
