GithubHelp home page GithubHelp logo

maddevsio / seo-analyzer Goto Github PK

View Code? Open in Web Editor NEW
71.0 6.0 10.0 53.19 MB

The library for analyze a HTML file to show all of the SEO defects

License: MIT License

HTML 5.38% JavaScript 10.08% Shell 0.22% TypeScript 84.32%
seo javascript html vue react angular node search-engine

seo-analyzer's Introduction

SEO analyzer — library for searching SEO issues

Developed by Mad Devs License: MIT

Preview

The library for analyze a HTML files to show all of the SEO defects.

Translations of documentation

Advantages of this plugin

  • Easy setup.
  • Adding custom rules.
  • 6 ready-made rules.
  • Running the seo-analyzer for SSR applications.
  • Running the seo-analyzer for SPA applications.
  • Running the seo-analyzer in pipelines(github, gitlab, ...) or pre-push or anywhere else.
  • Multiple options for outputting the result.

Why you should use Seo Analyzer

  • Saves time: will save you from manually searching for seo problems.
  • Seo Friendly: will save your project from problems with search engines.
  • It’s free: we’re happy to share the results of our work.

How to use the CLI

To use the CLI, you must install the package globally.

npm install -g seo-analyzer

Usage

seo-analyzer -h
Option Args Description
-h, --help null Show all options.
-v, --version null Display Application Version: Displays the current version of the application.
-iu, --ignoreUrls [array] Exclude Specific URLs from Analysis: Excludes certain URLs from analysis to avoid processing unwanted web pages.
-if, --ignoreFiles [array] Exclude Specific Files from Analysis: Allows excluding certain files from analysis, preventing their processing.
-ifl, --ignoreFolders [array] Exclude Specific Folders from Analysis: Excludes specified folders from the analysis process, ignoring all files within those folders.
-u, --urls [array] Perform SEO Analysis on Specified URLs: Conducts SEO analysis for specified URLs, checking their compliance with certain SEO criteria.
-f, --files [array] Perform SEO Analysis on Specified Files: Performs SEO analysis on specified files, ensuring their adherence to optimization standards and rules.
-fl, --folder [array] Perform SEO Analysis on Specified Folders: Analyzes all files within specified folders for compliance with SEO rules and recommendations.
-r, --rules [array] Apply Specific SEO Rules for Analysis: Applies specific SEO rules during analysis, allowing the user to customize the inspection process. By default run all default rules.

Example of using multiple url analysis

seo-analyzer -u https://maddevs.io https://maddevs.io/blog

Example of using rules

seo-analyzer -u https://maddevs.io -r titleLengthRule='{ "min": "500" }'

Use json format to pass parameters to the rule.

How to use as github action

To use SEO analyzer as actions on github, you can create a workflow file in .github/workflows/analyzer.yml with the following content:

name: SEO analyzer

on: [push]

jobs:
  seo-analyzer:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Use Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20.x'
      - run: npm i -g seo-analyzer
      - run: seo-analyzer -u https://maddevs.io

In the last step, you can specify the url you want to analyse.

How to use as API

Install to the project.

npm install -D seo-analyzer

Usage

Getting started

Setting up the SEO analyzer is as simple as possible. It will look something like this:

const SeoAnalyzer = require('seo-analyzer');

new SeoAnalyzer()
  .inputFiles(<array>)
  .addRule(<function>)
  .addRule(<function>)
  .outputConsole()
  .run();

Next I will show you some examples.

One way: analyze the url list and output the report to the console

const SeoAnalyzer = require('seo-analyzer');

new SeoAnalyzer()
  .inputUrls(['https://maddevs.io', 'https://maddevs.io/blog'])
  .addRule('imgTagWithAltAttributeRule')
  .outputConsole()
  .run();

Two way: file analysis for SPA application and log report to console

const SeoAnalyzer = require('seo-analyzer');

new SeoAnalyzer()
  .ignoreUrls(['/404', '/login'])
  .inputSpaFolder('/dist', 'sitemapindex.xml', 3000)
  .addRule('imgTagWithAltAttributeRule')
  .outputConsole()
  .run();

Three way: read a list HTML files and log report to console

const SeoAnalyzer = require('seo-analyzer');

new SeoAnalyzer()
  .inputFiles(['index.html', 'about.html'])
  .addRule('imgTagWithAltAttributeRule')
  .outputConsole();

Fourth way: read a folders with HTML files and log report to console

const SeoAnalyzer = require('seo-analyzer');

new SeoAnalyzer()
  .inputFolders(['dist', 'src'])
  .addRule('imgTagWithAltAttributeRule')
  .outputConsole()
  .run();

Fifth way: read a folders with HTML files and return json

const SeoAnalyzer = require('seo-analyzer');

new SeoAnalyzer()
  .inputFolders(['dist', 'src'])
  .addRule('imgTagWithAltAttributeRule')
  .outputJson(json => console.log(json))
  .run();

Sixth way: ignore subfolder "test" and 404.html in folder "src" and return js object

const SeoAnalyzer = require('seo-analyzer');

new SeoAnalyzer()
  .ignoreFolders(['src/test'])
  .ignoreFiles(['src/404.html'])
  .inputFolders(['dist', 'src'])
  .addRule('imgTagWithAltAttributeRule')
  .outputObject(obj => console.log(obj))
  .run();

Seventh way: Input an HTML string directly and log report to console

const SeoAnalyzer = require('seo-analyzer');

new SeoAnalyzer()
  .inputHTMLString(
    '<!DOCTYPE html><html><body><h1>title</h1><p>content</p></body></html>'
  )
  .addRule('imgTagWithAltAttributeRule')
  .outputConsole()
  .run();

Available methods:

Method Params Description
ignoreFiles ['dist/about.html'] This method expects an array of files to ignore before analysis.
ignoreFolders ['dist/ignore'] This method expects an array of folders to ignore before analysis.
ignoreUrls ['/404'] This method expects an array of urls to ignore before analysis.
inputFiles ['dist/index.html'] This method expects an array of html files.
inputUrls ['https://maddevs.io'] This method expects an array of urls to analyze.
inputFolders ['dist', 'src'] This method expects an array of folders with html files.
inputSpaFolder '/dist', 'sitemap.xml', 3000 This method expects an string of folder with SPA builded files to production & port for run server.
inputHTMLString ['example'] This method expects a string containing HTML.
addRule function(dom) {} This method adds a custom rule to check incoming HTML files.
outputObject function(obj) {} This method will return the report as a javascript object.
outputJson function(json) {} This method will return the report in JSON format.
outputConsole null This method must be used at the very end of the chain, because it completes the process in the console.

List of rules that are available by default

Below are the rules that are executed for each file transferred to Seo Analyzer. They are disabled by default and must be added.

Title Length Rule

Checks the length of tag <title>. Two parameters are accepted:

  • min: minimum length of the header
  • max: maximum length of the header
.addRule('titleLengthRule', { min: 10, max: 50 })

Img Tag With Alt Attribute Rule

Checks if all <img> tags have alt="" attribute.

.addRule('imgTagWithAltAttributeRule')

<a> Tag With Rel Attribute Rule

Checks if all <a> tags have rel="" attribute.

.addRule('aTagWithRelAttributeRule')

Meta Base Rule

Checks if the specified basic meta tags are present on the page. Accepts one parameter:

  • list: list of required meta tags
.addRule('metaBaseRule', { list: ['description', 'viewport'] })

Meta Social Rule

Checks if the specified social meta tags are present on the page. Accepts one parameter:

  • properties: list of required meta tags
.addRule('metaSocialRule', {
  properties: [
    'og:url',
    'og:type',
    'og:site_name',
    'og:title',
    'og:description',
    'og:image',
    'og:image:width',
    'og:image:height',
    'twitter:card',
    'twitter:text:title',
    'twitter:description',
    'twitter:image:src',
    'twitter:url'
  ],
})

Canonical Link Rule

Checks if a canonical link exists on the page.

.addRule('canonicalLinkRule')

Add custom rule

A custom rule is a function that takes a DOM tree argument.

function customRule(dom) {
  return new Promise(async (resolve, reject) => {
    const paragraph = dom.window.document.querySelector('p');
    if (paragraph) {
      resolve('');
    } else {
      reject('Not found <p> tags');
    }
  });
}

...
.addRule(customRule)
...

Licensing

MIT License

Copyright (c) 2024 Mad Devs

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

seo-analyzer's People

Contributors

denisoed avatar klandri avatar oh-cactus avatar tangopj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

seo-analyzer's Issues

how can i point this analyser to an existing local server?

For example i have a local CRA or Next.js app running on localhost:3000. How can i point this tool to analyse localhost:3000 ?

p.s.
Also, would be cool if this could be part of a test suite, so that if something breaks, whole build fails.

cli version

it would be optimal if the project provide a small cli (command line version) of the tool that took a input file

Links not found

I'm trying to run the seo-analyzer in a Next.js (13.2.3) project.

But I'm getting the following output:
🚀 Ready on http://localhost:3000

🚀 Get sitemap from http://localhost:3000

❌ Links not found

Sitemap is generated by next-sitemap on build and is exported to the public folder.

I guess the issue is that seo-analyzer can't detect the sitemap?

I've verified that the sitemap is reachable via http://localhost:3000/sitemap.xml in local development.

How can I resolve this?

Many thanks in advance!

seo-analyzer.js
require('dotenv').config()
const SeoAnalyzer = require('seo-analyzer')

new SeoAnalyzer()
  .inputNextJs(3000)
  .addRule(
    'titleLengthRule',
    { min: 10, max: 50 },
    'imgTagWithAltAttributeRule',
    'aTagWithRelAttributeRule',
    'metaSocialRule',
    {
      properties: [
        'og:url',
        'og:type',
        'og:site_name',
        'og:title',
        'og:description',
        'og:image',
        'og:image:width',
        'og:image:height',
        'twitter:card',
        'twitter:text:title',
        'twitter:description',
        'twitter:image:src',
        'twitter:url',
      ],
    },
    'canonicalLinkRule'
  )
  .outputConsole()
public/
┣ admin/
┃ ┣ assets/
┃ ┣ .gitignore
┃ ┗ index.html
┣ fonts/
┃ ┣ HelveticaNowText-Bold.woff2
┃ ┗ HelveticaNowText-Regular.woff2
┣ scripts/
┃ ┣ scrollbar-width.js
┃ ┣ smartlook.js
┃ ┣ theme.js
┃ ┗ window-height.js
┣ styles/
┃ ┣ globals.css
┃ ┗ swiper.css
┣ favicon.ico
┣ logotype.svg
┣ og_default.png
┣ prisjakt.png
┣ sitemap.xml
┗ sponsors.webp
.next/
┣ cache/
┃ ┣ images/
┃ ┣ swc/
┃ ┣ webpack/
┃ ┗ next-server.js.nft.json
┣ server/
┃ ┣ chunks/
┃ ┣ pages/
┃ ┣ font-loader-manifest.js
┃ ┣ font-loader-manifest.json
┃ ┣ font-manifest.json
┃ ┣ middleware-build-manifest.js
┃ ┣ middleware-manifest.json
┃ ┣ middleware-react-loadable-manifest.js
┃ ┣ pages-manifest.json
┃ ┣ webpack-api-runtime.js
┃ ┗ webpack-runtime.js
┣ static/
┃ ┣ Yv9_L8DMQcC1hKfxrYKCn/
┃ ┣ chunks/
┃ ┣ css/
┃ ┗ media/
┣ BUILD_ID
┣ build-manifest.json
┣ export-marker.json
┣ images-manifest.json
┣ next-server.js.nft.json
┣ package.json
┣ prerender-manifest.json
┣ react-loadable-manifest.json
┣ required-server-files.json
┣ routes-manifest.json
┗ trace

Feature: Make next/react optional

I am using it with nuxt js but it fails to run without next. I would be happy to contribute if you can suggest how to make next optional.

html output for cli version

I love the cli option!
I wish there were a simple html output option so I every nite could generate a html page to display on a big screen tv

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.