Use "PDF" attachment title for all individual PDFs from Mendeley import
https://forums.zotero.org/discussion/comment/327390/#Comment_327390
This commit is contained in:
parent
88f39cba80
commit
e2c4e3e86a
2 changed files with 13 additions and 5 deletions
|
@ -111,6 +111,11 @@ Zotero_Import_Mendeley.prototype.translate = async function (options = {}) {
|
||||||
let docURLs = urls.get(document.id);
|
let docURLs = urls.get(document.id);
|
||||||
let docFiles = files.get(document.id);
|
let docFiles = files.get(document.id);
|
||||||
|
|
||||||
|
// If there's a single PDF file, use "PDF" for the attachment title
|
||||||
|
if (docFiles && docFiles.length == 1 && docFiles[0].fileURL.endsWith('.pdf')) {
|
||||||
|
docFiles[0].title = 'PDF';
|
||||||
|
}
|
||||||
|
|
||||||
// If there's a single PDF file and a single PDF URL and the file exists, make an
|
// If there's a single PDF file and a single PDF URL and the file exists, make an
|
||||||
// imported_url attachment instead of separate file and linked_url attachments
|
// imported_url attachment instead of separate file and linked_url attachments
|
||||||
if (docURLs && docFiles) {
|
if (docURLs && docFiles) {
|
||||||
|
@ -124,7 +129,6 @@ Zotero_Import_Mendeley.prototype.translate = async function (options = {}) {
|
||||||
if (x.fileURL.endsWith('.pdf')) {
|
if (x.fileURL.endsWith('.pdf')) {
|
||||||
x.title = 'PDF';
|
x.title = 'PDF';
|
||||||
x.url = pdfURLs[0];
|
x.url = pdfURLs[0];
|
||||||
x.contentType = 'application/pdf';
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// Remove PDF URL from URLs array
|
// Remove PDF URL from URLs array
|
||||||
|
@ -988,7 +992,8 @@ Zotero_Import_Mendeley.prototype._saveFilesAndAnnotations = async function (file
|
||||||
let options = {
|
let options = {
|
||||||
libraryID,
|
libraryID,
|
||||||
parentItemID,
|
parentItemID,
|
||||||
file: realPath
|
file: realPath,
|
||||||
|
title: file.title
|
||||||
};
|
};
|
||||||
// If we're not set to link files or file is in Mendeley downloads folder, import it
|
// If we're not set to link files or file is in Mendeley downloads folder, import it
|
||||||
if (!this._linkFiles || this._isDownloadedFile(path)) {
|
if (!this._linkFiles || this._isDownloadedFile(path)) {
|
||||||
|
|
|
@ -42,6 +42,7 @@ Zotero.Attachments = new function(){
|
||||||
* @param {nsIFile|String} [options.file] - File to add
|
* @param {nsIFile|String} [options.file] - File to add
|
||||||
* @param {Integer} [options.libraryID]
|
* @param {Integer} [options.libraryID]
|
||||||
* @param {Integer[]|String[]} [options.parentItemID] - Parent item to add item to
|
* @param {Integer[]|String[]} [options.parentItemID] - Parent item to add item to
|
||||||
|
* @param {String} [options.title]
|
||||||
* @param {Integer[]} [options.collections] - Collection keys or ids to add new item to
|
* @param {Integer[]} [options.collections] - Collection keys or ids to add new item to
|
||||||
* @param {String} [options.fileBaseName]
|
* @param {String} [options.fileBaseName]
|
||||||
* @param {String} [options.contentType]
|
* @param {String} [options.contentType]
|
||||||
|
@ -57,6 +58,7 @@ Zotero.Attachments = new function(){
|
||||||
var path = file.path;
|
var path = file.path;
|
||||||
var leafName = file.leafName;
|
var leafName = file.leafName;
|
||||||
var parentItemID = options.parentItemID;
|
var parentItemID = options.parentItemID;
|
||||||
|
var title = options.title;
|
||||||
var collections = options.collections;
|
var collections = options.collections;
|
||||||
var fileBaseName = options.fileBaseName;
|
var fileBaseName = options.fileBaseName;
|
||||||
var contentType = options.contentType;
|
var contentType = options.contentType;
|
||||||
|
@ -91,7 +93,7 @@ Zotero.Attachments = new function(){
|
||||||
else if (libraryID) {
|
else if (libraryID) {
|
||||||
attachmentItem.libraryID = libraryID;
|
attachmentItem.libraryID = libraryID;
|
||||||
}
|
}
|
||||||
attachmentItem.setField('title', newName);
|
attachmentItem.setField('title', title != undefined ? title : newName);
|
||||||
attachmentItem.parentID = parentItemID;
|
attachmentItem.parentID = parentItemID;
|
||||||
attachmentItem.attachmentLinkMode = this.LINK_MODE_IMPORTED_FILE;
|
attachmentItem.attachmentLinkMode = this.LINK_MODE_IMPORTED_FILE;
|
||||||
if (collections) {
|
if (collections) {
|
||||||
|
@ -151,6 +153,7 @@ Zotero.Attachments = new function(){
|
||||||
/**
|
/**
|
||||||
* @param {nsIFile|String} options.file - File to add
|
* @param {nsIFile|String} options.file - File to add
|
||||||
* @param {Integer[]|String[]} [options.parentItemID] - Parent item to add item to
|
* @param {Integer[]|String[]} [options.parentItemID] - Parent item to add item to
|
||||||
|
* @param {String} [options.title]
|
||||||
* @param {Integer[]} [options.collections] - Collection keys or ids to add new item to
|
* @param {Integer[]} [options.collections] - Collection keys or ids to add new item to
|
||||||
* @param {String} [options.contentType] - Content type
|
* @param {String} [options.contentType] - Content type
|
||||||
* @param {String} [options.charset] - Character set
|
* @param {String} [options.charset] - Character set
|
||||||
|
@ -162,6 +165,7 @@ Zotero.Attachments = new function(){
|
||||||
|
|
||||||
var file = Zotero.File.pathToFile(options.file);
|
var file = Zotero.File.pathToFile(options.file);
|
||||||
var parentItemID = options.parentItemID;
|
var parentItemID = options.parentItemID;
|
||||||
|
var title = options.title;
|
||||||
var collections = options.collections;
|
var collections = options.collections;
|
||||||
var contentType = options.contentType || (yield Zotero.MIME.getMIMETypeFromFile(file));
|
var contentType = options.contentType || (yield Zotero.MIME.getMIMETypeFromFile(file));
|
||||||
var charset = options.charset;
|
var charset = options.charset;
|
||||||
|
@ -171,10 +175,9 @@ Zotero.Attachments = new function(){
|
||||||
throw new Error("parentItemID and collections cannot both be provided");
|
throw new Error("parentItemID and collections cannot both be provided");
|
||||||
}
|
}
|
||||||
|
|
||||||
var title = file.leafName;
|
|
||||||
var item = yield _addToDB({
|
var item = yield _addToDB({
|
||||||
file,
|
file,
|
||||||
title,
|
title: title != undefined ? title : file.leafName,
|
||||||
linkMode: this.LINK_MODE_LINKED_FILE,
|
linkMode: this.LINK_MODE_LINKED_FILE,
|
||||||
contentType,
|
contentType,
|
||||||
charset,
|
charset,
|
||||||
|
|
Loading…
Reference in a new issue