node-amp-mustache-skeleton
Version:
AMP page skeleton served via node.js featuring mustache templating.
125 lines (89 loc) • 4.4 kB
Markdown
AMP page skeleton served via node.js featuring mustache templating and equipped for Dockerization.
* Fork this repo.
* `npm i -g gulp-cli`
* `npm i`
* `npm start`
* Navigate to [`http://localhost:8080`](http://localhost:8080) in your browser to see stuff.
* Start developing.

```bash
dist/
pageA/
index.html
pageB/
index.html
img/
google-site-verification.html
index.html
index.js
package.json
package-lock.json
robots.txt
sitemap.xml
src/
img/
json/
seo/
robots.txt
google-site-verification.html
sitemap.xml
server/
index.js
styles/
mystyles.css
templates/
vars.json
views.json
wireframe.mustache
pageA.mustache
pageB.mustache
Dockerfile
gulpfile.js
package.json
package-lock.json
```
When executing `npm start` without the `NODE_ENV` environment variable set to `production`, gulp is instructed to watch changes to source files and automatically rebuild the project.
With each build, the resulting HTML is validated against the AMP standard and the build fails if invalid.
The skeleton is setup so you can inline JSON data, e.g. to add microdata. Put your JSON files into [`src/json/`](src/json) and reference them in your HTML via
```html
<script type="application/ld+json" src="my-data.json"></script>
```
All stylesheets located in [`src/styles`](src/styles) will be combined, processed by [postcss/autoprefixer](https://github.com/postcss/autoprefixer), minified and inlined into generated HTML files.
Templates are rendered by including a view partial into the base [wireframe](src/templates/wireframe.mustache).
Please take a look at [src/templates/wireframe.mustache](src/templates/wireframe.mustache) and adjust it according to your needs.
When you add a new page/view, it needs to be configured in [`src/templates/views.json`](src/templates/views.json). This file contains an array of all views/pages to publish. Each entry in the array is an object with the following signature:
```javascript
{
"name": "pagename",
"vars": {
"href": "/path/to/this/page",
// ...
}
}
```
The important parts are the `name` and the `vars.href` property. The build process will create the path referenced in `vars.href` in the `dist/` directory and render the view into an `index.html` file therein. By convention the build task looks for a partial named `pagename.mustache` in the [`src/templates`](src/templates) directory.
Please look at [`src/templates/views.json`](src/templates/views.json) for some basic examples.
Variables global to all templates are set in [`src/templates/vars.json`](src/templates/vars.json). Any variable can be overriden by a view via the `vars` property in [`src/templates/views.json`](src/templates/views.json).
Please look at [`src/templates/vars.json`](src/templates/vars.json) and [`src/templates/views.json`](src/templates/views.json) for some basic examples.
This skeleton comes equipped with a environment aware [`Koa`](http://koajs.com/) server with compression and basic caching enabled. Configure the server via the following environment variables:
* `PORT` [default: 8080]
* `COMPRESSION_THRESHOLD` [default: 0]
* `CACHE_MAXAGE`: [default: 60000 *(= 1 minute)*]
Please have a look at [`src/server/index.js`](src/server/index.js) and adjust according to your needs.
This skeleton provides a rudimentary [`Dockerfile`](Dockerfile)