想建立您的第一個AMP頁面又不知道如何開始?在本教程中,您將學習如何建立一個基本的AMP HTML頁面,如何對其進行設置並驗證它是否與AMP兼容,以及如何爲發佈和分發作好準備。html
Create your first AMP page
Not sure how to get started? In this tutorial, you’ll learn how to create a basic AMP HTML page, how to stage it and validate that it’s AMP compliant, and finally how to get it ready for publication and distribution.web
下面的代碼是一個不錯的amp樣板,能夠作爲學習的開始。複製並將其保存到擴展名爲.html的文件中。json
<!doctype html> <html amp lang="en"> <head> <meta charset="utf-8"> <script async src="https://cdn.ampproject.org/v0.js"></script> <title>Hello, AMPs</title> <link rel="canonical" href="https://amp.dev/documentation/guides-and-tutorials/start/create/basic_markup/"> <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1"> <script type="application/ld+json"> { "@context": "http://schema.org", "@type": "NewsArticle", "headline": "Open-source framework for publishing content", "datePublished": "2015-10-07T12:02:41Z", "image": [ "logo.jpg" ] } </script> <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> </head> <body> <h1>Welcome to the mobile web</h1> </body> </html>
body正文中的內容很是簡單。可是在頁面的頭部有不少額外的代碼,這些代碼可能不會當即顯示出來。讓咱們來分析一下所需的標記。 app
使用HTTPS:在建立AMP頁面和內容時,應該強烈考慮使用HTTPS協議。雖然AMP文檔自己或圖像和字體不須要HTTPS,但有許多AMP特性須要HTTPS(例如,視頻、iframes等)。要確保您的AMP頁面充分利用全部AMP功能,請使用HTTPS協議。async
必需的標記:ide
可選的標記佈局
除了基本的需求以外,咱們的示例還在頭部包含一個Schema.org定義,這不是AMP的嚴格要求,但若是想要將內容分發到某些位置(例如,在谷歌搜索頭部的花燈切換故事)則須要加這些標記。學習
很好!這就是咱們建立第一個AMP頁面所須要的一切,可是固然,在body中尚未進行不少工做。在下一節中,咱們將介紹如何添加基本的像圖像,自定義AMP元素,如何自定義樣式你的頁面和做出一個響應式佈局。引入圖片amp-img【英譯AMP】字體
參考資料https://amp.dev/documentation/guides-and-tutorials/start/create/basic_markup/?format=websitesui