Skip to content

Commit 9db8090

Browse files
committed
#890 recommend use of primary publish-to-the-web URL, allow that through the authoring tool, and encode/decode it rather than pack the full sheets URL into timeline URLs
1 parent 8fe7bc9 commit 9db8090

File tree

6 files changed

+45
-14
lines changed

6 files changed

+45
-14
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
3.9.7 (2025-03-10)
2+
-------------------------
3+
* #834 Improved timegroup-message element contrast
4+
* #890 Fixes to support modern Google Sheets publish-to-web URL format
5+
16
3.9.6 (2025-01-10)
27
-------------------------
38
* Change initial computation of component heights to address axis labels overflowing

src/js/core/ConfigFactory.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,25 @@ export function parseGoogleSpreadsheetURL(url) {
1919
}
2020
// key as url parameter (old-fashioned)
2121
var key_pat = /\bkey=([-_A-Za-z0-9]+)&?/i;
22+
// https://docs.google.com/spreadsheets/d/e/2PACX-1vTwrxBim-ruoMlLP9CnZIevWdP8rIatkV7XjNGXRSaMI94sNd-VbRF--W7A2kj6wfZhKUHWv1ur0Tb3/pubhtml
23+
var v2_url_pat = /docs.google.com\/spreadsheets.*?\/d\/e\/([^\/]+)\/.+/; // Google prefers pubhtml links with this format
2224
var url_pat = /docs.google.com\/spreadsheets(.*?)\/d\//; // fixing issue of URLs with u/0/d
2325

2426
if (url.match(key_pat)) {
2527
parts.key = url.match(key_pat)[1];
2628
// can we get a worksheet from this form?
29+
} else if (url.match(v2_url_pat)) {
30+
let v2_key = url.match(v2_url_pat)[1]
31+
parts.key = `v2:${v2_key}`
32+
// to do: get worksheet from this form?
2733
} else if (url.match(url_pat)) {
2834
var pos = url.search(url_pat) + url.match(url_pat)[0].length;
2935
var tail = url.substr(pos);
3036
parts.key = tail.split('/')[0]
3137
if (url.match(/\?gid=(\d+)/)) {
3238
parts.worksheet = url.match(/\?gid=(\d+)/)[1];
3339
}
34-
} else if (url.match(/^\b[-_A-Za-z0-9]+$/)) {
40+
} else if (url.match(/^\b(v2:)?[-_A-Za-z0-9]+$/)) {
3541
parts.key = url;
3642
}
3743

@@ -195,7 +201,19 @@ export async function readGoogleAsCSV(url, sheets_proxy) {
195201
*/
196202
export function makeGoogleCSVURL(url_or_key) {
197203
url_or_key = url_or_key.trim()
198-
if (url_or_key.match(/^[a-zA-Z0-9-_]+$/)) {
204+
if (url_or_key.match(/^v2:[a-zA-Z0-9-_]+$/)) {
205+
console.log(`it's a newbie: ${url_or_key}`)
206+
try {
207+
let key = url_or_key.substring(3)
208+
console.log(`key is ${key}`)
209+
let url = `https://docs.google.com/spreadsheets/d/e/${key}/pub?output=csv`
210+
console.log(`url is ${url}`)
211+
return url
212+
} catch (e) {
213+
debugger;
214+
throw new TLError('invalid_url_err', url_or_key);
215+
}
216+
} else if (url_or_key.match(/^[a-zA-Z0-9-_]+$/)) {
199217
// key pattern from https://developers.google.com/sheets/api/guides/concepts#spreadsheet_id
200218
return `https://docs.google.com/spreadsheets/d/${url_or_key}/pub?output=csv`
201219
}
@@ -270,6 +288,7 @@ export async function makeConfig(url, callback_or_options) {
270288

271289
if (key) {
272290
try {
291+
console.log(`reading url ${url}`);
273292
json = await jsonFromGoogleURL(url, options);
274293
} catch (e) {
275294
// even with an error, we make

src/js/core/__tests__/ConfigFactory.test.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@ test("new-ish url format should get the right key", () => {
3030
expect(parts.key).toBe(key)
3131
})
3232

33+
test("new new url format should get a viable key", () => {
34+
var url = 'https://docs.google.com/spreadsheets/d/e/2PACX-1vTwrxBim-ruoMlLP9CnZIevWdP8rIatkV7XjNGXRSaMI94sNd-VbRF--W7A2kj6wfZhKUHWv1ur0Tb3/pubhtml'
35+
var key = 'v2:2PACX-1vTwrxBim-ruoMlLP9CnZIevWdP8rIatkV7XjNGXRSaMI94sNd-VbRF--W7A2kj6wfZhKUHWv1ur0Tb3';
36+
var parts = parseGoogleSpreadsheetURL(url);
37+
expect(parts.key).toBe(key);
38+
})
39+
40+
test("encoded key part of new new url format should come back untouched", () => {
41+
var url = 'v2:2PACX-1vTwrxBim-ruoMlLP9CnZIevWdP8rIatkV7XjNGXRSaMI94sNd-VbRF--W7A2kj6wfZhKUHWv1ur0Tb3'
42+
var parts = parseGoogleSpreadsheetURL(url);
43+
expect(parts.key).toBe(url);
44+
})
45+
3346
describe("test making CSV URL from various inputs", () => {
3447
test("A 'd/' URL that's already right should work", () => {
3548
let test_url = 'https://docs.google.com/spreadsheets/u/1/d/1xuY4upIooEeszZ_lCmeNx24eSFWe0rHe9ZdqH2xqVNk/pub?output=csv'
@@ -65,4 +78,4 @@ describe("test making CSV URL from various inputs", () => {
6578
makeGoogleCSVURL('1xuY4upIooEeszZ_lCmeNx24eSFWe0rHe9ZdqH2xqVNk')
6679
).toMatch(/pub\?output=csv$/)
6780

68-
})
81+
})
59.3 KB
Loading

website/static/js/main.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ function getLinkAndIframe() {
5555
/* SOURCE KEY
5656
================================================== */
5757
if (e_source.value.match("docs.google.com")) {
58-
if (e_source.value.match(new RegExp('/spreadsheets/d/e'))) {
59-
theobj.warning = "Invalid Google URL. Please see the note above about how a recent change with Google Spreadsheets affects creating timelines.";
60-
return theobj;
61-
}
6258
var obj = TL.parseGoogleSpreadsheetURL(e_source.value);
6359
source_key = obj.key;
6460
} else {
@@ -237,4 +233,4 @@ document.addEventListener("DOMContentLoaded", function() {
237233
$target.collapse('show');
238234
navSmartScroll($target.prev());
239235
}
240-
});
236+
});

website/templates/_make.html

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,14 @@ <h6>Publish to the web</h6>
2929
<strong>Don't set your Timeline Google Sheet to "anyone with the link can edit."</strong> It isn't necessary, and could lead to someone changing your timeline without your consent.
3030
</p>
3131

32-
3332
<p style="clear: both;">
34-
<img class="img-shadow make-step-2" src="static/img/make/publish_to_web_button_small.png" alt="Screenshot of Google Sheets 'Publish to the Web' dialog window" /> In the next window, click the green "Publish" button. When asked,
35-
"Are you sure…?" click OK. <em>Ignore the URL that appears in the center of the window.</em> Just close the window using the <em>X</em> in the top right corner.
36-
33+
<img class="img-shadow make-step-2" src="static/img/make/publish_to_web_button_small.png" alt="Screenshot of Google Sheets 'Publish to the web' dialog window" /> In the next window, click the green "Publish" button. When asked,
34+
"Are you sure…?" click OK.
3735
</p>
3836
<p style="clear: both;">
39-
<img class="img-shadow" src="static/img/make/publish_to_web_browser_url.png" /> After you close the window, copy the URL in your browser's address bar. You'll use this in the next step.
37+
<img class="img-shadow make-step-2" src="static/img/make/publish_to_web_highlight_url.png" alt="Screenshot of Google Sheets 'Publish to the web' dialog window highlighting the URL to copy" /> Copy the URL that appears in the center of the window. Then close the window using the <em>X</em> in the top right corner.
4038
</p>
41-
<p class="note">If you get an error message referencing an "Invalid Google URL," please review the above instructions. You must use the Google Sheets URL from your browser's address bar, not the one from the "publish to the web" popup.</p>
39+
<p class="note">For some time, our advice was to ignore the URL which appears in the "publish to the web" window, but changes with Google Sheets have led us to change this advice. We now recommend using the URL from the 'Publish to the web' dialog window.</p>
4240
</div>
4341
</div>
4442
</li>

0 commit comments

Comments
 (0)