mirror of
https://github.com/retorquere/zotero-better-bibtex.git
synced 2022-05-23 09:36:29 +03:00
phase out reference
This commit is contained in:
@@ -394,7 +394,7 @@ Zotero.Translate.Export.prototype.Sandbox.BetterBibTeX = {
|
||||
return cloneDeep(cached)
|
||||
},
|
||||
|
||||
cacheStore(sandbox: { translator: { label: string }[] }, itemID: number, options: { exportNotes: boolean, useJournalAbbreviation: boolean }, prefs: any, reference: any, metadata: any) {
|
||||
cacheStore(sandbox: { translator: { label: string }[] }, itemID: number, options: { exportNotes: boolean, useJournalAbbreviation: boolean }, prefs: any, entry: any, metadata: any) {
|
||||
if (!Preference.caching) return false
|
||||
|
||||
if (!metadata) metadata = {}
|
||||
@@ -409,13 +409,13 @@ Zotero.Translate.Export.prototype.Sandbox.BetterBibTeX = {
|
||||
let cached = collection.findOne($and(selector))
|
||||
|
||||
if (cached) {
|
||||
cached.reference = reference
|
||||
cached.reference = entry
|
||||
cached.metadata = metadata
|
||||
cached = collection.update(cached)
|
||||
|
||||
}
|
||||
else {
|
||||
cached = collection.insert({...selector, reference, metadata})
|
||||
cached = collection.insert({...selector, entry, metadata})
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ class Cache extends Loki {
|
||||
type: 'object',
|
||||
properties: {
|
||||
itemID: { type: 'integer' },
|
||||
reference: { type: 'string' },
|
||||
entry: { type: 'string' },
|
||||
|
||||
// options
|
||||
exportNotes: { type: 'boolean' },
|
||||
@@ -103,16 +103,22 @@ class Cache extends Loki {
|
||||
meta: { type: 'object' },
|
||||
$loki: { type: 'integer' },
|
||||
},
|
||||
required: [ 'itemID', 'exportNotes', 'useJournalAbbreviation', ...(translator.preferences), 'reference' ],
|
||||
required: [ 'itemID', 'exportNotes', 'useJournalAbbreviation', ...(translator.preferences), 'entry' ],
|
||||
additionalProperties: false,
|
||||
},
|
||||
ttl,
|
||||
ttlInterval,
|
||||
})
|
||||
if (!Preference.caching) coll.removeDataOnly()
|
||||
log.debug(`cache.${coll.name}:`, coll.data.length)
|
||||
|
||||
this.clearOnUpgrade(coll, 'BetterBibTeX', version)
|
||||
if (!Preference.caching) {
|
||||
coll.removeDataOnly()
|
||||
}
|
||||
else if (! (coll.data[0]?.entry) ) { // phase out reference
|
||||
coll.removeDataOnly()
|
||||
}
|
||||
else {
|
||||
log.debug(`cache.${coll.name}:`, coll.data.length)
|
||||
this.clearOnUpgrade(coll, 'BetterBibTeX', version)
|
||||
}
|
||||
}
|
||||
|
||||
this.initialized = true
|
||||
|
||||
@@ -408,13 +408,13 @@ export class KeyManager {
|
||||
|
||||
this.keys.findAndRemove({ itemID: { $nin: ids } })
|
||||
|
||||
// find all references without citekey
|
||||
// find all items without citekey
|
||||
this.scanning = this.keys.find($and({ citekey: marker }))
|
||||
|
||||
if (this.scanning.length !== 0) {
|
||||
const progressWin = new Zotero.ProgressWindow({ closeOnClick: false })
|
||||
progressWin.changeHeadline('Better BibTeX: Assigning citation keys')
|
||||
progressWin.addDescription(`Found ${this.scanning.length} references without a citation key`)
|
||||
progressWin.addDescription(`Found ${this.scanning.length} items without a citation key`)
|
||||
const icon = `chrome://zotero/skin/treesource-unfiled${Zotero.hiDPI ? '@2x' : ''}.png`
|
||||
const progress = new progressWin.ItemProgress(icon, 'Assigning citation keys')
|
||||
progressWin.show()
|
||||
|
||||
@@ -165,7 +165,7 @@ class Item {
|
||||
public extra: string
|
||||
public extraFields: Extra.Fields
|
||||
|
||||
constructor(item: ZoteroItem | SerializedItem) { // Reference must have simplifyForExport pre-applied, without scrubbing
|
||||
constructor(item: ZoteroItem | SerializedItem) { // Item must have simplifyForExport pre-applied, without scrubbing
|
||||
this.item = item
|
||||
|
||||
if ((item as ZoteroItem).getField) {
|
||||
@@ -419,7 +419,7 @@ class PatternFormatter {
|
||||
}
|
||||
}
|
||||
|
||||
/** returns the name of the shared group library, or nothing if the reference is in your personal library */
|
||||
/** returns the name of the shared group library, or nothing if the item is in your personal library */
|
||||
public $library() {
|
||||
if (this.item.libraryID === Zotero.Libraries.userLibraryID) return this.set('')
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
@@ -925,13 +925,13 @@ class PatternFormatter {
|
||||
return this.set(this.value.replace(script.han, ' $1 ').trim())
|
||||
}
|
||||
|
||||
/** word segmentation for Chinese references. Uses substantial memory; must be enabled under Preferences -> Better BibTeX -> Advanced -> Citekeys */
|
||||
/** word segmentation for Chinese items. Uses substantial memory; must be enabled under Preferences -> Better BibTeX -> Advanced -> Citekeys */
|
||||
public _jieba() {
|
||||
if (!Preference.jieba) return this
|
||||
return this.set(jieba.cut(this.value).join(' ').trim())
|
||||
}
|
||||
|
||||
/** word segmentation for Japanese references. Uses substantial memory; must be enabled under Preferences -> Better BibTeX -> Advanced -> Citekeys */
|
||||
/** word segmentation for Japanese items. Uses substantial memory; must be enabled under Preferences -> Better BibTeX -> Advanced -> Citekeys */
|
||||
public _kuromoji() {
|
||||
if (!Preference.kuroshiro || !kuroshiro.enabled) return this
|
||||
return this.set(kuroshiro.tokenize(this.value || '').join(' ').trim())
|
||||
|
||||
@@ -62,7 +62,7 @@ export class TestSupport {
|
||||
await collections[0].eraseTx()
|
||||
}
|
||||
|
||||
// Zotero DB access is *really* slow and times out even with chunked transactions. 3.5k references take ~ 50 seconds
|
||||
// Zotero DB access is *really* slow and times out even with chunked transactions. 3.5k items take ~ 50 seconds
|
||||
// to delete.
|
||||
let items = await Zotero.Items.getAll(Zotero.Libraries.userLibraryID, false, true, true)
|
||||
while (items.length) {
|
||||
|
||||
@@ -214,7 +214,7 @@ export const Translators = new class { // eslint-disable-line @typescript-eslint
|
||||
// when exporting file data you get relative paths, when not, you get absolute paths, only one version can go into the cache
|
||||
displayOptions.exportFileData
|
||||
|
||||
// jabref 4 stores collection info inside the reference, and collection info depends on which part of your library you're exporting
|
||||
// jabref 4 stores collection info inside the entry, and collection info depends on which part of your library you're exporting
|
||||
|| (translator.label.includes('TeX') && job.preferences.jabrefFormat >= 4) // eslint-disable-line no-magic-numbers
|
||||
|
||||
// relative file paths are going to be different based on the file being exported to
|
||||
@@ -298,7 +298,7 @@ export const Translators = new class { // eslint-disable-line @typescript-eslint
|
||||
break
|
||||
|
||||
case 'cache':
|
||||
let { itemID, reference, metadata } = e.data
|
||||
let { itemID, entry, metadata } = e.data
|
||||
if (!metadata) metadata = {}
|
||||
|
||||
if (!cache) {
|
||||
@@ -316,13 +316,13 @@ export const Translators = new class { // eslint-disable-line @typescript-eslint
|
||||
if (cached) {
|
||||
// this should not happen?
|
||||
log.debug('unexpected cache store:', query)
|
||||
cached.reference = reference
|
||||
cached.reference = entry
|
||||
cached.metadata = metadata
|
||||
cached = cache.update(cached)
|
||||
|
||||
}
|
||||
else {
|
||||
cache.insert({...query, reference, metadata})
|
||||
cache.insert({...query, reference: entry, metadata})
|
||||
}
|
||||
break
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
"`format-date`=format? (string)": "formats date as by replacing y, m and d in the format",
|
||||
"`ge`=n (number)": "If the length of the output is not greater than or equal to the given number, skip to the next pattern. Alias: `>=[number]`.",
|
||||
"`gt`=n (number)": "If the length of the output is not greater than the given number, skip to the next pattern. Alias: `>[number]`.",
|
||||
"`jieba`": "word segmentation for Chinese references. Uses substantial memory; must be enabled under Preferences -> Better BibTeX -> Advanced -> Citekeys",
|
||||
"`kuromoji`": "word segmentation for Japanese references. Uses substantial memory; must be enabled under Preferences -> Better BibTeX -> Advanced -> Citekeys",
|
||||
"`jieba`": "word segmentation for Chinese items. Uses substantial memory; must be enabled under Preferences -> Better BibTeX -> Advanced -> Citekeys",
|
||||
"`kuromoji`": "word segmentation for Japanese items. Uses substantial memory; must be enabled under Preferences -> Better BibTeX -> Advanced -> Citekeys",
|
||||
"`le`=n (number)": "If the length of the output is not lower than or equal to the given number, skip to the next pattern. Alias: `<=[number]`.",
|
||||
"`local-time`": "transforms date/time to local time. Mainly useful for dateAdded and dateModified as it requires an ISO-formatted input.",
|
||||
"`longer`=n (number)": "If the length of the output is not longer than the given number, skip to the next pattern. Alias: `>[number]`.",
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
"`keywordN`": "Tag number `N`",
|
||||
"`language`": "Tests whether the entry has the given language set, and skips to the next pattern if not",
|
||||
"`lastpage`": "The number of the last page of the publication (See the remark on `firstpage`)",
|
||||
"`library`": "returns the name of the shared group library, or nothing if the reference is in your personal library",
|
||||
"`library`": "returns the name of the shared group library, or nothing if the item is in your personal library",
|
||||
"`month`": "the month of the publication",
|
||||
"`origdate`": "the original date of the publication",
|
||||
"`origyear`": "the original year of the publication",
|
||||
|
||||
@@ -2,7 +2,7 @@ import bs4
|
||||
import sqlite3
|
||||
import uuid
|
||||
import json, jsonpatch
|
||||
import os
|
||||
import os, sys
|
||||
import redo
|
||||
import platform
|
||||
import configparser
|
||||
@@ -24,7 +24,10 @@ import subprocess
|
||||
import atexit
|
||||
import time
|
||||
import datetime
|
||||
from collections import OrderedDict, MutableMapping
|
||||
|
||||
from collections import OrderedDict
|
||||
from collections.abc import MutableMapping
|
||||
|
||||
import sys
|
||||
import threading
|
||||
import socket
|
||||
|
||||
@@ -65,7 +65,7 @@ export const Exporter = new class {
|
||||
Translator.cache[cached ? 'hits' : 'misses'] += 1
|
||||
|
||||
if (cached) {
|
||||
Zotero.write(cached.reference)
|
||||
Zotero.write(cached.entry)
|
||||
this.postfix?.add(cached.metadata)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ export const CSLExporter = new class { // eslint-disable-line @typescript-eslint
|
||||
|
||||
let cached: Cache.ExportedItem
|
||||
if (cached = Zotero.BetterBibTeX.cacheFetch(item.itemID, Translator.options, Translator.preferences)) {
|
||||
items.push(cached.reference)
|
||||
items.push(cached.entry)
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@@ -50,8 +50,8 @@ class WorkerZoteroBetterBibTeX {
|
||||
Zotero.send({ kind: 'progress', percent, translator: workerContext.translator, autoExport: Zotero.config.autoExport })
|
||||
}
|
||||
|
||||
public cacheStore(itemID: number, options: any, prefs: any, reference: string, metadata: any) {
|
||||
if (Zotero.config.preferences.caching) Zotero.send({ kind: 'cache', itemID, reference, metadata })
|
||||
public cacheStore(itemID: number, options: any, prefs: any, entry: string, metadata: any) {
|
||||
if (Zotero.config.preferences.caching) Zotero.send({ kind: 'cache', itemID, entry, metadata })
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
2
typings/cache.d.ts
vendored
2
typings/cache.d.ts
vendored
@@ -7,7 +7,7 @@ export declare namespace Cache {
|
||||
|
||||
interface ExportedItem {
|
||||
itemID: number
|
||||
reference: string // exported reference
|
||||
entry: string // exported entry
|
||||
|
||||
exportNotes: boolean
|
||||
useJournalAbbreviation: boolean
|
||||
|
||||
2
typings/translators.d.ts
vendored
2
typings/translators.d.ts
vendored
@@ -17,7 +17,7 @@ export namespace Translators {
|
||||
| { kind: 'done', output: boolean | string }
|
||||
| { kind: 'debug', message: string }
|
||||
| { kind: 'error', message: string }
|
||||
| { kind: 'cache', itemID: number, reference: string, metadata: any }
|
||||
| { kind: 'cache', itemID: number, entry: string, metadata: any }
|
||||
| { kind: 'item', item: number }
|
||||
| { kind: 'stop' }
|
||||
| { kind: 'progress', percent: number, translator: string, autoExport: number }
|
||||
|
||||
Reference in New Issue
Block a user