|
37 | 37 | white-space: nowrap;
|
38 | 38 | }
|
39 | 39 |
|
| 40 | + #table-of-contents { |
| 41 | + padding: 0; |
| 42 | + margin: 0; |
| 43 | + margin-left: 0.5em; |
| 44 | + |
| 45 | + } |
| 46 | + |
| 47 | + .tl1 { |
| 48 | + margin-left: 0em; |
| 49 | + font-size: 90%; |
| 50 | + } |
| 51 | + |
| 52 | + .tl2 { |
| 53 | + margin-left: 0.5em; |
| 54 | + font-size: 85%; |
| 55 | + } |
| 56 | + |
| 57 | + .tl3 { |
| 58 | + margin-left: 1.0em; |
| 59 | + font-size: 80%; |
| 60 | + } |
| 61 | + |
| 62 | + .tl4 { |
| 63 | + margin-left: 1.5em; |
| 64 | + font-size: 75%; |
| 65 | + } |
| 66 | + |
| 67 | + .tl5 { |
| 68 | + margin-left: 2.0em; |
| 69 | + font-size: 75%; |
| 70 | + } |
| 71 | + |
| 72 | + .tl6 { |
| 73 | + margin-left: 2.5em; |
| 74 | + font-size: 75%; |
| 75 | + } |
| 76 | + |
| 77 | + #toc { |
| 78 | + float: right; |
| 79 | + position: sticky; |
| 80 | + top: 0; |
| 81 | + margin-top: 1.5em; |
| 82 | + } |
| 83 | + |
| 84 | + toc .sideitem { |
| 85 | + padding: 0.5em 0.5em; |
| 86 | + } |
| 87 | + |
| 88 | + #toc h2 { |
| 89 | + margin-bottom: 0.5em; |
| 90 | + padding-bottom: 0.0em; |
| 91 | + } |
| 92 | + |
40 | 93 | /*]]>*/
|
41 | 94 | </style>
|
42 | 95 | </head>
|
|
56 | 109 | <script>
|
57 | 110 | //<![CDATA[
|
58 | 111 |
|
59 |
| - generate(); |
60 |
| - |
61 |
| - const targetElement = document.getElementById('markdown-target'); |
62 |
| - const file = new URLSearchParams(window.location.search).get('file'); |
63 |
| - const parts = /(?<org>[^/]+)\/(?<repo>[^/]+)\/(?<branch>[^/]+)\/(?<path>.*)/.exec(file); |
64 | 112 | const repoNames = {
|
65 | 113 | "eclipse-platform/eclipse.platform": "Platform",
|
66 | 114 | "eclipse-platform/eclipse.platform.ui": "Platform UI",
|
| 115 | + "eclipse-platform/www.eclipse.org-eclipse": "Eclipse Website", |
67 | 116 | "eclipse-pde/eclipse.pde": "PDE",
|
68 | 117 | "eclipse-equinox/p2": "Equinox p2",
|
69 | 118 | "eclipse-ide/.github": "Eclipse IDE",
|
70 | 119 | };
|
71 | 120 |
|
| 121 | + const file = new URLSearchParams(window.location.search).get('file'); |
| 122 | + const parts = /(?<org>[^/]+)\/(?<repo>[^/]+)\/(?<branch>[^/]+)\/(?<path>.*)/.exec(file); |
| 123 | + const org = parts == null ? '' : parts.groups.org; |
| 124 | + const repo = parts == null ? '' : parts.groups.repo; |
| 125 | + const branch = parts == null ? '' : parts.groups.branch; |
| 126 | + const path = parts == null ? '' : parts.groups.path; |
| 127 | + |
| 128 | + const selfHosted = repo == 'www.eclipse.org-eclipse'; |
| 129 | + const repoName = parts == null ? '' : repoNames[`${org}/${repo}`]; |
| 130 | + |
| 131 | + defaultAside = toElements(`${markdownAside}`); |
| 132 | + |
| 133 | + if (parts != null && parts.groups.path.endsWith('.md')) { |
| 134 | + tableOfContentsAside = ` |
| 135 | +<div id="toc" class="col-md-6"> |
| 136 | + <aside |
| 137 | + <ul class="ul-left-nav"> |
| 138 | + <div class="sideitem"> |
| 139 | + <h2>Table of Contents</h2> |
| 140 | + <div id="toc-target"> |
| 141 | + </div> |
| 142 | + </div> |
| 143 | + </ul> |
| 144 | + </aside> |
| 145 | +</div>`; |
| 146 | + } |
| 147 | + |
| 148 | + generate(); |
| 149 | + |
| 150 | + const targetElement = document.getElementById('markdown-target'); |
| 151 | + |
72 | 152 | function niceName(name) {
|
73 | 153 | return name.replaceAll(/[_-]/g, ' ').replaceAll(/([a-z])([A-Z])/g, '$1 $2').replace(/^([a-z])/, letter => letter.toLocaleUpperCase())
|
74 | 154 | }
|
|
101 | 181 | targetElement.innerHTML = heading + fileElements.join('');
|
102 | 182 | }
|
103 | 183 |
|
| 184 | + function generateMarkdown(logicalBaseURL, response) { |
| 185 | + if (response instanceof Array) { |
| 186 | + generateFileList(response) |
| 187 | + } else { |
| 188 | + const text = response; |
| 189 | + const editLink = `<a id="edit-markdown-link" href=""><span class="orange">\u270E Improve this page</span></a>\n`; |
| 190 | + marked.use(markedGfmHeadingId.gfmHeadingId()); |
| 191 | + marked.use({ |
| 192 | + hooks: { |
| 193 | + postprocess(html) { |
| 194 | + return `${html}`; |
| 195 | + } |
| 196 | + } |
| 197 | + }); |
| 198 | + targetElement.innerHTML = editLink + marked.parse(text); |
| 199 | + |
| 200 | + |
| 201 | + const headings = markedGfmHeadingId.getHeadingList(); |
| 202 | + const headingText = ` |
| 203 | + <ul id="table-of-contents"> |
| 204 | + ${headings.map(({id, raw, level}) => `<li class="tl${level}"><a href="#${id}">${raw}</a></li>`).join(' ')} |
| 205 | + </ul> |
| 206 | + `; |
| 207 | + document.getElementById('toc-target').replaceChildren(...toElements(headingText)); |
| 208 | + |
| 209 | + const imgs = targetElement.querySelectorAll("img[src]"); |
| 210 | + for (const img of imgs) { |
| 211 | + const src = img.getAttribute('src'); |
| 212 | + if (!src.startsWith('http')) { |
| 213 | + img.src = `https://raw.githubusercontent.com/${org}/${repo}/${branch}/${src}`; |
| 214 | + } |
| 215 | + } |
| 216 | + |
| 217 | + const as = targetElement.querySelectorAll("a[href]"); |
| 218 | + for (const a of as) { |
| 219 | + const href = a.getAttribute('href'); |
| 220 | + if (href == null) { |
| 221 | + continue; |
| 222 | + } |
| 223 | + |
| 224 | + if (href.startsWith('#')) { |
| 225 | + a.setAttribute('href', fixHash(href)); |
| 226 | + continue; |
| 227 | + } |
| 228 | + |
| 229 | + const logicalHref = new URL(href, logicalBaseURL); |
| 230 | + const url = new URL(window.location); |
| 231 | + url.hash = fixHash(logicalHref.hash); |
| 232 | + if (logicalHref.hostname == 'api.github.com') { |
| 233 | + const parts = /\/repos\/(?<org>[^/]+)\/(?<repo>[^/]+)\/contents\/(?<path>.*)/.exec(logicalHref.pathname); |
| 234 | + if (parts != null) { |
| 235 | + url.search = `?file=${parts.groups.org}/${parts.groups.repo}/${branch}/${parts.groups.path}`; |
| 236 | + a.href = url; |
| 237 | + } |
| 238 | + } else if (logicalHref.hostname == 'github.com') { |
| 239 | + const parts = /(?<org>[^/]+)\/(?<repo>[^/]+)\/blob\/(?<branch>[^/]+)\/(?<path>.*)/.exec(logicalHref.pathname); |
| 240 | + if (parts != null) { |
| 241 | + url.search = `?file=${parts.groups.org}/${parts.groups.repo}/${parts.groups.branch}/${parts.groups.path}`; |
| 242 | + a.href = url; |
| 243 | + } |
| 244 | + } |
| 245 | + } |
| 246 | + |
| 247 | + document.getElementById('edit-markdown-link').href = `https://github.com/${org}/${repo}/blob/${branch}/${path}`; |
| 248 | + } |
| 249 | + } |
| 250 | + |
| 251 | + |
104 | 252 | if (parts == null || parts.length == 0) {
|
105 | 253 | targetElement.innerHTML = 'No well-formed query parameter of the form <code>?file=org/repo/branch/path</code> has been specified.';
|
106 | 254 | } else {
|
107 |
| - const org = parts.groups.org; |
108 |
| - const repo = parts.groups.repo; |
109 |
| - const repoName = repoNames[`${org}/${repo}`]; |
110 | 255 | if (repoName == null) {
|
111 | 256 | targetElement.innerHTML = `The repository ${org}/${repo} is not on the allowed list.`;
|
112 | 257 | } else {
|
113 | 258 | document.title = `${repoName} Documentation | Eclipse Project`;
|
114 | 259 |
|
115 |
| - const branch = parts.groups.branch; |
116 |
| - const path = parts.groups.path; |
117 |
| - |
118 | 260 | const breadcrumb = document.querySelector(".breadcrumb");
|
119 | 261 | const normalizedPath = path.replace(/\/$/, '');
|
120 | 262 | const segments = normalizedPath == '' ? [''] : ['', ...normalizedPath.split('/')];
|
|
125 | 267 | }
|
126 | 268 |
|
127 | 269 | const logicalBaseURL = new URL(`https://api.github.com/repos/${org}/${repo}/contents/${path}`);
|
128 |
| - const mdLocation = `${logicalBaseURL}?ref=${branch}`; |
129 |
| - |
130 |
| - sendRequest(mdLocation, request => { |
131 |
| - const response = JSON.parse(request.responseText); |
132 |
| - if (response instanceof Array) { |
133 |
| - generateFileList(response) |
| 270 | + fetch(selfHosted ? `${scriptBase}${path}` : `${logicalBaseURL}?ref=${branch}`).then(response => { |
| 271 | + console.log(response); |
| 272 | + return response.text(); |
| 273 | + }).then(text => { |
| 274 | + if (text.startsWith('<')) { |
| 275 | + console.log('Unsupported'); |
| 276 | + } else if (text.startsWith('{') || text.startsWith('[')) { |
| 277 | + const json = JSON.parse(text); |
| 278 | + generateMarkdown(logicalBaseURL, json instanceof Array ? json : blobToText(json.content)); |
134 | 279 | } else {
|
135 |
| - const text = blobToText(response.content); |
136 |
| - const editLink = `<a id="edit-markdown-link" href=""><span class="orange">\u270E Improve this page</span></a>\n`; |
137 |
| - targetElement.innerHTML = editLink + marked.use(markedGfmHeadingId.gfmHeadingId()).parse(text); |
138 |
| - |
139 |
| - const imgs = targetElement.querySelectorAll("img[src]"); |
140 |
| - for (const img of imgs) { |
141 |
| - const src = img.getAttribute('src'); |
142 |
| - if (!src.startsWith('http')) { |
143 |
| - img.src = `https://raw.githubusercontent.com/${org}/${repo}/${branch}/${src}`; |
144 |
| - } |
145 |
| - } |
146 |
| - |
147 |
| - const as = targetElement.querySelectorAll("a[href]"); |
148 |
| - for (const a of as) { |
149 |
| - const href = a.getAttribute('href'); |
150 |
| - if (href == null) { |
151 |
| - continue; |
152 |
| - } |
153 |
| - |
154 |
| - if (href.startsWith('#')) { |
155 |
| - a.setAttribute('href', fixHash(href)); |
156 |
| - continue; |
157 |
| - } |
158 |
| - |
159 |
| - const logicalHref = new URL(href, logicalBaseURL); |
160 |
| - const url = new URL(window.location); |
161 |
| - url.hash = fixHash(logicalHref.hash); |
162 |
| - if (logicalHref.hostname == 'api.github.com') { |
163 |
| - const parts = /\/repos\/(?<org>[^/]+)\/(?<repo>[^/]+)\/contents\/(?<path>.*)/.exec(logicalHref.pathname); |
164 |
| - if (parts != null) { |
165 |
| - url.search = `?file=${parts.groups.org}/${parts.groups.repo}/${branch}/${parts.groups.path}`; |
166 |
| - a.href = url; |
167 |
| - } |
168 |
| - } else if (logicalHref.hostname == 'github.com') { |
169 |
| - const parts = /(?<org>[^/]+)\/(?<repo>[^/]+)\/blob\/(?<branch>[^/]+)\/(?<path>.*)/.exec(logicalHref.pathname); |
170 |
| - if (parts != null) { |
171 |
| - url.search = `?file=${parts.groups.org}/${parts.groups.repo}/${parts.groups.branch}/${parts.groups.path}`; |
172 |
| - a.href = url; |
173 |
| - } |
174 |
| - } |
175 |
| - } |
176 |
| - |
177 |
| - document.getElementById('edit-markdown-link').href = `https://github.com/${org}/${repo}/blob/${branch}/${path}`; |
| 280 | + generateMarkdown(logicalBaseURL, text); |
178 | 281 | }
|
179 | 282 | });
|
180 | 283 | }
|
|
0 commit comments