Skip to content

Commit

Permalink
fix: ignore case when lookup journal abbr
Browse files Browse the repository at this point in the history
fix: #241
  • Loading branch information
northword committed Oct 22, 2024
1 parent 4a5205c commit 5813c60
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Ignore case when lookup journal abbrev. closes: [#241](https://github.com/northword/zotero-format-metadata/issues/241)

## [1.20.0] - 2024-10-17

### Added
Expand Down
14 changes: 9 additions & 5 deletions src/modules/rules/field-journalAbbr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ export class UpdateJournalAbbr extends RuleBase<UpdateJournalAbbrOptions> {
throw new Error("The custom journalAbbr file not exist.");
}

const normalizePublicationTitle = normalizeKey(publicationTitle);

if (customAbbrDataPath.endsWith(".json")) {
const customAbbrData = (await Zotero.File.getContentsAsync(customAbbrDataPath)) as string;
if (typeof customAbbrData !== "string" || customAbbrData === "") {
Expand All @@ -156,10 +158,12 @@ export class UpdateJournalAbbr extends RuleBase<UpdateJournalAbbrOptions> {

try {
const data = JSON.parse(customAbbrData);
const abbr = (data[publicationTitle] as string) ?? undefined;
if (!abbr)
ztoolkit.log("[Abbr] 自定义缩写未匹配");
return abbr;
for (const term in data) {
if (normalizeKey(term) === normalizePublicationTitle && data[term])
return data[term];
}
ztoolkit.log("[Abbr] 自定义缩写未匹配");
return undefined;
}
catch (e) {
throw new Error(`JSON Syntax Error, ${e}`);
Expand All @@ -176,7 +180,7 @@ export class UpdateJournalAbbr extends RuleBase<UpdateJournalAbbrOptions> {
ztoolkit.log(`[Abbr] Custom terms:`, resolvedTerms);

for (const term of resolvedTerms) {
if (term.publicationTitle === publicationTitle)
if (normalizeKey(term.publicationTitle) === normalizePublicationTitle)
return term.abbr;
}
}
Expand Down

0 comments on commit 5813c60

Please sign in to comment.