TypeError: Cannot read properties of undefined (reading 'strings')
kadisonm opened this issue · comments
I'm encorporating citeproc into a plugin for Obsidian, which uses TypeScript (if that's relevant). However, whenever I use updateItems() I get this error.
If anyone needs more context my repository is here: https://github.com/kadisonm/obsidian-reference-generator/tree/01607da92597b1679e617750714ddd243892955f
I can't really tell what I'm doing wrong. Is it something to do with typescript or my packages? I was getting this error earlier which I solved by making a types.d.ts file with:
declare module 'citeproc';
Here is my code: (also requestUrl() comes from the Obsidian api and is essentially fetch)
// Create CSL JSON
const JSON = [{
"id": "id",
"type": "webpage",
"title": title,
'container-title': siteName,
"URL": url,
"author": authors,
"issued": {
'date-parts': [[ published.getFullYear(), published.getMonth(), published.getDate() ]]
},
}];
// Create Citeproc Engine
const sys = {
retrieveLocale: async (lang: string) => {
const response = await requestUrl('https://raw.githubusercontent.com/citation-style-language/locales/master/locales-' + lang + '.xml');
const result = response.text;
return result;
},
retrieveItem: (id: string) => {
return JSON;
},
};
const style = await requestUrl('https://raw.githubusercontent.com/citation-style-language/styles/master/' + styleID + '.csl').text;
const engine = new CSL.Engine(sys, style);
// Get reference in style
engine.updateItems(['id']);
const result = engine.makeBibliography();
console.log(result);
return "";
I'm seeing two main things:
sys.retrieveLocale
cannot be asynchronous, locales would need to be fetched beforehand. citeproc always requestsen-US
so that would need to be fetched at a minimum.sys.retrieveItem
should return the object, not the full array.
Hi, I'll fix these and update soon. Thank you so much for such a fast response.
It works thank you so much.