Using Deadfinder and GitHub Actions for Seamless Link Management
A dead link, or broken link, occurs when a hyperlink points to a web page that has been removed or does not exist anymore. Beyond mere inconvenience, these dead links can significantly degrade the user experience, harm your website’s SEO, and introduce security vulnerabilities. For instance:
Therefore, maintaining link integrity not only preserves your site’s professionalism and usability but also plays a critical role in safeguarding your visitors from potential security threats.
Deadfinder is a versatile tool designed to help webmasters and bloggers keep their site’s integrity intact by finding dead links. By the way, this tool was created by me to manage my own website.
And Deadfinder supports GitHub Actions, allowing you to easily run it with the following workflow code:
steps:
- name: Run DeadFinder
uses: hahwul/[email protected]
# or uses: hahwul/deadfinder@latest
id: broken-link
with:
command: sitemap # url / file / sitemap
target: https://www.hahwul.com/sitemap.xml
# timeout: 10
# concurrency: 50
# silent: false
# headers: "X-API-Key: 123444"
# worker_headers: "User-Agent: Deadfinder Bot"
# include30x: false
# user_agent: "Apple"
# proxy: "http://localhost:8070"
- name: Output Handling
run: echo '${{ steps.broken-link.outputs.output }}'
GitHub Actions is a CI/CD (Continuous Integration/Continuous Deployment) tool provided by GitHub, which allows you to automate your software development workflows directly in your repository. Here’s how you can leverage GitHub Actions to automate dead link detection with Deadfinder:
---
name: DeadLink
on:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Find Broken Link
uses: hahwul/[email protected]
id: broken-link
with:
command: sitemap
target: https://hahwul.com/sitemap.xml
- name: Create Markdown Table from JSON
id: create-markdown-table
run: |
echo "## DeadLink Report" > deadlink_report.md
echo "" >> deadlink_report.md
echo "| Target URL | Deadlink |" >> deadlink_report.md
echo "|------------|------------|" >> deadlink_report.md
echo '${{ steps.broken-link.outputs.output }}' | jq -r 'to_entries[] | .key as $k | .value[] | "| \($k) | \(.) |"' >> deadlink_report.md
- name: Read Markdown Table from File
id: read-markdown-table
run: |
table_content=$(cat deadlink_report.md)
echo "TABLE_CONTENT<<EOF" >> $GITHUB_ENV
echo "$table_content" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Create an issue
uses: dacbd/create-issue-action@main
with:
token: ${{ secrets.GITHUB_TOKEN }}
title: DeadLink Issue
body: ${{ env.TABLE_CONTENT }}
This code runs Deadfinder according to specified conditions to identify dead links, converts them into Markdown format, and then posts them as a GitHub issue so that users can be aware of them. This is also applied to the site you’re looking at now, and since there are many articles, I run it periodically to remove dead links.
Github workflow history
Found and reported deadlinks!
You can easily enhance the quality and security of your site with this straightforward method. Give it a try and manage your site using this technique :)