Git Product home page Git Product logo

grunt-ng-html-snapshot's Introduction

grunt-ng-html-snapshot

A simple phantom.js based snapshots creator for single page applications written in Angular 1.x. DO NOT use it for regular website (whose front-end works not in Angular 1.x) with default phantom.js job. In case if you DO want to use it for regular website you have to set path to phantom.js job (see details bellow). This plugin will successfully create a page snapshot if it has automatically bootstrapped module (marked with either ng-app, or data-ng-app, or x-ng-app, or ng_app attribute).

Getting Started

This plugin requires Grunt ~0.4.5

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-ng-html-snapshot --save

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-ng-html-snapshot');

The "ng_html_snapshot" task

Overview

In your project's Gruntfile, add a section named ng_html_snapshot to the data object passed into grunt.initConfig().

grunt.initConfig({
  ng_html_snapshot: {
    options: {
      // Task-specific options go here.
    }
  }
});

Options

options.baseUrl

Type: String

Base url of your application / website in form of: protocol://host. Make sure that your web server is up and running if you running web application locally. For example, http://localhost:8080

options.jobPath

Type: String Default: './node_modules/grunt-ng-html-snapshot/utils/phantom-job.js'

Path to a phantom.js job (relatively to Gruntfile.js) which contains logic for building web pages snapshots. Change it only if you need custom phantom.js logic and you know what you are doing.

options.output

Type: Object

An object with output details

options.output.dir

Type: String

Output directory relative to Gruntfile.js

options.output.snapshotFileExt

Type: String

Snapshot file extension. If you would like to output each page snapshot without file extension, then either pass false or omit this param.

options.output.logFile

Type: String

Path to log file with a results of phantom.js actions. If you don't need such a log, then either pass false or omit this param.

options.pageLoadingTimeout

Type: Number Default: 100

If page wasn't successfully loaded during first attempt, then timeout is used as an interval before executing next attempt.

options.removeMetaFragment

Type: Boolean Default: true

Set this flag to false if you don't need to remove from a page snapshot. This might be necessary for some search engines. For example, this tag should be removed from a page so that it can be indexed by Yandex bot. [See details here] (https://yandex.com/support/webmaster/robot-workings/ajax-indexing.xml)

options.pageDocType

Type: String Default: '<!doctype html>'

Document type (for example, '<!doctype html>', '', etc).

options.pages

Type: Array

Array of target pages. Each object in this array has to have two fields: path and file. 'path' is added to baseUrl (options.output.baseUrl) in order to construct page's absolute url. 'file' is added to output directory path (options.output.dir) and result is merged with file extension (only if it was set) in order to get an absolute path to a file with page snapshot.

Usage Example

grunt.initConfig({
    ng_html_snapshot: {
        options: {
            /*
             * Keep in mind, that you have to have a running web server, if you running
             * your web application locally.
             */

            baseUrl: 'http://localhost:8080',
            
            /*
             * Overriding default path to phantom.js job.
             * Note: path is relative to Gruntfile.js
             */
            
            jobPath: './some-folder/some-custom-phantom-job.js',

            output: {
              // Output directory. In case if doesn't exists phantom creates it.

              dir: './html-snapshots',

              snapshotFileExt: 'html',

              // If you don't want to log job actions, then use false as a value.

              logFile: 'job-log.txt'
            },

            pageLoadingTimeout: 100,

            pageDocType: '<!doctype html>',
            
            /*
             * Overriding default parameter, hence
             * <meta name="fragment" content="!" />
             * will not be removed from snapshot (s) if
             * it was presented in the original page (s). 
             */
            
            removeMetaFragment: false,

            pages: [
              {
                path: '/path-to-page-a',

                file: 'page-a'
              },

              {
                path: '/',

                file: 'main-page'
              },

              {
                path: '/path-to-page-b',

                file: 'page-b'
              }
            ]
        }
    }
});

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality.

Release History

0.1.4 - bug fixes. 0.1.3 - Fix for gathering documentHtml in the default phantom.js job 0.1.2 - bug fixes. Improved method for checking page loading status. 0.1.0 - first version. No threshold for checks for page loading status. The process will be killed by timeout after 5 minutes.

grunt-ng-html-snapshot's People

Contributors

jasonrammoray avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

grunt-ng-html-snapshot's Issues

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.