angular/aio/tools/transforms/angular-base-package/processors/checkAbsoluteAioLinks.js
Matthieu Riegler bad7bae468 docs(docs-infra): Warning message when using absolute links to aio in the documentation (#50213)
This commit adds a processor to check for absolute links to angular.io. Absolute links to aio should be avoided because they will appear as external links.

PR Close #50213
2023-05-10 14:29:50 -07:00

26 lines
882 B
JavaScript

/**
* @dgProcessor checkAioAbsoluteLinks
* @description
* Searches for absolute links to aio.
* Absolute links are to be avoided because they appear as external links and won't point to the
* currently visited version of the docs
*/
module.exports = function checkAioAbsoluteLinks(log, createDocMessage) {
return {
$runAfter: ['inlineTagProcessor'],
$runBefore: ['convertToJsonProcessor'],
$process: function (docs) {
docs
.filter((doc) => !doc.fileInfo?.relativePath?.endsWith('json'))
.forEach((doc) => {
const matches = [...doc.renderedContent.matchAll(/href="(https:\/\/angular.io\/.*?)"/g)];
if (matches.length > 0) {
log.warn(createDocMessage('AIO link', doc));
matches.forEach(([, group]) => {
log.warn(`${group}`);
});
}
});
},
};
};