linkisgood
v0.0.1
Published
Verify links are not broken among local html files.
Downloads
95
Readme
linkisgood
Verify links are not broken among local html files. This is used validate links in html files used for static web sites. Though not generally useful, this package modularises the behaviour used by my own personal applications.
To explain, assume the following file exists,
/build/about/index.html
<!DOCTYPE html>
<head>
<title>static site</title>
<meta name="description" content="description of site">
<meta charset="utf-8">
<link href="/favicon.svg" rel="icon" type="image/svg+xml" />
</head>
<body>
<div id="root" class="root">
<a href="https://www.google.com">google</a>
<a href="/about/index.html">about</a>
<a href="/index.html">home</a>
<a href="/faq/index.html">FAQ</a>
</div>
<noscript>javacript required</noscript>
</body>
</html>
Call linkisgood
on a list of filepaths that includes the filepath above,
verifylinks.js
import linkisgood from 'linkisgood'
// for each filepath
// * read file,
// * parse link urls from file,
// * verify each url, remote or local,
// * return `true` OR throw error for invalid file
await linkisgood([
'./build/about/index.html',
'./build/faq/index.html',
'./build/index.html'
], './build/')
The call returns true
when https://www.google.com
responds to a HEAD fetch request and when files are found in the "build" directory for each "local" link. Otherwise, the call throws an error.
public prefix
Someties files are served from a "public prefix". Free hosting from gitlab and github pages work this way. For example, gitlab serves files from the /public/*
directory to requests on "public prefix" /myproject/*
. In this case, each "local" link corresponds to a local filepath that does not include /myproject/
,
<a href="/myproject/about/index.html">
maps to ./public/about/index.html
</a>
Specify a prefix using the third parameter to linkisgood
as follows,
await linkisgood([
'./build/about/index.html',
'./build/faq/index.html',
'./build/index.html'
], './build/', '/myproject/')
(The MIT License)
Copyright (c) [Bumblehead][0] [email protected]
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.