|
| 1 | +const types = require("../types"); |
| 2 | + |
| 3 | +const beforeGenerateToc = function ({ |
| 4 | + $, |
| 5 | + relativePath, |
| 6 | + addDashAnchor, |
| 7 | + docset, |
| 8 | +}) {}; |
| 9 | + |
| 10 | +const generateToc = function ({ |
| 11 | + $, |
| 12 | + relativePath, |
| 13 | + addDashAnchor, |
| 14 | + insertToDb, |
| 15 | + docset, |
| 16 | +}) { |
| 17 | + let titleElement = $(".header h1"); |
| 18 | + if (titleElement.length > 0) { |
| 19 | + let title = $(titleElement).text().trim(); |
| 20 | + if ( |
| 21 | + title.startsWith("Package") || |
| 22 | + title.startsWith("Uses of Package") || |
| 23 | + title.startsWith("Hierarchy For Package") || |
| 24 | + title.startsWith("模块") |
| 25 | + ) { |
| 26 | + return; |
| 27 | + } |
| 28 | + insertToDb({ |
| 29 | + name: title, |
| 30 | + type: types.Guide, |
| 31 | + path: relativePath, |
| 32 | + }); |
| 33 | + return; |
| 34 | + } |
| 35 | + let title = $(".header h2").text().trim(); |
| 36 | + $('> a[id]:not([id="field.detail"])', $('[id="field.detail"]').parent()).each( |
| 37 | + (index, element) => { |
| 38 | + let nextElement = $(element).next(); |
| 39 | + if (nextElement.length <= 0 || nextElement.get(0).tagName === "a") { |
| 40 | + return; |
| 41 | + } |
| 42 | + let fieldName = `${$("h4", nextElement).text().trim()} (${title})`; |
| 43 | + addDashAnchor({ |
| 44 | + element: $("code", element), |
| 45 | + title: element.attribs.id, |
| 46 | + type: types.Field, |
| 47 | + num: 0, |
| 48 | + }); |
| 49 | + insertToDb({ |
| 50 | + name: fieldName, |
| 51 | + type: types.Field, |
| 52 | + path: `${relativePath}#${encodeURIComponent(element.attribs.id)}`, |
| 53 | + }); |
| 54 | + if ($("pre", $(element).next()).text().indexOf("final") !== -1) { |
| 55 | + addDashAnchor({ |
| 56 | + element: $("code", element), |
| 57 | + title: element.attribs.id, |
| 58 | + type: types.Constant, |
| 59 | + num: 0, |
| 60 | + }); |
| 61 | + insertToDb({ |
| 62 | + name: fieldName, |
| 63 | + type: types.Constant, |
| 64 | + path: `${relativePath}#${encodeURIComponent(element.attribs.id)}`, |
| 65 | + }); |
| 66 | + } |
| 67 | + } |
| 68 | + ); |
| 69 | + $( |
| 70 | + '> a[id]:not([id="constructor.detail"])', |
| 71 | + $('[id="constructor.detail"]').parent() |
| 72 | + ).each((index, element) => { |
| 73 | + let nextElement = $(element).next(); |
| 74 | + if (nextElement.length <= 0 || nextElement.get(0).tagName === "a") { |
| 75 | + return; |
| 76 | + } |
| 77 | + let constructorName = `${$("h4", nextElement).text().trim()} (${title})`; |
| 78 | + addDashAnchor({ |
| 79 | + element: $("code", element), |
| 80 | + title: element.attribs.id, |
| 81 | + type: types.Constructor, |
| 82 | + num: 0, |
| 83 | + }); |
| 84 | + insertToDb({ |
| 85 | + name: constructorName, |
| 86 | + type: types.Constructor, |
| 87 | + path: `${relativePath}#${encodeURIComponent(element.attribs.id)}`, |
| 88 | + }); |
| 89 | + }); |
| 90 | + $( |
| 91 | + '> a[id]:not([id="method.detail"])', |
| 92 | + $('[id="method.detail"]').parent() |
| 93 | + ).each((index, element) => { |
| 94 | + let nextElement = $(element).next(); |
| 95 | + if (nextElement.length <= 0 || nextElement.get(0).tagName === "a") { |
| 96 | + return; |
| 97 | + } |
| 98 | + let methodName = `${$("h4", nextElement).text().trim()} (${title})`; |
| 99 | + addDashAnchor({ |
| 100 | + element: $("code", element), |
| 101 | + title: element.attribs.id, |
| 102 | + type: types.Method, |
| 103 | + num: 0, |
| 104 | + }); |
| 105 | + insertToDb({ |
| 106 | + name: methodName, |
| 107 | + type: types.Method, |
| 108 | + path: `${relativePath}#${encodeURIComponent(element.attribs.id)}`, |
| 109 | + }); |
| 110 | + }); |
| 111 | +}; |
| 112 | + |
| 113 | +const beforeFilter = function ({ $, relativePath, addDashAnchor, docset }) {}; |
| 114 | + |
| 115 | +const filter = function ({ $, relativePath, addDashAnchor, docset }) {}; |
| 116 | + |
| 117 | +const afterFilter = function ({ $, relativePath, addDashAnchor, docset }) {}; |
| 118 | + |
| 119 | +module.exports = { |
| 120 | + name: "java", |
| 121 | + displayName: "Java", |
| 122 | + platformFamily: "Java", |
| 123 | + entry: "index.html", |
| 124 | + domain: "", |
| 125 | + include: [], |
| 126 | + exclude: [], |
| 127 | + indexGenerator: [ |
| 128 | + { |
| 129 | + file: "allpackages-index.html", |
| 130 | + generateToc: function ({ |
| 131 | + $, |
| 132 | + relativePath, |
| 133 | + addDashAnchor, |
| 134 | + insertToDb, |
| 135 | + docset, |
| 136 | + }) { |
| 137 | + $(".overviewSummary th.colFirst:has(a)").each((index, element) => { |
| 138 | + let title = $(element).text().trim(); |
| 139 | + insertToDb({ |
| 140 | + name: title, |
| 141 | + type: types.Module, |
| 142 | + path: $("a:first-child", element).attr("href"), |
| 143 | + }); |
| 144 | + }); |
| 145 | + }, |
| 146 | + }, |
| 147 | + { |
| 148 | + file: "allpackages-index.html", |
| 149 | + generateToc: function ({ |
| 150 | + $, |
| 151 | + relativePath, |
| 152 | + addDashAnchor, |
| 153 | + insertToDb, |
| 154 | + docset, |
| 155 | + }) { |
| 156 | + $(".packagesSummary th.colFirst:has(a)").each((index, element) => { |
| 157 | + let title = $(element).text().trim(); |
| 158 | + insertToDb({ |
| 159 | + name: title, |
| 160 | + type: types.Package, |
| 161 | + path: $("a:first-child", element).attr("href"), |
| 162 | + }); |
| 163 | + }); |
| 164 | + }, |
| 165 | + }, |
| 166 | + { |
| 167 | + file: "allclasses-index.html", |
| 168 | + generateToc: function ({ |
| 169 | + $, |
| 170 | + relativePath, |
| 171 | + addDashAnchor, |
| 172 | + insertToDb, |
| 173 | + docset, |
| 174 | + }) { |
| 175 | + $(".typeSummary td.colFirst:has(a)").each((index, element) => { |
| 176 | + let type = $("a:first-child", element).attr("title").split(" in")[0]; |
| 177 | + let title = $(element).text().trim(); |
| 178 | + if (type === "interface") { |
| 179 | + type = types.Interface; |
| 180 | + } else if (type === "class") { |
| 181 | + if ( |
| 182 | + title.endsWith("Exception") || |
| 183 | + title.endsWith("Warning") || |
| 184 | + title === "异常" |
| 185 | + ) { |
| 186 | + type = types.Exception; |
| 187 | + } else if (title.endsWith("Error") || title === "ThreadDeath") { |
| 188 | + type = types.Error; |
| 189 | + } else { |
| 190 | + type = types.Class; |
| 191 | + } |
| 192 | + } else if (type === "enum") { |
| 193 | + type = types.Enum; |
| 194 | + } else if (type === "annotation") { |
| 195 | + type = types.Annotation; |
| 196 | + } |
| 197 | + insertToDb({ |
| 198 | + name: title, |
| 199 | + type: type, |
| 200 | + path: $("a:first-child", element).attr("href"), |
| 201 | + }); |
| 202 | + }); |
| 203 | + }, |
| 204 | + }, |
| 205 | + ], |
| 206 | + generator: [ |
| 207 | + { |
| 208 | + pattern: /.*/g, |
| 209 | + beforeGenerateToc, |
| 210 | + generateToc, |
| 211 | + filter, |
| 212 | + beforeFilter, |
| 213 | + afterFilter, |
| 214 | + }, |
| 215 | + ], |
| 216 | +}; |
0 commit comments