@a9i5k4/dsh-literature 0.2.8 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client.js +69 -13
- package/lib/index.js +53 -15
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1768,7 +1768,11 @@ var cite_exports = {};
|
|
|
1768
1768
|
__export(cite_exports, {
|
|
1769
1769
|
bibtex: () => bibtex,
|
|
1770
1770
|
cite: () => cite,
|
|
1771
|
-
|
|
1771
|
+
citeDetailed: () => citeDetailed,
|
|
1772
|
+
listStyles: () => listStyles,
|
|
1773
|
+
segmentsToHtml: () => segmentsToHtml,
|
|
1774
|
+
stripItalic: () => stripItalic,
|
|
1775
|
+
toSegments: () => toSegments
|
|
1772
1776
|
});
|
|
1773
1777
|
function authorsList(record, { max = 99, ellipsis = ", et al." } = {}) {
|
|
1774
1778
|
const list = record.authors ?? [];
|
|
@@ -1802,7 +1806,7 @@ function apa(record) {
|
|
|
1802
1806
|
const title = (record.title ?? "Untitled").trim();
|
|
1803
1807
|
if (record.itemType === "journalArticle" || record.itemType === "preprint") {
|
|
1804
1808
|
const journal = record.container ? `*${record.container}*, ` : "";
|
|
1805
|
-
const vol = record.volume ?
|
|
1809
|
+
const vol = record.volume ? `*${record.volume}*` : "";
|
|
1806
1810
|
const issue = record.issue ? `(${record.issue})` : "";
|
|
1807
1811
|
const pages = pagesStr(record) ? `, ${pagesStr(record)}` : "";
|
|
1808
1812
|
const volPart = vol || issue || pages ? `${vol}${issue}${pages}. ` : "";
|
|
@@ -1884,11 +1888,11 @@ function chicago(record) {
|
|
|
1884
1888
|
const who = list.length ? list.map((a) => `${a.firstName ?? ""} ${a.lastName ?? ""}`.trim()).join(", ") + ". " : "";
|
|
1885
1889
|
const title = (record.title ?? "Untitled").trim();
|
|
1886
1890
|
if (record.itemType === "journalArticle" || record.itemType === "preprint") {
|
|
1887
|
-
const journal = record.container ? `
|
|
1891
|
+
const journal = record.container ? ` *${record.container}*` : "";
|
|
1888
1892
|
const vol = record.volume ? ` ${record.volume}` : "";
|
|
1889
1893
|
const issue = record.issue ? `, no. ${record.issue}` : "";
|
|
1890
1894
|
const pages = pagesStr(record) ? `: ${pagesStr(record)}` : "";
|
|
1891
|
-
return `${who}"${title}
|
|
1895
|
+
return `${who}"${title}."${journal}${vol}${issue} (${yearStr(record)})${pages}.`.replace(/\s+/g, " ").replace(/ ,/g, ",").trim();
|
|
1892
1896
|
}
|
|
1893
1897
|
const pub = record.publisher ? ` ${record.publisher},` : "";
|
|
1894
1898
|
return `${who}*${title}.*${pub} ${yearStr(record)}.`.trim();
|
|
@@ -1930,22 +1934,56 @@ function bibtex(record) {
|
|
|
1930
1934
|
const body = fields.map(([k, v]) => ` ${k} = {${bibtexEscape(v)}}`).join(",\n");
|
|
1931
1935
|
return "@" + type + "{" + key + ",\n" + body + "\n}\n";
|
|
1932
1936
|
}
|
|
1937
|
+
function stripItalic(text) {
|
|
1938
|
+
return String(text ?? "").replace(/\*([^*]+)\*/g, "$1");
|
|
1939
|
+
}
|
|
1940
|
+
function toSegments(text) {
|
|
1941
|
+
const s = String(text ?? "");
|
|
1942
|
+
const out = [];
|
|
1943
|
+
const re = /\*([^*]+)\*/g;
|
|
1944
|
+
let last = 0;
|
|
1945
|
+
let m;
|
|
1946
|
+
while (m = re.exec(s)) {
|
|
1947
|
+
if (m.index > last) out.push({ text: s.slice(last, m.index) });
|
|
1948
|
+
out.push({ text: m[1], italic: true });
|
|
1949
|
+
last = m.index + m[0].length;
|
|
1950
|
+
}
|
|
1951
|
+
if (last < s.length) out.push({ text: s.slice(last) });
|
|
1952
|
+
return out.length ? out : [{ text: s }];
|
|
1953
|
+
}
|
|
1954
|
+
function escapeHtml(text) {
|
|
1955
|
+
return String(text ?? "").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
1956
|
+
}
|
|
1957
|
+
function segmentsToHtml(segments) {
|
|
1958
|
+
return segments.map((seg) => seg.italic ? `<i>${escapeHtml(seg.text)}</i>` : escapeHtml(seg.text)).join("");
|
|
1959
|
+
}
|
|
1933
1960
|
function cite(record, opts = {}) {
|
|
1961
|
+
return citeDetailed(record, opts).text;
|
|
1962
|
+
}
|
|
1963
|
+
function citeDetailed(record, opts = {}) {
|
|
1934
1964
|
const style = STYLES[opts.style] ?? STYLES.apa;
|
|
1935
1965
|
const mode = opts.mode ?? "reference";
|
|
1936
|
-
if (opts.style === "bibtex")
|
|
1966
|
+
if (opts.style === "bibtex") {
|
|
1967
|
+
const text2 = style.format(record);
|
|
1968
|
+
return { text: text2, segments: [{ text: text2 }], html: escapeHtml(text2), style: opts.style, mode: "reference" };
|
|
1969
|
+
}
|
|
1970
|
+
let raw;
|
|
1937
1971
|
if (mode === "intext") {
|
|
1938
1972
|
if (opts.style === "gb") {
|
|
1939
|
-
|
|
1973
|
+
raw = `\uFF08${authorsShortGb(record)}\uFF0C${yearStr(record)}\uFF09`;
|
|
1974
|
+
} else {
|
|
1975
|
+
raw = `(${authorsShort(record)}, ${yearStr(record)})`;
|
|
1940
1976
|
}
|
|
1941
|
-
|
|
1942
|
-
}
|
|
1943
|
-
if (mode === "direct") {
|
|
1977
|
+
} else if (mode === "direct") {
|
|
1944
1978
|
const pages = opts.pages ? opts.style === "gb" ? `\uFF0C\u7B2C ${opts.pages} \u9875` : `, p. ${opts.pages}` : "";
|
|
1945
|
-
if (opts.style === "gb")
|
|
1946
|
-
|
|
1979
|
+
if (opts.style === "gb") raw = `\u201C${(record.title ?? "").trim()}\u201D\uFF08${authorsShortGb(record)}\uFF0C${yearStr(record)}${pages}\uFF09`;
|
|
1980
|
+
else raw = `"${(record.title ?? "").trim()}" (${authorsShort(record)}, ${yearStr(record)}${pages})`;
|
|
1981
|
+
} else {
|
|
1982
|
+
raw = style.format(record);
|
|
1947
1983
|
}
|
|
1948
|
-
|
|
1984
|
+
const text = stripItalic(raw);
|
|
1985
|
+
const segments = toSegments(raw);
|
|
1986
|
+
return { text, segments, html: segmentsToHtml(segments), style: opts.style ?? "apa", mode };
|
|
1949
1987
|
}
|
|
1950
1988
|
function authorsShortGb(record) {
|
|
1951
1989
|
const list = record.authors ?? [];
|
|
@@ -35823,13 +35861,13 @@ async function handler(req, res, ctx) {
|
|
|
35823
35861
|
writeJson(res, 404, { error: "\u6761\u76EE\u7F3A\u5C11\u5143\u6570\u636E\uFF0C\u65E0\u6CD5\u751F\u6210\u5F15\u7528", code: "noMetadataCite" });
|
|
35824
35862
|
return;
|
|
35825
35863
|
}
|
|
35826
|
-
const {
|
|
35827
|
-
const
|
|
35864
|
+
const { citeDetailed: citeDetailed2 } = await Promise.resolve().then(() => (init_cite(), cite_exports));
|
|
35865
|
+
const detail = citeDetailed2(item.record, {
|
|
35828
35866
|
style: body?.style ?? "apa",
|
|
35829
35867
|
mode: body?.mode ?? "reference",
|
|
35830
35868
|
pages: body?.pages
|
|
35831
35869
|
});
|
|
35832
|
-
writeJson(res, 200, {
|
|
35870
|
+
writeJson(res, 200, { ...detail, style: body?.style ?? "apa", mode: body?.mode ?? "reference" });
|
|
35833
35871
|
return;
|
|
35834
35872
|
}
|
|
35835
35873
|
if (head === "scan-dir" && methodOk(req, "POST")) {
|
package/package.json
CHANGED