|
| 1 | +if (window.DOCSIFY_ROUTER_MODE === "history") { |
| 2 | + var clink = document.createElement("link") |
| 3 | + clink.rel = "canonical" |
| 4 | + document.getElementsByTagName("head")[0].appendChild(clink) |
| 5 | +} |
| 6 | + |
| 7 | +var documentTitleBase = document.title; |
| 8 | + |
| 9 | +var gitterURL = "https://gitter.im/imgproxy/imgproxy"; |
| 10 | +var gitterBadgeURL = "https://img.shields.io/gitter/room/imgproxy/imgproxy" + |
| 11 | + "?color=1775d3&style=for-the-badge&logo=gitter"; |
| 12 | +var gitterBadge = '<div class="gitter">' + |
| 13 | + '<a class="gitter-link" href="' + gitterURL + '" target="_blank">' + |
| 14 | + '<img alt="Chat on Gitter" src="' + gitterBadgeURL + '">' + |
| 15 | + '</div></a>'; |
| 16 | + |
| 17 | +var docEditBase = 'https://github.com/imgproxy/imgproxy/edit/master/docs/'; |
| 18 | + |
| 19 | +var proBadge = document.createElement("img") |
| 20 | +proBadge.setAttribute("src", "/assets/pro.svg") |
| 21 | +proBadge.setAttribute("title", "This feature is available in imgproxy Pro") |
| 22 | + |
| 23 | +var proBadgeRegex = /\!\[pro\]\((\S+)\)/g; |
| 24 | +var proLink = '<a class="badge" href="https://imgproxy.net/#pro" target="_blank">' + |
| 25 | + proBadge.outerHTML + '</a>'; |
| 26 | + |
| 27 | +var oldProBadge = "<i class='badge badge-pro'></i>"; |
| 28 | + |
| 29 | +var versions = ["latest"].concat(window.IMGPROXY_VERSIONS); |
| 30 | +var latestVersion = window.IMGPROXY_VERSIONS[0]; |
| 31 | +var versionSelect = '<select id="version-selector" name="version" class="sidebar-version-select">'; |
| 32 | +versions.forEach(function (version) { |
| 33 | + var value = version == latestVersion ? "" : version; |
| 34 | + versionSelect = versionSelect + '<option value="' + value + '">' + version + '</value>'; |
| 35 | +}); |
| 36 | +versionSelect = versionSelect + '</select>'; |
| 37 | + |
| 38 | +window.$docsify = { |
| 39 | + name: '<a id="home-link" class="app-name-link" href="/"><img src="/assets/logo.svg"></a>' + |
| 40 | + gitterBadge + |
| 41 | + versionSelect, |
| 42 | + nameLink: false, |
| 43 | + repo: 'https://github.com/imgproxy', |
| 44 | + loadSidebar: true, |
| 45 | + subMaxLevel: 2, |
| 46 | + auto2top: true, |
| 47 | + routerMode: window.DOCSIFY_ROUTER_MODE || "hash", |
| 48 | + noEmoji: true, |
| 49 | + alias: { |
| 50 | + '/latest/': 'README.md', |
| 51 | + '/latest/(.*)': '$1', |
| 52 | + '/([0-9]+\.[0-9]+)/(.*)': 'https://raw.githubusercontent.com/imgproxy/imgproxy/v$1.0/docs/$2', |
| 53 | + '/([0-9]+\.[0-9]+)/': 'https://raw.githubusercontent.com/imgproxy/imgproxy/v$1.0/docs/README.md', |
| 54 | + '/(.*)': 'https://raw.githubusercontent.com/imgproxy/imgproxy/v' + latestVersion + '.0/docs/$1', |
| 55 | + '/': 'https://raw.githubusercontent.com/imgproxy/imgproxy/v' + latestVersion + '.0/docs/README.md', |
| 56 | + }, |
| 57 | + search: { |
| 58 | + namespace: 'docs-imgproxy', |
| 59 | + depth: 6, |
| 60 | + pathNamespaces: versions.map(function (v) { return "/" + v }) |
| 61 | + }, |
| 62 | + namespaces: [ |
| 63 | + { |
| 64 | + id: "version", |
| 65 | + values: versions, |
| 66 | + optional: true, |
| 67 | + selector: "#version-selector" |
| 68 | + } |
| 69 | + ], |
| 70 | + plugins: [ |
| 71 | + function (hook, vm) { |
| 72 | + window.DocsifyVM = vm |
| 73 | + hook.beforeEach(function () { |
| 74 | + if (clink) { |
| 75 | + clink.href = "https://docs.imgproxy.net" + vm.route.path |
| 76 | + } |
| 77 | + }); |
| 78 | + |
| 79 | + hook.doneEach(function () { |
| 80 | + var appNameLink = Docsify.dom.find("#home-link"); |
| 81 | + |
| 82 | + if (!appNameLink) return; |
| 83 | + |
| 84 | + appNameLink.href = vm.config.currentNamespace; |
| 85 | + }); |
| 86 | + |
| 87 | + hook.doneEach(function() { |
| 88 | + if (document.title != documentTitleBase) |
| 89 | + document.title += " | " + documentTitleBase; |
| 90 | + }); |
| 91 | + |
| 92 | + |
| 93 | + hook.afterEach(function (html) { |
| 94 | + var docName = vm.route.file.replace( |
| 95 | + /https\:\/\/raw.githubusercontent\.com\/(.*)\/docs\//, '' |
| 96 | + ) |
| 97 | + |
| 98 | + if (!docName) { |
| 99 | + return html; |
| 100 | + } |
| 101 | + |
| 102 | + var editButton = '<a class="github-edit-btn" title="Edit on GitHub" href="' + |
| 103 | + docEditBase + docName + |
| 104 | + '" target="_blank">' + |
| 105 | + 'Edit on <strong>GitHub</strong>' + |
| 106 | + '</a>'; |
| 107 | + |
| 108 | + return html + editButton |
| 109 | + }) |
| 110 | + |
| 111 | + hook.beforeEach(function (content, next) { |
| 112 | + content = content.replaceAll(proBadgeRegex, proLink) |
| 113 | + content = content.replaceAll(oldProBadge, proLink) |
| 114 | + console.log(content) |
| 115 | + next(content) |
| 116 | + }) |
| 117 | + |
| 118 | + hook.doneEach(function () { |
| 119 | + var badges = Docsify.dom.findAll(".sidebar .badge-pro") |
| 120 | + badges.forEach(function (b) { b.replaceWith(proBadge.cloneNode()) }) |
| 121 | + |
| 122 | + // Docsify cuts off "target" sometimes |
| 123 | + var links = Docsify.dom.findAll("a.badge") |
| 124 | + links.forEach(function(l){ l.setAttribute("target", "_blank") }) |
| 125 | + }) |
| 126 | + } |
| 127 | + ] |
| 128 | +} |
0 commit comments