Skip to content

Commit

Permalink
feat: check preprint not journalArticle
Browse files Browse the repository at this point in the history
closes: #137
  • Loading branch information
northword committed Mar 17, 2024
1 parent 3824b2d commit a277f93
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 10 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Minor Breaking Changes

- 检测重复条目和检测网页条目现在在每一次 lint 都执行,而不是仅在导入条目时执行。

### Added

- 检测是否有预印本被错误存为期刊文章。close: [#137](https://github.com/northword/zotero-format-metadata/issues/137)

### Fixed

- 修复前一版本从 Semantic Scholar 更新预印本时将期刊文章存为会议的问题。

## [1.14.0] - 2024-03-16

### Added
Expand Down
10 changes: 8 additions & 2 deletions addon/content/preferences.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,24 @@
<!-- 条目 -->
<groupbox>
<label><html:h2 data-l10n-id="section-item"></html:h2></label>
<!-- 添加时检测是否存在重复条目 -->
<!-- 检测是否存在重复条目 -->
<checkbox
data-l10n-id="item-noDuplication"
preference="__prefsPrefix__.noDuplicationItems"
native="true"
/>
<!-- 添加时检测网页条目 -->
<!-- 检测网页条目 -->
<checkbox
data-l10n-id="item-checkWebpage"
preference="__prefsPrefix__.checkWebpage"
native="true"
/>
<!-- 检测预印本误存为期刊文章 -->
<checkbox
data-l10n-id="item-NoPreprintJournalArticle"
preference="__prefsPrefix__.noPreprintJournalArticle"
native="true"
/>
</groupbox>

<!-- 字段:标题 -->
Expand Down
6 changes: 5 additions & 1 deletion addon/locale/en-US/addon.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,8 @@ unimplemented = This feature is unimplemented.
## 重复条目弹窗
dialog-dup-title = Duplicates found
dialog-dup-desc = The currently imported item is a duplicate of the item in the library
dialog-dup-button-merge = Go to merge
dialog-dup-button-merge = Go to merge
## 规则运行警告
checkWebpage-warning = The URL of this WebPage item contains the domain of academic publisher, there may be an exception to the import, please confirm!
NoPreprintJournalArticle-warning = The URL of this journal article item is the domain of the **preprint** server, please confirm that there may be an exception to the import!
2 changes: 2 additions & 0 deletions addon/locale/en-US/preferences.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ item-noDuplication =
.label = No duplicate items added
item-checkWebpage =
.label = No webpage items linked to academic publishers
item-NoPreprintJournalArticle =
.label = No journalArticle items have preprint url
## 标题
section-title = Title
Expand Down
6 changes: 5 additions & 1 deletion addon/locale/zh-CN/addon.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,8 @@ unimplemented = 此功能尚未实现。
## 重复条目弹窗
dialog-dup-title = 发现重复条目
dialog-dup-desc = 以下条目与已有条目重复
dialog-dup-button-merge = 前往合并条目窗格
dialog-dup-button-merge = 前往合并条目窗格
## 规则运行警告
checkWebpage-warning = 监测到您导入了一个 WebPage 条目,其 URL 中包含了主要学术出版商的域名,\n导入可能存在异常,请确认!
NoPreprintJournalArticle-warning = 监测到您导入了一个期刊文章条目,其 URL 中包含了预印本服务器的域名,\n导入可能存在异常,请确认!
2 changes: 2 additions & 0 deletions addon/locale/zh-CN/preferences.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ item-noDuplication =
.label = 不应添加重复条目
item-checkWebpage =
.label = 网页条目不应连接到学术出版社(应为期刊文章或其他类型)
item-NoPreprintJournalArticle =
.label = 预印本不应保存为期刊文章
## 标题
section-title = 标题 Title
Expand Down
1 change: 1 addition & 0 deletions addon/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pref("__prefsPrefix__.richtext.toolBar", true);
pref("__prefsPrefix__.richtext.hotkey", true);
pref("__prefsPrefix__.noDuplicationItems", true);
pref("__prefsPrefix__.checkWebpage", true);
pref("__prefsPrefix__.noPreprintJournalArticle", true);
pref("__prefsPrefix__.titleSentenceCase", true);
pref("__prefsPrefix__.creatorsCase", true);
pref("__prefsPrefix__.lang", true);
Expand Down
5 changes: 3 additions & 2 deletions src/modules/rules-presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ function getStdLintRules() {
// 作者、期刊、年、期、卷、页 -> 判断语言 -> 作者大小写 -> 匹配缩写 -> 匹配地点 -> 格式化日期 -> 格式化DOI
const rules = [];
// getPref("isEnableOtherFields") ? rules.push(new Rules.UpdateMetadata({ mode: "blank" })) : "";
getPref("noDuplicationItems") ? rules.push(new Rules.NoDuplicatItem({})) : "skip";
getPref("checkWebpage") ? rules.push(new Rules.NoWebPageItem({})) : "skip";
getPref("noPreprintJournalArticle") ? rules.push(new Rules.NoPreprintJournalArticle({})) : "skip";
getPref("lang") ? rules.push(new Rules.UpdateItemLanguage({})) : "";
getPref("creatorsCase") ? rules.push(new Rules.CapitalizeCreators({})) : "";
getPref("titleSentenceCase") ? rules.push(new Rules.TitleSentenceCase({})) : "";
Expand All @@ -24,8 +27,6 @@ function getStdLintRules() {

function getNewItemLintRules() {
const rules = [];
getPref("checkWebpage") ? rules.push(new Rules.NoWebPageItem({})) : "skip";
getPref("noDuplicationItems") ? rules.push(new Rules.NoDuplicatItem({})) : "skip";
getPref("lint.onAdded") ? rules.push(getStdLintRules()) : "";
return rules.flat();
}
Expand Down
2 changes: 2 additions & 0 deletions src/modules/rules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import TitleSentenceCase from "./field-title-sentence-case";
import University from "./field-university";
import NoDuplicatItem from "./no-duplicate-item";
import NoExtraZeros from "./no-extra-zeros";
import NoPreprintJournalArticle from "./no-journalArticle-preprint";
import NoWebPageItem from "./no-webpage-item";
import UpdateMetadata from "./retrive-metadata";
import SetFieldValue from "./set-field-value";
Expand All @@ -36,4 +37,5 @@ export default {
NoWebPageItem,
ThesisType,
University,
NoPreprintJournalArticle,
};
27 changes: 27 additions & 0 deletions src/modules/rules/no-journalArticle-preprint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { getString } from "../../utils/locale";
import { progressWindow } from "../../utils/logger";
import { isStringMatchStringInArray } from "../../utils/str";
import { RuleBase, RuleBaseOptions } from "./rule-base";

// 当条目为 webpage ,且 url 为各期刊出版社时,警告

const publisherUrlKeyWords = ["arxiv.org", "biorxiv.org", "medrxiv.org", "chinaxiv.org"];

class NoPreprintJournalArticleOptions implements RuleBaseOptions {}

export default class NoPreprintJournalArticle extends RuleBase<NoPreprintJournalArticleOptions> {
constructor(options: NoPreprintJournalArticleOptions) {
super(options);
}

apply(item: Zotero.Item): Zotero.Item | Promise<Zotero.Item> {
if (item.itemType !== "journalArticle") return item;
const url = item.getField("url");
if (typeof url == "string" && url !== "" && isStringMatchStringInArray(url, publisherUrlKeyWords)) {
ztoolkit.log("The url of this journalArticle item is match with domin of preprint publisher.");
// show alart todo: 对话框完善,通过 URL 获取 DOI 并通过 DOI 强制更新条目类别
progressWindow(getString("NoPreprintJournalArticle-warning"), "fail").startCloseTimer(100000);
}
return item;
}
}
6 changes: 2 additions & 4 deletions src/modules/rules/no-webpage-item.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getString } from "../../utils/locale";
import { progressWindow } from "../../utils/logger";
import { isStringMatchStringInArray } from "../../utils/str";
import { RuleBase, RuleBaseOptions } from "./rule-base";
Expand Down Expand Up @@ -102,10 +103,7 @@ export default class NoWebPageItem extends RuleBase<NoWebPageItemOptions> {
if (typeof url == "string" && url !== "" && isStringMatchStringInArray(url, publisherUrlKeyWords)) {
ztoolkit.log("The url of this webpage item is match with domin of publisher.");
// show alart todo: 对话框完善,通过 URL 获取 DOI 并通过 DOI 强制更新条目类别
progressWindow(
"监测到您导入了一个 WebPage 条目,其 URL 中包含了主要学术出版商的域名,\n导入可能存在异常,请确认!",
"fail",
).startCloseTimer(10000);
progressWindow(getString("checkWebpage-warning"), "fail").startCloseTimer(100000);
}
ztoolkit.log(`The url of this webpage item is not belong to publisher, maybe a normal webpage.`);
return item;
Expand Down

0 comments on commit a277f93

Please sign in to comment.