|
180 | 180 | {% if page.fork_ribbon != false %} |
181 | 181 | <!-- Fork ribbon styles + injector --> |
182 | 182 | <style> |
183 | | - /* Ribbon container positioned near top-left or top-right to avoid colliding with the site menu */ |
184 | 183 | .fork-ribbon { |
185 | 184 | position: fixed; |
186 | | - top: 12px; |
| 185 | + top: 0; |
| 186 | + left: 0; |
187 | 187 | z-index: 10000; |
188 | | - pointer-events: none; /* let underlying controls receive clicks except the link */ |
189 | | - overflow: visible; |
| 188 | + pointer-events: none; |
190 | 189 | } |
191 | 190 |
|
192 | 191 | .fork-ribbon a { |
193 | 192 | pointer-events: auto; |
194 | 193 | display: block; |
195 | | - width: 160px; /* width tuned for visibility */ |
196 | | - background: #151513; /* GitHub-like dark ribbon */ |
| 194 | + background: #151513; |
197 | 195 | color: #fff; |
198 | 196 | text-decoration: none; |
199 | 197 | font-weight: 700; |
200 | | - font-size: 13px; |
201 | | - line-height: 1.4; |
202 | | - padding: 6px 0; |
203 | | - text-align: center; |
204 | | - box-shadow: 0 6px 14px rgba(0, 0, 0, 0.2); |
205 | | - border-radius: 2px; |
| 198 | + font-size: 12px; |
| 199 | + line-height: 1; |
| 200 | + padding: 8px 48px; |
| 201 | + transform: translate(-34px, 18px) rotate(-45deg); |
| 202 | + box-shadow: 0 6px 14px rgba(0, 0, 0, 0.22); |
206 | 203 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; |
207 | | - transform-origin: 0 0; |
| 204 | + white-space: nowrap; |
| 205 | + } |
| 206 | + |
| 207 | + .fork-ribbon a:hover, |
| 208 | + .fork-ribbon a:focus { |
| 209 | + background: #0b0b0b; |
208 | 210 | } |
209 | 211 |
|
210 | | - /* Hide ribbon on small screens where it can obstruct content */ |
211 | 212 | @media (max-width: 640px) { |
212 | 213 | .fork-ribbon { display: none; } |
213 | 214 | } |
|
216 | 217 | <script> |
217 | 218 | (function () { |
218 | 219 | function injectForkRibbon() { |
219 | | - // Avoid inserting multiple times |
220 | 220 | if (document.querySelector('.fork-ribbon')) return; |
221 | 221 |
|
222 | | - // Prefer site.social.github (format: owner/repo), fall back to site.github if present |
223 | 222 | var repo = "{{ site.social.github | default: site.github | escape }}"; |
224 | 223 | if (!repo) return; |
225 | 224 |
|
226 | | - var url = 'https://github.com/' + repo; |
227 | | - |
228 | 225 | var container = document.createElement('div'); |
229 | 226 | container.className = 'fork-ribbon'; |
230 | 227 |
|
231 | 228 | var anchor = document.createElement('a'); |
232 | | - anchor.href = url; |
| 229 | + anchor.href = 'https://github.com/' + repo; |
233 | 230 | anchor.target = '_blank'; |
234 | 231 | anchor.rel = 'noopener noreferrer'; |
235 | 232 | anchor.setAttribute('aria-label', 'Fork me on GitHub'); |
236 | | - |
237 | | - // Detect floating site menu to avoid collision |
238 | | - var hasSiteMenu = !!document.querySelector('[data-site-menu]'); |
239 | | - |
240 | | - // Build the inner HTML (SVG icon + text) |
241 | 233 | anchor.textContent = 'Fork me'; |
242 | | - // Ensure visuals match the ribbon CSS and prevent clipping |
243 | | - anchor.style.display = 'inline-block'; |
244 | | - anchor.style.width = '140px'; |
245 | | - anchor.style.textAlign = 'center'; |
246 | | - anchor.style.color = '#fff'; |
247 | | - anchor.style.textDecoration = 'none'; |
248 | | - anchor.style.fontWeight = '700'; |
249 | | - anchor.style.fontSize = '13px'; |
250 | | - anchor.style.padding = '6px 0'; |
251 | | - anchor.style.background = '#151513'; |
252 | | - anchor.style.boxShadow = '0 6px 14px rgba(0, 0, 0, 0.2)'; |
253 | | - anchor.style.borderRadius = '2px'; |
254 | | - anchor.style.fontFamily = '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif'; |
255 | | - |
256 | | - if (hasSiteMenu) { |
257 | | - // Place on left and rotate -45deg |
258 | | - container.style.left = '-44px'; |
259 | | - anchor.style.transform = 'rotate(-45deg)'; |
260 | | - anchor.style.transformOrigin = '0 0'; |
261 | | - } else { |
262 | | - // Place on right and rotate 45deg |
263 | | - container.style.right = '-44px'; |
264 | | - anchor.style.transform = 'rotate(45deg)'; |
265 | | - anchor.style.transformOrigin = '100% 0'; |
266 | | - } |
267 | 234 |
|
268 | 235 | container.appendChild(anchor); |
269 | | - |
270 | | - // If body exists, append normally |
271 | | - if (document.body) { |
272 | | - document.body.appendChild(container); |
273 | | - return; |
274 | | - } |
275 | | - |
276 | | - // If document isn't parsed yet, attempt document.write as a fallback so the element ends up in the document |
277 | | - try { |
278 | | - if (typeof document.write === 'function' && document.readyState === 'loading') { |
279 | | - var posAttr = hasSiteMenu ? 'left:-44px' : 'right:-44px'; |
280 | | - var rotation = hasSiteMenu ? 'transform:rotate(-45deg);transform-origin:0 0;' : 'transform:rotate(45deg);transform-origin:100% 0;'; |
281 | | - var html = '<div class="fork-ribbon" style="top:12px;' + posAttr + '"><a style="display:block;width:140px;' + rotation + 'background:#151513;color:#fff;text-align:center;" href="' + url + '" target="_blank" rel="noopener noreferrer">Fork me</a></div>'; |
282 | | - document.write(html); |
283 | | - return; |
284 | | - } |
285 | | - } catch (e) { |
286 | | - // ignore and continue to last-resort append below |
287 | | - } |
288 | | - |
289 | | - // As a last resort, append to documentElement |
290 | | - (document.documentElement || document).appendChild(container); |
| 236 | + document.body.appendChild(container); |
291 | 237 | } |
292 | 238 |
|
293 | | - // Run immediately if DOM is already available, otherwise wait for DOMContentLoaded. |
294 | 239 | if (document.readyState === 'loading') { |
295 | | - document.addEventListener('DOMContentLoaded', function () { |
296 | | - injectForkRibbon(); |
297 | | - }); |
298 | | - // Also run on window.load to catch pages that defer document modifications |
299 | | - window.addEventListener('load', function () { injectForkRibbon(); }); |
300 | | - // Fallback in case DOMContentLoaded doesn't fire for some reason in certain pages |
301 | | - setTimeout(function () { injectForkRibbon(); }, 3000); |
| 240 | + document.addEventListener('DOMContentLoaded', injectForkRibbon); |
| 241 | + window.addEventListener('load', injectForkRibbon); |
302 | 242 | } else { |
303 | | - try { |
304 | | - injectForkRibbon(); |
305 | | - } catch (e) { |
306 | | - // If anything goes wrong, try again shortly |
307 | | - setTimeout(injectForkRibbon, 3000); |
308 | | - } |
| 243 | + injectForkRibbon(); |
309 | 244 | } |
310 | 245 | })(); |
311 | 246 | </script> |
|
0 commit comments