playground

package
v0.0.0-...-9217bb4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

README

AMP by Example - Playground

Configuring auto-import of components

The AMP by Example Playground editor automatically adds <script> elements for components detected in the HTML source. For example, adding a <amp-sidebar> element to the source adds the following child element to <head>:

<script async custom-element="amp-sidebar" src="https://cdn.ampproject.org/v0/amp-sidebar-0.1.js"></script>

The mapping of component HTML element names to versions is derived by parsing definitions in the ampproject source on GitHub, using the GitHub API.

Use of this API requires the use of a token in order to avoid rate limiting associated with unauthenticated requests.

To create and store a token for a deployed instance of AMP by Example:

  1. In your GitHub profile, navigate to Settings > Developer settings.
  2. Click on Personal access tokens then Generate new token.
  3. No additional scopes are required before clicking Generate token.
  4. Create a new entity in Datastore:
    1. Set the Kind to GitHubApiToken
    2. Set the Key identifier to Custom name with value GitHubApiTokenKey
    3. Add a property with Name AuthKey and Value set to the token obtained from GitHub.
  5. If this has been successful, no warnings will be present in the logs where requests are made to GitHub, bearing in mind that such requests only occur daily.

Documentation

Overview

*

  • Copyright 2018 The AMP HTML Authors. All Rights Reserved. *
  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at *
  • http://www.apache.org/licenses/LICENSE-2.0 *
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS-IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License.

Index

Constants

View Source
const (
	COMPONENTS_URL                 = "https://api.github.com/repos/ampproject/amphtml/git/trees/master?recursive=1"
	COMPONENTS_MEMCACHE_KEY        = "amp-components-list"
	COMPONENTS_UPDATE_FREQ_SECONDS = 86400 // one day
	PLAYGROUND_PATH_PREFIX         = "/playground"
)

Variables

This section is empty.

Functions

func InitPlayground

func InitPlayground()

func InitializeComponents

func InitializeComponents(r *http.Request)

Types

type AmpComponentsList

type AmpComponentsList struct {
	Timestamp  int
	Components []byte
}

type ComponentsReqError

type ComponentsReqError struct {
	Message string
	Code    int
}

type GitHubApiResponse

type GitHubApiResponse struct {
	Sha       string       `json:"sha"`
	Url       string       `json:"url"`
	Tree      []GitHubBlob `json:"tree"`
	Truncated bool         `json:"truncated"`
}

type GitHubApiToken

type GitHubApiToken struct {
	AuthKey string
}

An Auth key for using GitHub API should be generated and placed in Datastore on App Engine, with the Datastore key of "GitHubApiTokenKey". This ensures that requests to the GitHub API are not subject to the severe rate limiting imposed on unauthenticated requests, stopping the components map being built.

type GitHubBlob

type GitHubBlob struct {
	Path     string `json:"path"`
	Mode     string `json:"mode"`
	BlobType string `json:"type"`
	Sha      string `json:"sha"`
	Size     int    `json:"size"`
	Url      string `json:"url"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL