npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

grunt-ng-html-snapshot

v0.1.6

Published

A simple phantom.js based snapshots creator for single page applications written in Angular 1.x

Downloads

10

Readme

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: ''

Document type (for example, '', '', 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.0 - first version. No threshold for checks for page loading status. The process will be killed by timeout after 5 minutes.