Skip to content

Commit

Permalink
Reduce bundle size, add a conf param
Browse files Browse the repository at this point in the history
* Remove use of zotero-api-client as all we need is a single static file
  (schema) so it makes little sense to bring in entire library for this
  one trivial request
* Make api URL configurable
  • Loading branch information
tnajdek committed May 26, 2023
1 parent 99845f0 commit f594a70
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 66 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ Specifies an additional prefix for where translation server request should be se
**translateURL**
Specifies URL for the *translation-server*. By default localhost is assumed to proxy request to the translation server.

**apiAuthorityPart**
Specifies the authority part of the URL for Zotero API requests. Defaults to `api.zotero.org`.

Development server configuration
--------------

Expand Down
5 changes: 3 additions & 2 deletions config/custom-environment-variables.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"indexConfig": {
"apiAuthorityPart": "API_AUTHORITY_PART",
"storeURL": "STORE_URL",
"stylesCacheTime": "STYLES_CACHE_TIME",
"stylesURL": "STYLES_URL",
"translatePrefix": "TRANSLATION_SERVER_PREFIX",
"translateURL": "TRANSLATION_SERVER_URL",
"stylesCacheTime": "STYLES_CACHE_TIME"
"translateURL": "TRANSLATION_SERVER_URL"
}
}
3 changes: 2 additions & 1 deletion config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
// listed below can be overriden in local.json and/or using
// env variables. See https://www.npmjs.com/package/config
//
// "apiAuthorityPart": undefined,
// "storeURL": undefined,
// "stylesURL": undefined,
// "translatePrefix": "",
// "translateURL": undefined,
// "translateURL": undefined
}
}
84 changes: 29 additions & 55 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@
"react-modal": "^3.16.1",
"react-transition-group": "^4.4.5",
"smooth-scroll": "^16.1.3",
"use-debounce": "^9.0.4",
"zotero-api-client": ">=0.41.1"
"use-debounce": "^9.0.4"
},
"devDependencies": {
"@babel/core": "^7.21.8",
Expand All @@ -95,6 +94,7 @@
"cheerio": "^1.0.0-rc.12",
"citeproc": "^2.4.63",
"config": "^3.3.9",
"cross-fetch": "^3.1.6",
"cssnano": "^6.0.1",
"eslint": "^8.41.0",
"eslint-plugin-jest-dom": "^4.0.3",
Expand Down
8 changes: 4 additions & 4 deletions src/js/components/container.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ const fetchAndSelectStyle = async (dispatch, styleName, opts = {}) => {
}
}

const configureZoteroSchema = async (dispatch, locale) => {
const configureZoteroSchema = async (dispatch, locale, apiAuthorityPart) => {
dispatch({ type: REQUEST_SCHEMA });
try {
const schema = await fetchSchema();
const schema = await fetchSchema(apiAuthorityPart);
configureZoteroShim(schema, locale);
const meta = getMetaFromSchema(schema, locale);
dispatch({ type: RECEIVE_SCHEMA, schema, meta });
Expand Down Expand Up @@ -1293,13 +1293,13 @@ const BibWebContainer = props => {
useLegacy.current = !params.get('use_experimental_citeproc') || (['false', '0']).includes(params.get('use_experimental_citeproc'));

if(remoteId) {
configureZoteroSchema(dispatch, intl.locale);
configureZoteroSchema(dispatch, intl.locale, config.apiAuthorityPart);
fetchRemoteBibliography();
} else {
const prefilledIdentifier = params.get('q') || '';
setIdentifier(prefilledIdentifier);
setIsDataReady(true);
configureZoteroSchema(dispatch, intl.locale);
configureZoteroSchema(dispatch, intl.locale, config.apiAuthorityPart);
fetchAndSelectStyle(
dispatch,
localStorage.getItem('zotero-bib-citation-style') || coreCitationStyles.find(cs => cs.isDefault).name,
Expand Down
1 change: 1 addition & 0 deletions src/js/constants/defaults.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default Object.freeze({
apiAuthorityPart: 'api.zotero.org',
storeURL: '/store',
stylesURL: 'https://www.zotero.org/styles-files/styles.json',
storage: window.localStorage
Expand Down
3 changes: 1 addition & 2 deletions src/js/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import balanced from 'balanced-match';
import api from 'zotero-api-client';

import ZoteroBib from './zotero-translation-client';
import CiteprocWrapper from './citeproc-wrapper';
Expand Down Expand Up @@ -425,7 +424,7 @@ const mergeFetchOptions = (init, globalOpts, localOpts) => {
return { ...init, ...(globalOpts.init || {}), ...(localOpts.init || {}), headers };
}

const fetchSchema = async (apiConfig = {}) => (await api(null, apiConfig).schema().get()).getData();
const fetchSchema = async (apiAuthorityPart) => (await fetch(`https://${apiAuthorityPart}/schema`)).json();

const ignoredItemTypes = ['note', 'attachment', 'annotation'];
const getMetaFromSchema = (schema, locale) => {
Expand Down

0 comments on commit f594a70

Please sign in to comment.