MCPcopy Create free account
hub / github.com/arfct/itty-bitty / updateLink

Function updateLink

docs/edit.js:343–391  ·  view source on GitHub ↗
(url, metadata, push)

Source from the content-addressed store, hash-verified

341
342let bittyLink = undefined;
343function updateLink(url, metadata, push) {
344
345 let title = metadata.title;
346
347 let includeMetadata = !metadata.includeMetadata;
348 let path = includeMetadata ? "/" : bitty.metadataToPath(metadata) ?? "/";
349 let prefix = includeMetadata ? bitty.encodePrettyComponent(title) : "";
350
351 if (url.length) {
352 url = path + "#" + prefix + "/" + url;
353 } else {
354 url = "/edit";
355 }
356
357 document.getElementById("doc-title-text").innerText = title.length ? title : "";
358
359 bittyLink = new URL(url, document.location).href;
360
361 document.getElementById("canonical").href = bittyLink;
362
363 if(previewContent) {
364 console.log("previewing", bittyLink);
365 QS("#preview-frame").src = bittyLink;
366 }
367
368 var hash = location.hash;
369 if (true) {
370 if (push || !hash || !hash.length) {
371 window.history.pushState(null, null, bittyLink);
372 } else {
373 window.history.replaceState(null, null, bittyLink);
374 }
375 }
376
377 var length = bittyLink.length;
378
379 QS("#length").innerText = length + " bytes";
380 QS("#length").onclick = () => {
381 window.open(bittyLink, "_blank");
382 }
383 for (var key in maxLengths) {
384 var maxLength = maxLengths[key];
385 if (length > maxLength) {
386 QS(key).classList.add("invalid");
387 } else {
388 QS(key).classList.remove("invalid");
389 }
390 }
391}
392
393function share() {
394 navigator.share({

Callers 4

edit.jsFile · 0.70
handleDropFunction · 0.70
fetchCodepenFunction · 0.70
handleContentChangeFunction · 0.70

Calls 1

addMethod · 0.80

Tested by

no test coverage detected