hexo-broken-link-checker

1.0.3 • Public • Published

Introduction

This is a hexo plugin which detects links that don't work, missing images and redirects.

Plugin installation

Run the following command in the root directory of hexo:

npm install hexo-broken-link-checker --save

And enable the plugin in your _config.yml.

plugins:
  - hexo-broken-link-checker

Configuration

Open your _config.yml file and paste the following lines:

# hexo-broken-link-checker plugin
link_checker:
  enabled: true
  storage_dir: temp/link_checker
  silent_logs: false
  • enabled: (boolean) - Enables or disables the post inspection for links.
  • storage_dir: (string) - Where do you want the plugin to store its files.
  • silent_logs: (boolean) - If true, the logs will be placed in a log file instead of the console output.

First run

Once you have all configured, you need to create a few files that will be used by this plugin. Run the following command:

hexo link_checker setup

You'll see something link this:

If, for some reason, you execute this command twice, you'll see a warning message:

Pro Tip!

link_checker command has an alias, lc. That said, hexo link_checker [arguments] and hexo lc [arguments] are the same command.

Usage

Extracting links

First of all, make sure the plugin is enabled:

# _config.yml
link_checker:
  enabled: true

This will automatically register a hexo post filter, which is a function that processes your already rendered posts. The post filter will be called every time you run hexo generate, will extract and store all the links on your posts. Currently, hexo-broken-link-checker detects:

  • <a> tags.
  • <img> tags.
  • YouTube embedded videos.

So, as I said, run:

hexo generate

And you'll see the following messages:

Scanning links

If you have a blog with 1000 posts, and each article has 2 external links, you'll have 2000 links to extract and check. That's a lot of operations just to check for success or error HTTP Codes, and that's why the extraction and scan are two different tasks.

Once hexo generate has finished the extraction process, you can run:

hexo lc scan

This command will take every link on the storage file and will make a HTTP request to it. All results will be stored on the same storage file.

Pro Tip!

Because this command is slow and passive, you can use a cron job to check all of your links in background. For example:

# Every day at 10PM, go to my blog directory, run the scanner and only store the errors on linkchecker_error.log
0 22 * * * cd /home/me/MyBlog/ && hexo lc scan 2> linkchecker_errors.log

Checking the scan results

hexo lc show-links [options]

Options can be:

  • --filter=[all|broken|ok|redirects|unverified]: filter links by status.
  • --id=[linkID]: shows detailed info of a link.

Examples:

Checking the log files

hexo lc show-logs

The screenshot below shows the log file when you set silent_logs: true into _config.yml:

Bitdeli Badge

Package Sidebar

Install

npm i hexo-broken-link-checker

Weekly Downloads

0

Version

1.0.3

License

none

Last publish

Collaborators

  • sergiolepore