GithubHelp home page GithubHelp logo

lgs / amp-vue-hackernews Goto Github PK

View Code? Open in Web Editor NEW

This project forked from musement/amp-vue-hackernews

0.0 2.0 0.0 173 KB

Hacker News client built with AMP and Nuxt.js

Home Page: https://hn-amp.herokuapp.com

JavaScript 46.91% Vue 50.67% HTML 2.42%

amp-vue-hackernews's Introduction

AMP Hacker News client PWA

Hacker News client app built with Nuxt.js (and Vue.js) which generates fast and lightweight AMP pages as a Progressive Web Application

The idea behind this project is to provide a developer friendly "recipe" to generate and serve a PWA with AMP using Javascript.


Live Demo

Why Vue.js and Nuxt.js

Simplicity is the key to brilliance

  1. Because of Vue.js simple, intuitive and reliable template engine.
  2. Because of Nuxt.js presets and conventions, which let you stay focused on the most important thing: enjoy coding your app
  3. Because is javascript

Main AMP requirements

  • Render all pages with required markup
  • Loading stylesheet from an external file is not allowed
  • Custom javascript is not allowed, only amp custom-element scripts can be used
  • When is supposed to be so, render the right amp custom-element in place of native HTML elements
  • amp custom-elements scripts must be imported only if they're used in page
  • Output head meta tags like canonical and amphtml "rel" links to make AMP pages discoverable

AMP PWA recipe - ingredient list

Is a Server Side Rendered Vue.js application in universal mode.

[+] webpack bundles removal

Since custom javascript is not allowed, client side webpack bundles imports must be removed from DOM. Of course, would be better to avoid client side build at all but I didn't find the way to exclude this step. See ampHtmlSanitizer.js module for the regular expression applied for this purpose.

[+] remote data and vuex store

In server side rendering everything works as usual with any other Nuxt.js app. Fetch method is used to fire an async vuex action to call the APIs and gather request data in order to render the page. If you are familiar with Vue.js and Nuxt.js you should easily understand the request and render flow in SSR

[+] client side interaction replaced with amp-bind and amp-state

Client side interaction can be done using amp-bind and amp-mustache-templates. In this app you can see them in action by navigating to any /item/:id route and clicking on "toggle replies" link: on link tap fires setState action, which toggles the underneath block visibility and amp-list gets remote data using a remote endpoint. Comment replies are shown using mustache templates under components/amp-mustache-templates folder by referencing their id (filename including extension)

Canonical and amphtml page link meta tags are handled at layout level by using the appConfigInjector.js module. To put these meta tags in <head> tag Nuxt.js relies on vue-meta plugin, which works great.

Build Setup

# install dependencies
$ yarn install

# serve with hot reload at localhost:8000
$ yarn run dev

# build for production and launch server
$ yarn run build
$ yarn start

# generate static project
$ yarn run generate

For detailed explanation on how to deal with Nuxt.js, checkout Nuxt.js docs

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.