[ADF-3809] Added image URL checks and added missing image files (#4054)

* [ADF-3809] Updated file checker with broken image URL hints

* [ADF-3809] Updated rel note images based on file checker
This commit is contained in:
Andy Stark 2018-12-05 16:00:42 +00:00 committed by Eugenio Romano
parent 6f526c3862
commit 21460ce64c
14 changed files with 76 additions and 23 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 654 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 596 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

View File

@ -3,14 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
var path = require("path");
var fs = require("fs");
var unist_util_select_1 = require("unist-util-select");
var lev = require("fast-levenshtein");
var ngHelpers = require("../ngHelpers");
//const angFilenameRegex = /([a-zA-Z0-9\-]+)\.((component)|(directive)|(interface)|(model)|(pipe)|(service)|(widget))/;
var imageFolderPath = path.resolve('docs', 'docassets', 'images');
// Using this value for the edit distance between Markdown image URLs
// and filenames is enough to trap errors like missing out the 'images'
// folder in the path. Keeping it low avoids crazy suggestions.
var maxImagePathLevDistance = 7;
function processDocs(mdCache, aggData, errorMessages) {
var pathnames = Object.keys(mdCache);
var classlessDocs = [];
var linkRefs = {};
var imageRefs = {};
var brokenImageRefs = {};
var filters = makeFilepathFilters(aggData.config["fileCheckerFilter"]);
pathnames.forEach(function (pathname) {
var fileBaseName = path.basename(pathname, '.md');
@ -26,22 +31,15 @@ function processDocs(mdCache, aggData, errorMessages) {
var linkElems = unist_util_select_1.selectAll('link', tree);
linkElems.forEach(function (linkElem) {
var normUrl = normaliseLinkPath(pathname, linkElem.url);
if (linkRefs[normUrl]) {
linkRefs[normUrl].push(pathname);
}
else {
linkRefs[normUrl] = [pathname];
}
multiSetAdd(linkRefs, normUrl, pathname);
});
}
var imageElems = unist_util_select_1.selectAll('image', tree);
imageElems.forEach(function (imageElem) {
var normUrl = normaliseLinkPath(pathname, imageElem.url);
if (imageRefs[normUrl]) {
imageRefs[normUrl].push(pathname);
}
else {
imageRefs[normUrl] = [pathname];
multiSetAdd(imageRefs, normUrl, pathname);
if (!fs.existsSync(normUrl)) {
brokenImageRefs[normUrl] = pathname;
}
});
});
@ -56,6 +54,7 @@ function processDocs(mdCache, aggData, errorMessages) {
}
console.groupEnd();
});
console.log();
var imagePaths = getImagePaths(imageFolderPath);
imagePaths.forEach(function (imagePath) {
if (!imageRefs[imagePath]) {
@ -63,6 +62,20 @@ function processDocs(mdCache, aggData, errorMessages) {
console.log("Warning: no links to image file \"" + relImagePath + "\"");
}
});
console.log();
var brokenImUrls = Object.keys(brokenImageRefs);
brokenImUrls.forEach(function (url) {
var relUrl = url.substring(url.indexOf('docs'));
var relDocPath = brokenImageRefs[url].substring(brokenImageRefs[url].indexOf('docs'));
console.group("Broken image link \"" + relUrl + "\" found in \"" + relDocPath);
imagePaths.forEach(function (imPath) {
if (lev.get(imPath, url) <= maxImagePathLevDistance) {
var relImPath = imPath.substring(imPath.indexOf('docs'));
console.log("Should it be \"" + relImPath + "\"?");
}
});
console.groupEnd();
});
}
exports.processDocs = processDocs;
function normaliseLinkPath(homeFilePath, linkUrl) {
@ -84,3 +97,11 @@ function filterFilepath(filters, filepath) {
}
return false;
}
function multiSetAdd(container, key, value) {
if (container[key]) {
container[key].push(value);
}
else {
container[key] = [value];
}
}

View File

@ -3,12 +3,19 @@ import * as fs from "fs";
import { select, selectAll } from "unist-util-select";
import * as lev from "fast-levenshtein";
import * as ngHelpers from "../ngHelpers";
//const angFilenameRegex = /([a-zA-Z0-9\-]+)\.((component)|(directive)|(interface)|(model)|(pipe)|(service)|(widget))/;
const imageFolderPath = path.resolve('docs', 'docassets', 'images');
// Using this value for the edit distance between Markdown image URLs
// and filenames is enough to trap errors like missing out the 'images'
// folder in the path. Keeping it low avoids crazy suggestions.
const maxImagePathLevDistance = 7;
export function processDocs(mdCache, aggData, errorMessages) {
var pathnames = Object.keys(mdCache);
@ -16,6 +23,7 @@ export function processDocs(mdCache, aggData, errorMessages) {
let classlessDocs = [];
let linkRefs = {};
let imageRefs = {};
let brokenImageRefs = {};
let filters = makeFilepathFilters(aggData.config["fileCheckerFilter"]);
@ -35,12 +43,7 @@ export function processDocs(mdCache, aggData, errorMessages) {
linkElems.forEach(linkElem => {
let normUrl = normaliseLinkPath(pathname, linkElem.url);
if (linkRefs[normUrl]) {
linkRefs[normUrl].push(pathname);
} else {
linkRefs[normUrl] = [ pathname ];
}
multiSetAdd(linkRefs, normUrl, pathname);
});
}
@ -48,11 +51,10 @@ export function processDocs(mdCache, aggData, errorMessages) {
imageElems.forEach(imageElem => {
let normUrl = normaliseLinkPath(pathname, imageElem.url);
multiSetAdd(imageRefs, normUrl, pathname);
if (imageRefs[normUrl]) {
imageRefs[normUrl].push(pathname);
} else {
imageRefs[normUrl] = [ pathname ];
if (!fs.existsSync(normUrl)) {
brokenImageRefs[normUrl] = pathname;
}
});
});
@ -71,6 +73,8 @@ export function processDocs(mdCache, aggData, errorMessages) {
console.groupEnd();
});
console.log();
let imagePaths = getImagePaths(imageFolderPath);
imagePaths.forEach(imagePath => {
@ -79,6 +83,25 @@ export function processDocs(mdCache, aggData, errorMessages) {
console.log(`Warning: no links to image file "${relImagePath}"`);
}
});
console.log();
let brokenImUrls = Object.keys(brokenImageRefs);
brokenImUrls.forEach(url => {
let relUrl = url.substring(url.indexOf('docs'));
let relDocPath = brokenImageRefs[url].substring(brokenImageRefs[url].indexOf('docs'));
console.group(`Broken image link "${relUrl}" found in "${relDocPath}`);
imagePaths.forEach(imPath => {
if (lev.get(imPath, url) <= maxImagePathLevDistance) {
let relImPath = imPath.substring(imPath.indexOf('docs'));
console.log(`Should it be "${relImPath}"?`)
}
});
console.groupEnd();
});
}
@ -106,4 +129,13 @@ function filterFilepath(filters: RegExp[], filepath: string): boolean {
}
}
return false;
}
function multiSetAdd(container: {}, key: string, value: string) {
if (container[key]) {
container[key].push(value);
} else {
container[key] = [ value ];
}
}