From eb5c62fb6d9e4f8d664b5e8c67416dc0770fe037 Mon Sep 17 00:00:00 2001 From: Max Edell Date: Tue, 17 Oct 2023 08:24:18 -0700 Subject: [PATCH] fix: handle sheet params in table block --- blocks/table/table.js | 5 ++++- scripts/scripts.js | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/blocks/table/table.js b/blocks/table/table.js index 9468b57..ebbfb86 100644 --- a/blocks/table/table.js +++ b/blocks/table/table.js @@ -1,4 +1,5 @@ import { + WEB_ORIGINS, decoratePills, html, isValidDocsURL, isValidWebURL, } from '../../scripts/scripts.js'; @@ -58,7 +59,9 @@ async function sheetToDivTable(path) { } } - const json = await store.fetchJSON(href); + const url = new URL(href, WEB_ORIGINS[store.env]); + const json = await store.fetchJSON(url.pathname, url.searchParams.getAll('sheet')); + if (!json || !json.data) { return null; } diff --git a/scripts/scripts.js b/scripts/scripts.js index d565775..48e33a0 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -24,8 +24,8 @@ polyfill(); const range = document.createRange(); -export const BRANCH_ORIGIN = 'https://prisma-cloud-docs-production.adobeaem.workers.dev'; -// export const BRANCH_ORIGIN = 'http://127.0.0.1:3001'; +// export const BRANCH_ORIGIN = 'https://prisma-cloud-docs-production.adobeaem.workers.dev'; +export const BRANCH_ORIGIN = 'http://127.0.0.1:3001'; export const SPA_NAVIGATION = true; export const REDIRECTED_ARTICLE_KEY = 'redirected-article'; @@ -330,6 +330,9 @@ const store = new (class { } catch (_) { url = new URL(`${window.location.origin}${path}.json`); } + if (url.pathname.endsWith('.json.json')) { + url.pathname = url.pathname.replace(/\.json\.json$/, '.json'); + } if (sheets) { // eslint-disable-next-line no-param-reassign