Created
May 2, 2020 19:43
-
-
Save halkeye/ac8d97796ede68770c9db2b92d616774 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable no-console */ | |
const axios = require('axios'); | |
const escapeStringRegexp = require('escape-string-regexp'); | |
const {parse:parseUrl} = require('url'); | |
const requestGET = (url) => { | |
return axios | |
.get(url) | |
.then((results) => { | |
if (results.status !== 200) { | |
throw results.data; | |
} | |
return results.data; | |
}); | |
}; | |
const pluginWikiUrlRe = /^https?:\/\/wiki.jenkins(?:-ci.org|.io)\/display\/(?:jenkins|hudson)\/([^/]*)\/?$/i; | |
requestGET('https://updates.jenkins.io/current/plugin-documentation-urls.json').then(urls => { | |
for (const [key, {url}] of Object.entries(urls)) { | |
if (!pluginWikiUrlRe.test(url)) { continue; } | |
const [other, page] = url.match(pluginWikiUrlRe); | |
console.log(`RewriteCond %{HTTP_USER_AGENT} !^jenkins-wiki-exporter/(.*)$`) | |
console.log(`RewriteRule "^${escapeStringRegexp(parseUrl(other).pathname).replace(/\+/g, '\+')}$" "https://plugins.jenkins.io/${key}" [NC,L,QSA,R=301]`); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment