From d397e66e039c6704fee10093676ed8146c6fe3bf Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Sun, 8 Jan 2017 21:29:26 -0500 Subject: [PATCH] lint links --- docs/generate.js | 4 +++- docs/lint.js | 18 ++++++++++++++++++ docs/render.md | 2 +- docs/route.md | 6 +++--- docs/stream.md | 2 +- 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/docs/generate.js b/docs/generate.js index 412d7887..cb25f5a4 100644 --- a/docs/generate.js +++ b/docs/generate.js @@ -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)) diff --git a/docs/lint.js b/docs/lint.js index 7a83af80..e92104a1 100644 --- a/docs/lint.js +++ b/docs/lint.js @@ -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 diff --git a/docs/render.md b/docs/render.md index 3218c761..1a0f81d9 100644 --- a/docs/render.md +++ b/docs/render.md @@ -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. diff --git a/docs/route.md b/docs/route.md index b62fed23..d8566215 100644 --- a/docs/route.md +++ b/docs/route.md @@ -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 diff --git a/docs/stream.md b/docs/stream.md index d2585383..fe233f18 100644 --- a/docs/stream.md +++ b/docs/stream.md @@ -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` | Yes | List of streams that were affected by an update **returns** | `any` | | Returns a computed value