Giter Site home page Giter Site logo

ampproject / amp-by-example Goto Github PK

View Code? Open in Web Editor NEW
754.0 88.0 506.0 235.37 MB

DEPRECATED: AMP by Example has been merged into amp.dev

Home Page: http://amp.dev

License: Apache License 2.0

Go 6.74% JavaScript 15.00% HTML 74.13% CSS 3.79% Shell 0.24% Dockerfile 0.10%
amp amp-html

amp-by-example's Introduction

IMPORTANT: AMP by Example has been merged into amp.dev. All new issues and pull requests should be created here.

AMP by Example

Installation

  1. Fork the repository.
  2. Install NodeJS. You will need version 4.0.0 or above.
  3. Install Gulp via npm. You may need to use sudo depending on your Node installation.
$ npm install -g gulp
  1. Set up the repository:
$ git clone https://github.com/YOUR_GITHUB_NAME/amp-by-example.git
$ cd amp-by-example
$ npm install
  1. Build and run the site:
$ gulp
  1. If everything went well, gulp should now be running the site on http://localhost:8000/

Creating a new sample

Create a new example with gulp create. Set the title via --name or -n and add it to an existing section using --dest or -d:

$ gulp create --name amp-img --dest src/20_Components
$ vim src/20_Components/amp-img.html

For more descriptive example names including whitespaces use quotes:

$ gulp create --name 'Hello World' --dest src/10_Introduction
$ vim src/10_Introduction/Hello_World.html

If you want to create a new sample category, use --category or -c. Prefix the name with two digits followed by a space to define the sort order:

$ gulp create --name amp-awesome --category "50 More Awesomeness"
$ vim src/50_More_Awesomeness/amp-awesome.html

Run validate to validate all examples against AMP spec:

$ gulp validate

Run build to generate all examples:

$ gulp build

While working on an example you can start a local webserver with auto-reload on http://localhost:8000/ by running gulp:

$ gulp

Some components, like amp-live-list require an additional server endpoint.

Writing the sample

Use HTML comments (<!-- ... -->) to document your sample code:

<!-- Look! Images in AMP. -->
<amp-img src="img/image1.jpg" width="200" height="100" layout="responsive"></amp-img>

This works for elements in the header as well:

<head>
  <!-- Import the amp-youtube component -->
  <script async custom-element="amp-youtube" src="https://cdn.ampproject.org/v0/amp-youtube-0.1.js"></script>
  ...
</head>

Every HTML comment creates a separate example section spanning the following HTML element.

<!-- This comment spans the whole following section including the two images -->
<section>
  <amp-img src="img/image1.jpg" width="200" height="100" layout="responsive"></amp-img>
  <amp-img src="img/image2.jpg" width="200" height="100" layout="responsive"></amp-img>
</section>

Nesting comments are not supported:

<!-- A comment -->
<div>
  <!-- This does not work because the parent div has already a comment -->
  <amp-img src="img/image1.jpg" width="200" height="100" layout="responsive"></amp-img>
</div>
<div>
  <!-- Commenting inside nested tags works though -->
  <amp-img src="img/image1.jpg" width="200" height="100" layout="responsive"></amp-img>
</div>

If your comment spans multiple elements, wrap these in an single div without any attributes. The enclosing div tag will be hidden in source code listings:

<!-- The enclosing `div` will be hidden in source code listings. -->
<div>
  <button on="tap:my-lightbox" role="button" tabindex="0">Open lightbox</button>
  <amp-lightbox id="my-lightbox" layout="nodisplay">
    <h1>Hello World!</h1>
  </amp-lightbox>
</div>

Sample Styling

Sometimes it's good to add a little bit more styling to a sample (e.g. to separate a button from an input field). To make sure that all samples have a consistent styling, please use the following CSS variables to style specific elements in your sample:

:root {
  --color-primary: #005AF0;
  --color-secondary: #00DCC0;
  --color-text-light: #fff;
  --color-text-dark: #000;
  --color-error: #B00020;
  --color-bg-light: #FAFAFC;

  --space-1: .5rem;  /* 8px */
  --space-2: 1rem;   /* 16px */
  --space-3: 1.5rem; /* 24px */
  --space-4: 2rem;   /* 32px */

  --box-shadow-1: 0 1px 1px 0 rgba(0,0,0,.14), 0 1px 1px -1px rgba(0,0,0,.14), 0 1px 5px 0 rgba(0,0,0,.12);
}

You can use them to style your samples like this:

.button {
  margin: var(--space-2);
  padding: var(--space-1);
  background-color: var(--color-primary);
  color: var(--color-text-light);
}

Only add the ones that you need to the sample. These CSS variable declarations will be added automatically to your sample, if you use gulp create ... to create the sample.

Colors

screenshot 2018-11-30 at 00 22 57

Spaces

screenshot 2018-11-30 at 00 23 08

Formatting

You can use markdown to format your documentation:

<!--
  A simple [responsive](https://www.ampproject.org/docs/guides/responsive/control_layout.html)
  image - *width* and *height* are used to determine the aspect ratio.
-->
<amp-img src="img/image1.jpg" width="200" height="100" layout="responsive"></amp-img>

Notes, Warnings & Tips

There's a special markup available for callouts:

[tip type="default|important|note|read-on"]
Tip!
[/tip]

For example:

[tip type="important"]
Warning! This might go wrong.
[/tip]

Hints

If you'd like to add additional information about a single element inside a section, use the <!--~ hint syntax ~-->:

<!-- A comment about the form. -->
<form method="post"
  action-xhr="https://example.com/subscribe"
  target="_top">
  <fieldset>
    <input type="text" name="username">

    <!--~ Addition explanation about the hidden field. ~-->
    <input type="hidden" name="id" value="abc">
  </fieldset>
</form>

This will make the <input> element clickable, with the additional explanation appearing on click.

Drafts

You can mark samples as drafts if they are still work-in-progress. This means the samples won't show up in the start page.

<!---
draft: true
--->

Experimental Features

If your sample is using one or more experimental features, you can add a metadata section (<!--- ... --->) with the variable experiments to specify which experiments to enable. This will skip its validation and add an experimental note with instructions to your sample:

<!---
experiments:
  - amp-experiment-name
  - amp-another-experiment
--->

Preview Mode

Visually rich examples can provide a preview mode like this. Enable via metadata in the sample:

<!---
preview: default
--->

There is a special preview mode for AMP Ad samples:

<!---
preview: a4a
--->

Single Column Layout

If your sample looks better with a single column layout, you can disable the code and preview columns adding the following flags to your sample file:

<!---
hideCode: true
hidePreview: true
--->

Disabling the Playground

If it doesn't make sense for your sample to provide a playground link, you can disable it:

<!---
disablePlayground: true
--->

Running the backend server

If you need to run or write a sample that depends on the backend server, you can run a local version.

  1. Install the Google App Engine SDK for Go.

  2. Run the backend server in watch mode so it will recompile on change.

    $ gulp backend:watch
    

    If you get an error message can't find import: "golang.org/x/net/context", you have to manually install and configure the GO appengine environment:

    # install the google.goland.org/appengine package
    $ go get google.golang.org/appengine
    # explicitly set the GOROOT and APPENGINE_DEV_APPSERVER env vars
    $ export GOROOT=$HOME/local/google-cloud-sdk/platform/google_appengine/goroot
    $ export APPENGINE_DEV_APPSERVER=$(which dev_appserver.py)
    
  3. If everything went well, the full site should now be running on http://localhost:8080/

Adding backend functionality

Sample specific backend endpoints should be defined in their own file, e.g. for a sample amp-my-component.html the backend should be backends/amp-my-component.go.

How to style examples

You can’t reference external stylesheets when creating samples. AMP by Example provides a default styling for common elements (p, h1, h2, h3, a, ...) which you should use. Sample specific styles must live in the head of the document using the tag <style amp-custom>. Try to keep the additional CSS for samples to a minimum and use the default styles as often as possible. If you compile a sample via Gulp and run it, the default styling will be applied.

Please note: if you copy code from a sample's code section, you will not get the style that you can see in the preview section.

Contributing

Please see the CONTRIBUTING file for information on contributing to amp-by-example.

License

AMP by Example is made by the AMP Project, and is licensed under the Apache License, Version 2.0.

amp-by-example's People

Contributors

aghassemi avatar alanorozco avatar calebcordry avatar camelburrito avatar carlosfuertes avatar cathyxz avatar cvializ avatar dandv avatar demianrenzulli avatar erwinmombay avatar fstanis avatar ithinkihaveacat avatar jkingyens avatar jmadler avatar juliantoledo avatar kevinkassimo avatar kul3r4 avatar lannka avatar lisaychuang avatar martinschierle avatar morsssss avatar nainar avatar paul-matthews avatar renovate-bot avatar rowan-m avatar sebastianbenz avatar tcmg avatar trodrigues avatar ymotongpoo avatar zhouyx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

amp-by-example's Issues

Make anchor links order independent

Currently anchor links depend on the order (example1, example2,...). These will break if a new section is added in between. We should use a slugged version of the content instead.

It is any way to start with AJAX or custome event ??

Hello,

I am starting with AMP for my site Need to know that we can not use AJAX ??

AND one more issue which i am getting on development

If i am adding script like this
<script async src=https://cdn.ampproject.org/v0.js></script> -IT's fine
But If i download that script and try to add like,<script async src=folderPAth/v0.js></script>
AMP Validation ERROR Why ??

validate-example: mark ignored samples

Can we include ignored samples (skipValidation / experimental) in the validation report? e.g.:

Validating components/amp-list/index.html: IGNORED (in yellow)

Shorten text in code sections

Long texts in the sample files is often required (e.g. amp-carousel), but bloats the code sections. Let's automatically shorten text between html tags that is longer than 50 chars, e.g.

<p>
  This is a very very very very very very very very very veryvery very very long text
</p>

becomes:

<p>
  This is a very very very very very very very ...
</p>

Mark experimental samples

[] append [experimental] to example name in overview page
[] inject src/templates/experiment.html into example template if experimental flag is set (see #32)

Add description to sections

Create a file section.json in each section dir which includes the description. Generate it automatically when running gulp create with a new section.

{
  "description": "This is my section"
}

Split examples into sections

To give a better overview over the samples, we could split the samples into sections in the overview page, e.g.:

  1. Introduction
    • Hello World
    • ...
  2. Components
    • amp-img
    • amp-carousel
    • ....
  3. Getting more out of AMP
    • Video Carousel
    • How to cope with the fixed carousel height?
    • User notifications with server end-point
    • ...

Implementation wise this is simple by moving the samples into respective directories.

//cc @adewale @juliantoledo @jkingyens @ymotongpoo @kul3r4 what do you think?

amp-accordion example does'nt work!

Powered by AMP ⚡ HTML – Version 1456954860788
AMP validation had errors:
https://ampbyexample.com/components/amp-accordion/:5:2 The attribute 'custom-element' in tag 'amp-access extension .js script' is set to the invalid value 'amp-accordion'. (see https://www.ampproject.org/docs/reference/extended/amp-access.html)
https://ampbyexample.com/components/amp-accordion/:1570:12 The tag 'amp-accordion' is disallowed.
https://ampbyexample.com/components/amp-accordion/:1571:4 The attribute 'expanded' may not appear in tag 'section'.
https://ampbyexample.com/components/amp-accordion/:1653:2 The tag 'amp-accordion' is disallowed.

Validation fails with timeout

[15:24:52] Validating example components/amp-ad/index.html: PASS
undefined:1
Fatal Error: Timeout: did not get to load all resources on this page
^

SyntaxError: Unexpected token F
    at Object.parse (native)
    at ChildProcess.<anonymous> (/Users/sbenz/Documents/projects/amp-by-example-dev/tasks/validate-example.js:63:37)
    at emitTwo (events.js:100:13)
    at ChildProcess.emit (events.js:185:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)

@jkingyens have you seen this before?

Add metadata to examples

Make it possible to add metadata to examples via special comment tag, e.g.

<!---{ 
  experiment: true,
  component: amp-accordion
}--->

Metadata can contain arbitrary JSON. The DocumentParser should extract the metadata and add it to a new field in Document.

This is the foundation for:

  • #33 marking experimental samples
  • #1 don't validate experimental samples

//cc @jkingyens @juliantoledo does anyone of you want to tackle this?

SAMPLES_DIR is missing at gulpfile.js

[21:40:56] 'compile:sitemap' errored after 186 μs
[21:40:56] ReferenceError: SAMPLES_DIR is not defined
at Gulp. (/Users/jtoledo/Documents/workspace/amp-by-example/gulpfile.js:167:19)
at module.exports (/Users/jtoledo/Documents/workspace/amp-by-example/node_modules/orchestrator/lib/runTask.js:34:7)
at Gulp.Orchestrator._runTask (/Users/jtoledo/Documents/workspace/amp-by-example/node_modules/orchestrator/index.js:273:3)
at Gulp.Orchestrator._runStep (/Users/jtoledo/Documents/workspace/amp-by-example/node_modules/orchestrator/index.js:214:10)
at Gulp.Orchestrator.start (/Users/jtoledo/Documents/workspace/amp-by-example/node_modules/orchestrator/index.js:134:8)
at /usr/local/lib/node_modules/gulp/bin/gulp.js:129:20
at nextTickCallbackWith0Args (node.js:452:9)
at process._tickCallback (node.js:381:13)
at Function.Module.runMain (module.js:449:11)
at startup (node.js:139:18)

Support code sections in docs

Using code sections in docs with triple ''' does not keep the indentation.
Example is: amp-list where the json inside the docs is not correctly indented.

Create an example that shows all the video types in AMP

The list includes (at least):

  • amp-video
  • amp-instagram pointing at a video
  • amp-vine
  • amp-youtube
  • amp-vimeo
  • amp-dailymotion
  • amp-twitter pointing at a Twitter-native video
  • amp-facebook pointing at a Facebook-native video
  • amp-brightcove
  • a non-natively supported video platform via amp-iframe

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.