lint links

This commit is contained in:
Leo Horie 2017-01-08 21:29:26 -05:00
parent e4d69c409a
commit d397e66e03
5 changed files with 26 additions and 6 deletions

View file

@ -37,7 +37,9 @@ function generate(pathname) {
var modified = guides.match(link) ? guides.replace(link, replace) : methods.replace(link, replace)
return title + modified + "\n\n"
})
.replace(/\.md/gim, ".html") // fix links
.replace(/(\[[^\]]+)(\.md)/gim, function(match, path, extension) {
return path + (path.match(/http/) ? extension : ".html")
}) // fix links
var html = layout
.replace(/\[version\]/, version) // update version
.replace(/\[body\]/, marked(fixed))

View file

@ -2,6 +2,8 @@
var fs = require("fs")
var path = require("path")
var http = require("http")
var url = require("url")
//lint rules
function lint(file, data) {
@ -9,6 +11,7 @@ function lint(file, data) {
ensureCodeIsSyntaticallyValid(file, data)
ensureCodeIsRunnable(file, data)
ensureCommentStyle(file, data)
ensureLinkIsValid(file, data)
}
function ensureCodeIsHighlightable(file, data) {
@ -82,6 +85,21 @@ function ensureCommentStyle(file, data) {
})
}
function ensureLinkIsValid(file, data) {
var links = data.match(/\]\(([^\)]+)\)/gim)
links.forEach(function(match) {
var link = match.slice(2, -1)
var path = link.match(/[\w-]+\.md/)
if (link.match(/http/)) {
var u = url.parse(link)
http.request({method: "HEAD", host: u.host, path: u.pathname, port: 80}).on("error", function(r) {
console.log(file + " - broken external link: " + link)
})
}
else if (path && !fs.existsSync("docs/" + path)) console.log(file + " - broken link: " + link)
})
}
function initMocks() {
global.window = require("../test-utils/browserMock")()
global.document = window.document

View file

@ -54,7 +54,7 @@ In contrast, traversing a javascript data structure has a much more predictable
### Differences from other API methods
`m.render()` method is internally called by [`m.mount()`](mount.md), [`m.route()`](route.md), [`m.redraw()`](redraw.md) and [`m.request()`](request.md). It is not called by [`m.prop()`](prop.md)
`m.render()` method is internally called by [`m.mount()`](mount.md), [`m.route()`](route.md), [`m.redraw()`](redraw.md) and [`m.request()`](request.md). It is not called after [stream updates](stream.md)
Unlike with `m.mount()` and `m.route()`, a vnode tree rendered via `m.render()` does not auto-redraw in response to view events, `m.redraw()` calls or `m.request()` calls. It is a low level mechanism suitable for library authors who wish to manually control rendering instead of relying on Mithril's built-in auto-redrawing system.

View file

@ -89,13 +89,13 @@ Argument | Type | Required | Description
##### m.route.prefix
Defines a router prefix. The router prefix is a fragment of the URL that dictates the underlying [strategy](routing-strategies.md) used by the router.
Defines a router prefix. The router prefix is a fragment of the URL that dictates the underlying [strategy](#routing-strategies) used by the router.
`m.route.prefix(prefix)`
Argument | Type | Required | Description
----------------- | --------- | -------- | ---
`prefix` | `String` | Yes | The prefix that controls the underlying [routing strategy](#routing-strategy) used by Mithril.
`prefix` | `String` | Yes | The prefix that controls the underlying [routing strategy](#routing-strategies) used by Mithril.
**returns** | | | Returns `undefined`
##### m.route.link
@ -333,7 +333,7 @@ This way, if the user searches and presses the back button to return to the appl
### Changing router prefix
The router prefix is a fragment of the URL that dictates the underlying [strategy](routing-strategies.md) used by the router.
The router prefix is a fragment of the URL that dictates the underlying [strategy](#routing-strategies) used by the router.
```javascript
// set to pathname strategy

View file

@ -83,7 +83,7 @@ Specifies how the value of a computed stream is generated. See [combining stream
Argument | Type | Required | Description
------------ | -------------------- | -------- | ---
`streams...` | splat of `Stream`s | No | Splat of zero or more streams that correspond to the streams passed as the second argument to [`stream.combine`](#stream-combine.md)
`streams...` | splat of `Stream`s | No | Splat of zero or more streams that correspond to the streams passed as the second argument to [`stream.combine`](#stream-combine)
`changed` | `Array<Stream>` | Yes | List of streams that were affected by an update
**returns** | `any` | | Returns a computed value