Package: linkmedic
A python script for checking links and resources used in local static webpages (.htm,.html), OpenDocument files (.odt,.odp,.ods), and single OpenDocument XML files (.fodt,.fodp,.fods).linkmedicstarts a test webserver, requests entry page from the test webserver and crawls all the local pages. All the links in the tags (<a><img><script><link><iframe><event-listener>) are checked and the dead links are reported. If a link is present in multiple pages, only once it will be tested. By default, links to the external websites are ignored. If there is a.linkignorefile in the website’s root, the links listed in that file will be ignored during the tests (one link per line, see below for examples). After checking all the links if any dead links are discovered,linkmedicexits with a non-zero code.For testing links in dynamic html content e.g. using JS template engines, or other document formats, you must first convert your files [with a thirdparty tool] to static html and then runlinkmedic.Quick startprerequisitesDepending on your operating system, you may have multiple options for installing them:python:linkmedicis only tested onofficially supported python versions.pythonpackage installer: For example,pipInstall linkmedicYou can install thelinkmedicusing your favorite python package installer. For example usingpipyou can download it fromPyPI:pipinstalllinkmedic--userRunTo start a test webserver with files at/var/wwwand crawl the pages and test all the links starting from/var/www/index.htmlpage, run:linkmedic--root=/var/wwwUsage & OptionsMirror package repositoryYou can also installlinkmedicfrom MPCDF GitLab package repository:pipinstalllinkmedic--user--index-urlhttps://gitlab.mpcdf.mpg.de/api/v4/projects/5763/packages/pypi/simpleContainerYou can use one of the container images with required libraries (andlinkmedkittools) already installed in:quay.io/meisam/linkmedic:latestgitlab-registry.mpcdf.mpg.de/tbz/linkmedic:latestYou can access a specific version onlinkmedicusing container tags e.g.linkmedic:v0.7.4instead oflinkmedic:latest. See all available container tagshere.Using a container image,linkmedic’s test webserver needs to have access to the files for your website pages from inside the container. Depending on your container engine, you may need to mount the path to your files inside the container. For example, usingpodman:podmanrun--volume/www/public:/testquay.io/meisam/linkmedic:latestlinkmedic--root=/testHere,--volume/www/public:/testflag mounts/www/publicinside the container at/testpath.CI/CDYou can also use the container image in your CI/CD pipelines. For example, for GitLab CI in.gitlab-ci.yml:test_internal_links:image:quay.io/meisam/linkmedic:latestscript:-linkmedic --root=/var/www/ --entry=index.html --warn-http --with-badgeafter_script:-gitlab_badge_sticker.shor for Woodpecker CI in.woodpecker.yml:test_internal_links:image:quay.io/meisam/linkmedic:latestcommands:-linkmedic --root=/var/www/ --entry=index.html --warn-httpIf you want to check the external links of your website in CI, you must avoid running multiple tests in a short period of time, e.g. on each commit of the development branches. Otherwise, the IP of your CI runners may get banned by external web servers. For example, in GitLab CI you can limit the external link checks only to the default branch of your git repository:test_external_links:image:quay.io/meisam/linkmedic:latestrules:-if:$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCHscript:-linkmedic --root=/var/www/ --ignore-local --with-badgeafter_script:-gitlab_badge_sticker.shallow_failure:truePlease note thatgitlab_badge_sticker.shscript used in these examples requires an API access token with maintainer permissionCI_API_TOKENto modify the badges. Seelinkmedkit documentationfor more details.CLI referenceDisplay help. Will show all the command line options and their default values.linkmedic-hStart the webserver with the current directory as the root path of the server. Starting fromindex.htmlcrawl the pages and test all the links.linkmedicStart the webserver with./tests/public1/as the root path of the server. Starting fromindex.htmlcrawl the pages and test all the links.linkmedic--root=./tests/public1/Start the webserver with./tests/public1/as the root path of the server. Starting fromindex2.htmlcrawl the pages and test all the links. Entry point should be relative to the server root. (in the example below,index2.htmlshould be accessible at./tests/public1/index2.html)linkmedic--root=./tests/public1/--entry=index2.htmlConfigure test webserver not to redirect missing pages (/directory/pageto/directory/page.html).linkmedic--no-redirectCheck links to external websites.[IMPORTANT: You must avoid running the link checker on external links multiple times in a short period of time, e.g. on each commit of the develop branch. Otherwise, IP of your machine (or CI runners) may get banned by the CDN or the DoS mitigation solution of the external webservers. SeeCI/CD sectionfor a solution.]linkmedic--check-externalIgnore local dead links [and activates external link checking].linkmedic--ignore-localDo not consider the external links which return HTTP status codes 403 and 503 as dead links.linkmedic--ignore-status403503Check links in an OpenDocument file (.odt,.odp,.ods), or a single OpenDocument XML file (.fodt,.fodp,.fods).linkmedic--entry=./presentation.odpShow warning for HTTP links.linkmedic--warn-httpIf any link tomydomain.comis encountered, treat them as internal links and resolve locally.linkmedic--domain=mydomain.comStart the webserver on port 3000. If the webserver could not be started on the requested port, the initializer will automatically try the next ports.linkmedic--port=3000Generate badge information file. Depending on the type of diagnosis, this file will be namedbadge.dead_internal_links.json,badge.dead_external_links.json, orbadge.dead_links.json. if--warn-httpflag is used, a badge file for the number of discovered HTTP links will be also written tobadge.http_links.jsonfile. These files can be used to generate badges (seelinkmedkitscripts) or to serve forshields.io endpointresponse.linkmedic--with-badgeCheck the links but always exit with code 0.linkmedic--exit-zeroLog the output in a different level of verbosity. If more than one of these flags are defined, the most restrictive one will be in effect.--verbose: log debug information--quiet: only log errors--silent: completely silence the output logsExample .linkignoreinvalidfile.tar.gzwill_add/later.htmlhttps://not.accessible.comDevelopmentThis project is usingPDMfor packaging and dependency management,verminandbanditfor validation,blackandisortfor styling, andjsonschemaandjqfor testing. Seedevelopers guidefor more details.HistoryThe original idea of this project is from Dr. Klaus Reuter (MPCDF). Fruitful discussions with Dr. Sebastian Kehl (MPCDF) facilitated this project’s packaging and release.Accompanying tools for thelinkmedichave been moved to a separate repository (linkmedkit) in version 0.7.LicenseCopyright 2021-2023 M. Farzalipour Tabriz, Max Planck Computing and Data Facility (MPCDF)Copyright 2023-2024 M. Farzalipour Tabriz, Max Planck Institute for Physics (MPP)All rights reserved.This software may be modified and distributed under the terms of the 3-Clause BSD License. See the LICENSE file for details.