Skip to content

Commit 2bb287a

Browse files
committed
Handle URLs in json-ld fragment identifiers.
Also handle `copyContext`.
1 parent 6d3ddfe commit 2bb287a

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

playground/next/editor.mjs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -562,15 +562,25 @@ window.app = createApp({
562562
};
563563
setEditorValue(this.contextEditor, this.contextDoc);
564564
},
565-
gatherHash() {
565+
async gatherHash() {
566566
const url = new URL(window.location);
567567
const hash = new URLSearchParams(url?.hash.slice(1));
568568
this.contextDoc = JSON.parse(hash.get('context')) || {};
569569
setEditorValue(this.contextEditor, this.contextDoc);
570570
this.frameDoc = JSON.parse(hash.get('frame')) || {};
571571
setEditorValue(this.frameEditor, this.frameDoc);
572-
this.doc = JSON.parse(hash.get('json-ld')) || {};
573-
setEditorValue(this.mainEditor, this.doc);
572+
// the `json-ld` parameter can be JSON or a URL
573+
const jsonLdOrUrl = hash.get('json-ld');
574+
try {
575+
this.doc = JSON.parse(jsonLdOrUrl);
576+
setEditorValue(this.mainEditor, this.doc);
577+
} catch {
578+
this.remoteDocURL = jsonLdOrUrl;
579+
await this.retrieveDoc(this.mainEditor, 'doc', this.remoteDocURL);
580+
}
581+
if (hash.get('copyContext') === 'true') {
582+
this.copyContext();
583+
}
574584
this.outputTab = hash.get('startTab')?.slice(4);
575585
}
576586
}).mount();

0 commit comments

Comments
 (0)