Skip to content

Commit a7469ec

Browse files
committed
Accept CSL files (styles) at URLs
and fix extra forward slash in api calls
1 parent 94a4577 commit a7469ec

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,22 @@ presence of particular tags.
8383
* `style` - The bibliography display style for the citations, e.g., apa. Leave
8484
blank for the default which is chicago-note-bibliography.
8585

86-
You can also supply links to datasets that the publication references by
86+
The allowable values for the `style` parameter are filenames from the [Zotero Style
87+
Repository](https://www.zotero.org/styles), without the .csl extension. Find the style you want on that
88+
page, and then hover you mouse over the style name and click Source, and then
89+
read the `id` for the style. For example, the filename for [Analytica Chimica
90+
Acta: X](https://www.zotero.org/styles/analytica-chimica-acta-x?source=1) is
91+
actually `analytica-chimica-acta-x`. You can also host your own style file
92+
(*.csl) on a public facing Web server and provide the **full URL** to the file
93+
in ZOTERO_CONFIG's `style` parameter, as in:
94+
95+
```JavaScript
96+
ZOTERO_CONFIG["style"] = "https://mysite.org/mystyle.csl";
97+
```
98+
99+
### Data Links
100+
101+
You can supply links to datasets that the publication references by
87102
placing each dataset's DOI (with https://doi.org/ in front of it) on its own
88103
line in the **Extra** field in Zotero, as in:
89104

zotero.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
var ZOTERO_CONFIG = {
66
"zotId": "2211939", // ID of group or user library to search in Zotero, e.g., 2211939, 2055673
77
"zotIdType": "group", // group or user
8-
"collectionKey": "", // Key of collection within library to search, e.g., "KHTHLKB5", or "" if no collection
8+
"collectionKey": "KHTHLKB5", // Key of collection within library to search, e.g., "KHTHLKB5", or "" if no collection
99
"filterTags": "", // For filtering results by tag(s), e.g., "&tag=LTER-Funded". See examples at https://www.zotero.org/support/dev/web_api/v3/basics
1010
"resultsElementId": "searchResults", // Element to contain results
1111
"includeCols": ["Year", "Type", "ShowTags"], // Array of columns to include in the output table, other than Citation. The full set is ["Year", "Type", "ShowTags"]
@@ -282,12 +282,17 @@ function showUrl(url) {
282282
}
283283

284284

285+
function encodeStyle(style) {
286+
return style.replace(/\//g, '%3A').replace(/:/g, '%2F');
287+
}
288+
289+
285290
// Passes search URL and callbacks to CORS function
286291
function searchZotero(query, itemType, sort, start) {
287292
var zotId = (ZOTERO_CONFIG["zotIdType"] === "group") ? "groups/" + ZOTERO_CONFIG["zotId"] : "users/" + ZOTERO_CONFIG["zotId"];
288-
var collection = (ZOTERO_CONFIG["collectionKey"] === "") ? "/" : "/collections/" + ZOTERO_CONFIG["collectionKey"] + "/";
293+
var collection = (ZOTERO_CONFIG["collectionKey"] === "") ? "" : "/collections/" + ZOTERO_CONFIG["collectionKey"];
289294
var base = "https://api.zotero.org/" + zotId + collection + "/items?v=3&include=bib,data";
290-
var style = (ZOTERO_CONFIG["style"] === "") ? "" : "&style=" + ZOTERO_CONFIG["style"];
295+
var style = (ZOTERO_CONFIG["style"] === "") ? "" : "&style=" + encodeStyle(ZOTERO_CONFIG["style"]);
291296
var params = "&q=" + encodeURI(query) + "&itemType=" + itemType +
292297
"&sort=" + sort + "&start=" + start + ZOTERO_CONFIG["filterTags"];
293298
var limit = "&limit=" + ZOTERO_CONFIG["limit"];

0 commit comments

Comments
 (0)