Skip to content

Commit

Permalink
Add pandoc reference list
Browse files Browse the repository at this point in the history
  • Loading branch information
mgmeyers committed Jul 4, 2023
1 parent 9c0588c commit 21d3b2b
Show file tree
Hide file tree
Showing 22 changed files with 1,819 additions and 976 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./dist/main.js
asset_path: ./main.js
asset_name: main.js
asset_content_type: text/javascript
# Upload the manifest.json
Expand All @@ -54,7 +54,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./dist/manifest.json
asset_path: ./manifest.json
asset_name: manifest.json
asset_content_type: application/json
# Upload the style.css
Expand All @@ -65,6 +65,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./dist/styles.css
asset_path: ./styles.css
asset_name: styles.css
asset_content_type: text/css
40 changes: 0 additions & 40 deletions esbuild.config.js

This file was deleted.

59 changes: 59 additions & 0 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import builtins from 'builtin-modules';
import esbuild from 'esbuild';
import process from 'process';

const banner = `/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
`;

const prod = process.argv[2] === 'production';

const context = await esbuild.context({
banner: {
js: banner,
},
entryPoints: ['./src/main.ts'],
bundle: true,
external: [
'obsidian',
'electron',
'@codemirror/autocomplete',
'@codemirror/closebrackets',
'@codemirror/collab',
'@codemirror/commands',
'@codemirror/comment',
'@codemirror/fold',
'@codemirror/gutter',
'@codemirror/highlight',
'@codemirror/history',
'@codemirror/language',
'@codemirror/lint',
'@codemirror/matchbrackets',
'@codemirror/panel',
'@codemirror/rangeset',
'@codemirror/rectangular-selection',
'@codemirror/search',
'@codemirror/state',
'@codemirror/stream-parser',
'@codemirror/text',
'@codemirror/tooltip',
'@codemirror/view',
'node:*',
...builtins,
],
format: 'cjs',
target: 'es2018',
logLevel: 'info',
sourcemap: prod ? false : 'inline',
treeShaking: true,
outfile: 'main.js',
});

if (prod) {
await context.rebuild();
process.exit(0);
} else {
await context.watch();
}
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-zotero-desktop-connector",
"name": "Zotero Integration",
"version": "2.4.1",
"version": "3.0.0",
"minAppVersion": "1.1.1",
"description": "Insert and import citations, bibliographies, notes, and PDF annotations from Zotero.",
"author": "mgmeyers",
Expand Down
13 changes: 5 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "This is a sample plugin for Obsidian (https://obsidian.md)",
"main": "main.js",
"scripts": {
"dev": "cross-env BUILD=dev obsidian-plugin dev src/main.ts -e esbuild.config.js",
"build": "cross-env BUILD=production obsidian-plugin build src/main.ts -e esbuild.config.js",
"dev": "node esbuild.config.mjs",
"build": "node esbuild.config.mjs production",
"check-types": "tsc --noemit",
"lint": "eslint ./src",
"lint:fix": "eslint ./src/**/* --fix",
Expand All @@ -20,11 +20,14 @@
"@babel/core": "7.22.5",
"@babel/preset-env": "7.22.5",
"@babel/preset-typescript": "7.22.5",
"@codemirror/language": "https://github.com/lishid/cm-language",
"@trivago/prettier-plugin-sort-imports": "4.1.1",
"@types/download": "8.0.2",
"@types/jest": "29.5.2",
"@types/lru-cache": "^7.10.10",
"@types/node": "20.3.3",
"@types/nunjucks": "3.2.3",
"@types/react-dom": "18.2.6",
"@types/which": "^3.0.0",
"@typescript-eslint/eslint-plugin": "5.61.0",
"@typescript-eslint/parser": "5.61.0",
Expand All @@ -39,18 +42,12 @@
"jest": "29.5.0",
"moment": "2.29.4",
"obsidian": "1.2.8",
"obsidian-plugin-cli": "0.9.0",
"prettier": "2.8.8",
"tslib": "2.6.0",
"typescript": "5.1.6",
"xml-js": "1.6.11"
},
"dependencies": {
"@codemirror/language": "https://github.com/lishid/cm-language",
"@codemirror/state": "^6.2.1",
"@codemirror/view": "^6.14.0",
"@types/lru-cache": "^7.10.10",
"@types/react-dom": "18.2.6",
"download": "8.0.0",
"escape-path-with-spaces": "1.0.2",
"execa": "7.1.1",
Expand Down
10 changes: 9 additions & 1 deletion src/bbt/cayw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ export function getCiteKeyFromAny(item: any): CiteKey | null {
};
}

let cachedIsRunning = false;
let lastCheck = 0;
export async function isZoteroRunning(
database: DatabaseWithPort,
silent?: boolean
) {
if (cachedIsRunning && Date.now() - lastCheck < 1000 * 60) {
return cachedIsRunning;
}

let modal: LoadingModal;
if (!silent) {
modal = new LoadingModal(app, 'Fetching data from Zotero...');
Expand All @@ -35,7 +41,9 @@ export async function isZoteroRunning(
});

modal?.close();
return res === 'ready';
cachedIsRunning = res === 'ready';
lastCheck = Date.now();
return cachedIsRunning;
} catch (e) {
modal?.close();
!silent &&
Expand Down
52 changes: 46 additions & 6 deletions src/bbt/getCiteKeyExport.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { request } from 'obsidian';
import { DatabaseWithPort } from 'src/types';
import { CiteKeyExport, DatabaseWithPort } from 'src/types';

import { isZoteroRunning } from './cayw';
import { defaultHeaders, getPort } from './helpers';

const translatorId = 'f4b52ab0-f878-4556-85a0-c7aeedd09dfc';
Expand All @@ -22,7 +23,27 @@ export async function getCiteKeyExport(
const entries = JSON.parse(res);

return Array.isArray(entries)
? entries.map((e) => e['citation-key']).filter((k) => !!k)
? entries
.map((e) => {
const out: Record<string, any> = {
libraryID: Number(groupId),
};

if (e['citation-key']) {
out.citekey = e['citation-key'];
} else {
return null;
}

if (e['title']) {
out.title = e['title'];
} else {
return null;
}

return out as { libraryID: number; citekey: string; title: string };
})
.filter((k) => !!k)
: null;
} catch (e) {
return null;
Expand Down Expand Up @@ -58,11 +79,27 @@ export async function getUserGroups(database: DatabaseWithPort) {
}
}

export async function getAllCiteKeys(database: DatabaseWithPort) {
const allKeys: string[] = [];
let cachedKeys: CiteKeyExport[] = [];
let lastCheck = 0;

export async function getAllCiteKeys(
database: DatabaseWithPort,
force?: boolean
) {
if (!force && cachedKeys.length && Date.now() - lastCheck < 1000 * 60 * 60) {
return { citekeys: cachedKeys, fromCache: true };
}

if (!(await isZoteroRunning(database, true))) {
return { citekeys: cachedKeys, fromCache: true };
}

const allKeys: CiteKeyExport[] = [];
const userGroups = await getUserGroups(database);

if (!userGroups) return allKeys;
if (!userGroups) {
return { citekeys: cachedKeys, fromCache: true };
}

for (const group of userGroups) {
const keys = await getCiteKeyExport(database, group.id, group.name);
Expand All @@ -72,5 +109,8 @@ export async function getAllCiteKeys(database: DatabaseWithPort) {
}
}

return allKeys;
cachedKeys = allKeys;
lastCheck = Date.now();

return { citekeys: allKeys, fromCache: false };
}
Loading

0 comments on commit 21d3b2b

Please sign in to comment.