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

node-seo-validator

v1.0.2

Published

SEO validator for static html file.

Downloads

3

Readme

node-seo-validator

SEO validator for static html file.

Installation

yarn add node-seo-validator
# or
npm install --save node-seo-validator

Test

yarn test
# or
npm test

Usage

seo(htmlFilePath, outputLogPath, applyRules)

Parameters

  • htmlFilePath: Static html file input
  • outputLogPath: Log path for output validation result
  • applyRules: SEO rule names in array, these rule name should be configured in src/rules.js

Currently, there are 6 Pre-defined SEO Rules in this package.

IMG_ALT, HTML_A, HEADER_TITLE, HEADER_META, STRONG, H1

// test.js
const seo = require('node-seo-validator')

const applyRules = [
  'IMG_ALT',
  'HTML_A',
  'HEADER_TITLE',
  'HEADER_META',
  'STRONG',
  'H1'
]

seo('./index.html', './seo.log', applyRules)

Output

$ node test.js
Output file: ./seo.log
┌──────────────┬───────────────────────────────────────────────────┐
│ Rule Name    │ Validate Result                                   │
├──────────────┼───────────────────────────────────────────────────┤
│ IMG_ALT      │ There are 27 <img> tag without attribute: alt     │
├──────────────┼───────────────────────────────────────────────────┤
│ HTML_A       │ There are 856 <a> tag without attribute: rel      │
├──────────────┼───────────────────────────────────────────────────┤
│ HEADER_TITLE │ Good                                              │
├──────────────┼───────────────────────────────────────────────────┤
│ HEADER_META  │ This HTML does not contain <meta name="keywords"> │
├──────────────┼───────────────────────────────────────────────────┤
│ STRONG       │ Good                                              │
├──────────────┼───────────────────────────────────────────────────┤
│ H1           │ Good                                              │
└──────────────┴───────────────────────────────────────────────────┘

Rule Configuration

You can define your SEO rules in src/rules.js

/* 
   New rule to validate if
     <meta name="robots" />
   has been defined in <head>
*/
const HEADER_META_ROBOTS = {
  scope: 'head',
  tag: 'meta',
  upperBound: null,
  lowerBound: null,
  attribute: [
    { name: 'name', value: 'robots', type: 'one' }
  ]
}

| Key | Description | Sample Value | |---|---|---| | scope | Validate elements which are under this scope | head | | tag | Which element you want to validate | meta | | upperBound | Set upper bound limit to this tag Set null to ignore this rule | 10 | | lowerBound | Set lower bound limit to this tag Set null to ignore this rule | 10 | | attribute | Array of attribute rule object Set [] to ignore this rule | [{ name: 'name', value: 'description', type: 'one' }]

Attribute Rule Object

| Key | Description | Sample Value | |---|---|---| | name | Defined the attribute name to validate | href | | value | Defined the value of this attribute to validate Set null to ignore this rule | https://github.com/ | | type | Define this name/value rule should appear in at least one element or every elements | one or every |

Pre-defined SEO Rules

There are some pre-defined rule in this package.

1. IMG_ALT

Detect if any <img /> tag without alt attribute.

2. HTML_A

Detect if any <a /> tag without rel attribute.

3. HEADER_TITLE

In <head> tag, Detect if header doesn’t have <title> tag.

4. HEADER_META

In <head> tag, Detect if header doesn’t have <meta name="descriptions" ... /> and <meta name="keywords" ... /> tag.

5. STRONG

Detect if there are more than 15 <strong> tag in HTML.

6. H1

Detect if a HTML have more than one <H1> tag.