broken links
v0.3.0-rc1
該工具刮擦指定URL中的所有頁面,並檢查目標鏈接是否存在。它報告了原始頁面,錨的文本,目標網址以及鏈接是否正常工作。如果任何鏈接不起作用,該工具將使用錯誤代碼退出。它還提供了分析的摘要。
它可以作為GitHub操作,命令行工具和Docker容器運行。
該工具也可以用作GITHUB操作,以自動檢查存儲庫中的鏈接。
url (可選):開始從中刮除的基本URL。默認值為http://localhost:4444/ 。only-errors (可選):如果設置為true,則只顯示錯誤。默認值為false 。ignore-file (可選):忽略文件的路徑。默認值為./check-ignore 。如果設置了參數並且不存在文件,則操作將帶有錯誤。有關更多信息,請參見上面的忽略文件格式部分。忽略文件應每行包含一個URL模式。模式可以包括通配符(*)以匹配多個URL。這裡有一些例子:
http://example.com/ignore-this-page忽略此特定URL。http://example.com/ignore/* - 忽略以http://example.com/ignore/開頭的所有URL。*/ignore-this-path/* - 忽略所有包含/ignore-this-path/ URL。https://*.domain.com* - 忽略domain.com的所有子域,例如https://sub.domain.com或https://sub2.domain.com/page ,等等。此操作不會產生任何輸出。但是,在分析結束時,它以:
name : Broken-links Checker
on : [push]
jobs :
check-links :
runs-on : ubuntu-latest
steps :
- name : Checkout repository
uses : actions/checkout@v2
- name : Run Link Checker
uses : merlos/[email protected]
with :
url : ' http://example.com '
only-errors : ' true ' name : MkDocs Preview and Link Check
on :
push :
branches :
- main
jobs :
preview_and_check :
runs-on : ubuntu-latest
steps :
- name : Checkout repository
uses : actions/checkout@v2
- name : Set up Python
uses : actions/setup-python@v2
with :
python-version : ' 3.x '
- name : Install dependencies
run : |
python -m pip install --upgrade pip
pip install mkdocs mkdocs-material
- name : Run MkDocs server
run : mkdocs serve -a 0.0.0.0:4444 &
continue-on-error : true
- name : Wait for server to start
run : sleep 10
- name : Run Link Checker
uses : merlos/[email protected]
with :
url : ' http://localhost:4444 '
only-errors : ' true '
ignore-file : ' ./check-ignore ' name : Quarto Preview and Link Check
on :
push :
branches :
- main
jobs :
preview_and_check :
runs-on : ubuntu-latest
steps :
- name : Checkout repository
uses : actions/checkout@v2
- name : Set up Quarto
uses : quarto-dev/quarto-actions/setup@v2
- name : Render Quarto project
run : quarto preview --port 444 &
continue-on-error : true
- name : Wait for server to start
run : sleep 10
- name : Run Link Checker
uses : merlos/[email protected]
with :
url : ' http://localhost:444 '
only-errors : ' true '
ignore-file : ' ./check-ignore ' 安裝軟件包:
pip install broken-links使用broken-links命令:
broken-links http://example.com --only-error --ignore-file ./check-ignore命令行參數:
url (可選):開始從中刮除的基本URL。默認值為http://localhost:4444/ 。--only-error或-o (可選):如果設置,則僅顯示錯誤。默認值為false 。--ignore-file或-i (可選):忽略文件的路徑。默認值為./check-ignore 。如果未設置參數並且不存在文件,它將檢查所有鏈接。如果設置了參數並且不存在文件,則該工具將帶有錯誤。上面的[忽略文件格式(#ighore-file-format)部分以忽略文件的格式說明。
Docker圖像是為這些體系結構構建的: arm64 , amd64和arm7 ,並已在Docker-Hub和Github容器中發行了
docker pull merlos/broken-links:latest
# or from GitHub Container Registry
docker pull ghcr.io/merlos/broken-links:latestdocker run -ti merlos/broken-links https://www.example.com該論點與上面解釋的命令行( url , --only-error , --ignore-file )相同。 docker Run使用的-ti選項顯示命令的輸出。
為了使用--ignore-file參數,您需要安裝卷。例如:
docker run -ti -v /path/on/host/to/ignore-file:/ignore-file merlos/broken-links https://www.example.com --ignore-file /ignore-file它是使用Python開發的。因此,您需要在系統中安裝Python。
克隆存儲庫:
git clone https://github.com/merlos/broken-links
cd broken-links設置虛擬環境:
python -m venv venv
source venv/bin/activate在編輯模式( -e )中安裝軟件包
pip install -e .開始編碼!
docker build -t broken-links . docker run --rm broken-links http://example.com --only-error 要運行測試,請使用以下命令:
python -m unittest discover tests分叉並發送拉動請求。請更新/添加單元測試。
該項目已根據Merlos的GNU通用公共許可證v3.0的條款許可。