From d153d53660a64a2761d8c1fd5a8a438c366e5837 Mon Sep 17 00:00:00 2001 From: Joe Germuska Date: Fri, 11 Oct 2024 10:58:17 -0500 Subject: [PATCH] begin to support JSON export --- src/js/core/ConfigFactory.js | 2 +- src/js/index.js | 9 +++------ src/js/timeline/Timeline.js | 14 ++++++++++++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/js/core/ConfigFactory.js b/src/js/core/ConfigFactory.js index 6b1bc4fa9..4b42d03b0 100644 --- a/src/js/core/ConfigFactory.js +++ b/src/js/core/ConfigFactory.js @@ -223,7 +223,7 @@ var buildGoogleFeedURL = function(key, api_version) { } } -async function jsonFromGoogleURL(google_url, options) { +export async function jsonFromGoogleURL(google_url, options) { if (!options['sheets_proxy']) { throw new TLError("Proxy option must be set to read data from Google") diff --git a/src/js/index.js b/src/js/index.js index dbabe35cc..95fb50689 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -1,7 +1,4 @@ import "../less/TL.Timeline.less" -export { Timeline } -from "./timeline/Timeline" -export { parseGoogleSpreadsheetURL } -from "./core/ConfigFactory" -export { lookupMediaType } -from "./media/MediaType" \ No newline at end of file +export { Timeline, exportJSON } from "./timeline/Timeline" +export { parseGoogleSpreadsheetURL } from "./core/ConfigFactory" +export { lookupMediaType } from "./media/MediaType" diff --git a/src/js/timeline/Timeline.js b/src/js/timeline/Timeline.js index 971060970..08cfb3be8 100644 --- a/src/js/timeline/Timeline.js +++ b/src/js/timeline/Timeline.js @@ -5,7 +5,7 @@ import Message from "../ui/Message" import { Language, fallback, loadLanguage } from "../language/Language" import { I18NMixins } from "../language/I18NMixins"; import Events from "../core/Events"; -import { makeConfig } from "../core/ConfigFactory" +import { makeConfig, jsonFromGoogleURL } from "../core/ConfigFactory" import { TimelineConfig } from "../core/TimelineConfig" import { TimeNav } from "../timenav/TimeNav" import * as Browser from "../core/Browser" @@ -1018,4 +1018,14 @@ class Timeline { classMixin(Timeline, I18NMixins, Events) -export { Timeline } +async function exportJSON(url, proxy_url) { + + if (!proxy_url) { + proxy_url = 'https://sheets-proxy.knightlab.com/proxy/' + } + + let json = await jsonFromGoogleURL(url, {sheets_proxy: proxy_url}) + return json +} + +export { Timeline, exportJSON }