mirror of
https://github.com/Wanxp/obsidian-douban.git
synced 2026-04-05 01:28:46 +08:00
complete douban book import
This commit is contained in:
parent
3440bf266e
commit
824296a8a7
@ -25,8 +25,8 @@ export const doubanHeadrs = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const DEFAULT_SETTINGS:DoubanPluginSettings = {
|
export const DEFAULT_SETTINGS:DoubanPluginSettings = {
|
||||||
movieTemplate: `
|
movieTemplate:
|
||||||
---
|
`
|
||||||
doubanId: {{id}}
|
doubanId: {{id}}
|
||||||
title: {{title}}
|
title: {{title}}
|
||||||
type: {{type}}
|
type: {{type}}
|
||||||
@ -36,10 +36,10 @@ director: {{director}}
|
|||||||
actor: {{actor}}
|
actor: {{actor}}
|
||||||
author: {{author}}
|
author: {{author}}
|
||||||
url: {{url}}
|
url: {{url}}
|
||||||
image: {{image}}
|
desc: {{desc}}
|
||||||
---`,
|
`,
|
||||||
bookTemplate: `
|
bookTemplate:
|
||||||
---
|
`---
|
||||||
doubanId: {{id}}
|
doubanId: {{id}}
|
||||||
title: {{title}}
|
title: {{title}}
|
||||||
subTitle: {{subTitle}}
|
subTitle: {{subTitle}}
|
||||||
@ -49,18 +49,18 @@ author: {{author}}
|
|||||||
score: {{score}}
|
score: {{score}}
|
||||||
datePublished: {{datePublished}}
|
datePublished: {{datePublished}}
|
||||||
translator: {{translator}}
|
translator: {{translator}}
|
||||||
publish: {{publish}
|
publish: {{publish}}
|
||||||
isbn: {{isbn}}
|
isbn: {{isbn}}
|
||||||
url: {{url}}
|
url: {{url}}
|
||||||
image: {{image}}
|
|
||||||
totalWord: {{totalWord}}
|
|
||||||
totalPage: {{totalPage}}
|
totalPage: {{totalPage}}
|
||||||
price: {{price}}
|
price: {{price}}
|
||||||
tags: Book, {{labels}}
|
tags: Book
|
||||||
|
desc: {{desc}}
|
||||||
---
|
---
|
||||||
|

|
||||||
|
`,
|
||||||
|
// totalWord: {{totalWord}}
|
||||||
|
|
||||||
- Menu
|
|
||||||
{{menu}}`,
|
|
||||||
searchUrl: 'https://www.douban.com/search?q=',
|
searchUrl: 'https://www.douban.com/search?q=',
|
||||||
searchHeaders: JSON.stringify(doubanHeadrs),
|
searchHeaders: JSON.stringify(doubanHeadrs),
|
||||||
dateFormat: "yyyy_MM_DD",
|
dateFormat: "yyyy_MM_DD",
|
||||||
|
|||||||
@ -88,6 +88,35 @@ export class DoubanSettingTab extends PluginSettingTab {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
new Setting(containerEl).setName(i18nHelper.getMessage("book content template")).then((setting) => {
|
||||||
|
setting.addTextArea((textarea) => {
|
||||||
|
setting.descEl.appendChild(
|
||||||
|
createFragment((frag) => {
|
||||||
|
frag.appendText(i18nHelper.getMessage('book content template desc 1'));
|
||||||
|
frag.createEl('br');
|
||||||
|
frag.appendText(i18nHelper.getMessage('book content template desc 2'));
|
||||||
|
frag.createEl('br');
|
||||||
|
frag.appendText(i18nHelper.getMessage('book content template desc 3'));
|
||||||
|
frag.createEl('br');
|
||||||
|
frag.appendText(i18nHelper.getMessage('book content template desc 4'));
|
||||||
|
frag.createEl('br');
|
||||||
|
frag.appendText(i18nHelper.getMessage('book content template desc 5'));
|
||||||
|
frag.createEl('br');
|
||||||
|
frag.appendText(i18nHelper.getMessage('book content template desc 6'));
|
||||||
|
frag.createEl('br');
|
||||||
|
})
|
||||||
|
);
|
||||||
|
textarea.inputEl.addClass("settings_area");
|
||||||
|
textarea.inputEl.setAttr("rows", 10);
|
||||||
|
textarea.setPlaceholder(DEFAULT_SETTINGS.bookTemplate)
|
||||||
|
.setValue(this.plugin.settings.bookTemplate)
|
||||||
|
.onChange(async (value) => {
|
||||||
|
this.plugin.settings.bookTemplate = value;
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
new Setting(containerEl).setName(i18nHelper.getMessage("Person Name Language Mode")).then((setting) => {
|
new Setting(containerEl).setName(i18nHelper.getMessage("Person Name Language Mode")).then((setting) => {
|
||||||
setting.addDropdown((dropdwon) => {
|
setting.addDropdown((dropdwon) => {
|
||||||
setting.descEl.appendChild(
|
setting.descEl.appendChild(
|
||||||
|
|||||||
@ -9,7 +9,6 @@ import DoubanSubject from "douban/model/DoubanSubject";
|
|||||||
|
|
||||||
export default class DoubanBookLoadHandler extends DoubanAbstractLoadHandler<DoubanBookSubject> {
|
export default class DoubanBookLoadHandler extends DoubanAbstractLoadHandler<DoubanBookSubject> {
|
||||||
|
|
||||||
|
|
||||||
parseText(extract: DoubanBookSubject, settings:DoubanPluginSettings): string {
|
parseText(extract: DoubanBookSubject, settings:DoubanPluginSettings): string {
|
||||||
return settings.bookTemplate ? settings.bookTemplate.replaceAll("{{id}}", extract.id)
|
return settings.bookTemplate ? settings.bookTemplate.replaceAll("{{id}}", extract.id)
|
||||||
.replaceAll("{{type}}", extract.type ? extract.type : "")
|
.replaceAll("{{type}}", extract.type ? extract.type : "")
|
||||||
@ -53,9 +52,11 @@ export default class DoubanBookLoadHandler extends DoubanAbstractLoadHandler<Dou
|
|||||||
var type = html(html("head > meta[property= 'og:type']").get(0)).attr("content");
|
var type = html(html("head > meta[property= 'og:type']").get(0)).attr("content");
|
||||||
var author = html(html("head > meta[property= 'book:author']").get(0)).attr("content");
|
var author = html(html("head > meta[property= 'book:author']").get(0)).attr("content");
|
||||||
var isbn = html(html("head > meta[property= 'book:isbn']").get(0)).attr("content");
|
var isbn = html(html("head > meta[property= 'book:isbn']").get(0)).attr("content");
|
||||||
var detailDom = html(html("#info").get(0))
|
var score = html(html("#interest_sectl > div > div.rating_self.clearfix > strong[property= 'v:average']").get(0)).text();
|
||||||
|
var detailDom = html(html("#info").get(0));
|
||||||
var publish = detailDom.find("span.pl");
|
var publish = detailDom.find("span.pl");
|
||||||
|
|
||||||
|
var valueMap = new Map<string, string>();
|
||||||
|
|
||||||
publish.map((index, info) => {
|
publish.map((index, info) => {
|
||||||
let key = html(info).text().trim();
|
let key = html(info).text().trim();
|
||||||
@ -65,7 +66,7 @@ export default class DoubanBookLoadHandler extends DoubanAbstractLoadHandler<Dou
|
|||||||
}else{
|
}else{
|
||||||
value = html(info.next).text().trim();
|
value = html(info.next).text().trim();
|
||||||
}
|
}
|
||||||
|
valueMap.set(BookKeyValueMap.get(key), value);
|
||||||
})
|
})
|
||||||
|
|
||||||
var idPattern = /(\d){5,10}/g;
|
var idPattern = /(\d){5,10}/g;
|
||||||
@ -73,20 +74,20 @@ export default class DoubanBookLoadHandler extends DoubanAbstractLoadHandler<Dou
|
|||||||
|
|
||||||
const result:DoubanBookSubject = {
|
const result:DoubanBookSubject = {
|
||||||
author: [author],
|
author: [author],
|
||||||
translator: [translator],
|
translator: [valueMap.get('translator')],
|
||||||
bookType: "",
|
bookType: "",
|
||||||
image: image,
|
image: image,
|
||||||
datePublished: datePublished?new Date(datePublished[0]):null,
|
datePublished: valueMap.has('datePublished')?new Date(valueMap.get('datePublished')) : null,
|
||||||
totalWord: 0,
|
totalWord: valueMap.has('totalWord') ? Number(valueMap.get('totalWord')) : null,
|
||||||
isbn: isbn,
|
isbn: isbn,
|
||||||
publish: null,
|
publish: valueMap.has('publish') ? valueMap.get('publish') : "",
|
||||||
score: 0,
|
score: Number(score),
|
||||||
originalTitle: "",
|
originalTitle: valueMap.has('originalTitle') ? valueMap.get('originalTitle') : "",
|
||||||
subTitle: "",
|
subTitle: "",
|
||||||
totalPage: 0,
|
totalPage: valueMap.has('originalTitle') ? Number(valueMap.get('totalPage')) : null,
|
||||||
belong: "",
|
belong: "",
|
||||||
menu: [],
|
menu: [],
|
||||||
price: 0,
|
price: valueMap.has('price') ? Number(valueMap.get('price').replace('元', '')) : null,
|
||||||
labels: [],
|
labels: [],
|
||||||
id: id ? id[0]:"",
|
id: id ? id[0]:"",
|
||||||
type: "Book",
|
type: "Book",
|
||||||
@ -101,3 +102,16 @@ export default class DoubanBookLoadHandler extends DoubanAbstractLoadHandler<Dou
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const BookKeyValueMap:Map<string, string> = new Map(
|
||||||
|
[['作者', 'author'],
|
||||||
|
['出版社:', 'publish'],
|
||||||
|
['原作名:', 'originalTitle'],
|
||||||
|
['出版年:', 'datePublished'],
|
||||||
|
['页数:', 'totalPage'],
|
||||||
|
['定价:', 'price'],
|
||||||
|
['装帧:', 'binding'],
|
||||||
|
['丛书:', 'bush'],
|
||||||
|
['ISBN:', 'isbn'],
|
||||||
|
['译者', 'translator'],
|
||||||
|
]
|
||||||
|
);
|
||||||
@ -15,13 +15,21 @@ export default {
|
|||||||
'douban search url desc 5': `Just copy the web address to the current input box.`,
|
'douban search url desc 5': `Just copy the web address to the current input box.`,
|
||||||
|
|
||||||
'movie content template': `Movie Content Template`,
|
'movie content template': `Movie Content Template`,
|
||||||
'movie content template desc 1': `Set markdown template for extract to be inserted.`,
|
'movie content template desc 1': `Set markdown Movie template for extract to be inserted.`,
|
||||||
'movie content template desc 2': `Available template variables are :`,
|
'movie content template desc 2': `Available template variables are :`,
|
||||||
'movie content template desc 3': `{{id}}, {{type}}, {{title}},`,
|
'movie content template desc 3': `{{id}}, {{type}}, {{title}},`,
|
||||||
'movie content template desc 4': `{{score}}, {{datePublished}}, {{director}},`,
|
'movie content template desc 4': `{{score}}, {{datePublished}}, {{director}},`,
|
||||||
'movie content template desc 5': `{{author}}, {{autor}}, {{desc}},`,
|
'movie content template desc 5': `{{author}}, {{actor}}, {{desc}},`,
|
||||||
'movie content template desc 6': `{{image}}, {{url}}`,
|
'movie content template desc 6': `{{image}}, {{url}}`,
|
||||||
|
|
||||||
|
'book content template': `Book Content Template`,
|
||||||
|
'book content template desc 1': `Set markdown Book template for extract to be inserted.`,
|
||||||
|
'book content template desc 2': `Available Book template variables are :`,
|
||||||
|
'book content template desc 3': `{{id}}, {{title}}, {{originalTitle}}, {{subTitle}},`,
|
||||||
|
'book content template desc 4': `{{score}}, {{author}}, {{datePublished}}, {{type}},`,
|
||||||
|
'book content template desc 5': `{{publish}}, {{desc}}, {{translator}}, {{isbn}},`,
|
||||||
|
'book content template desc 6': `{{image}}, {{url}}, {{price}}, {{desc}}, {{totalPage}}`,
|
||||||
|
|
||||||
'Date format': `Date Format`,
|
'Date format': `Date Format`,
|
||||||
'This format will be used when available template variables contain date.':
|
'This format will be used when available template variables contain date.':
|
||||||
`This format will be used when available template variables contain date.`,
|
`This format will be used when available template variables contain date.`,
|
||||||
|
|||||||
@ -23,6 +23,14 @@ export default {
|
|||||||
'movie content template desc 5': `{{author}}, {{autor}}, {{desc}},`,
|
'movie content template desc 5': `{{author}}, {{autor}}, {{desc}},`,
|
||||||
'movie content template desc 6': `{{image}}, {{url}}`,
|
'movie content template desc 6': `{{image}}, {{url}}`,
|
||||||
|
|
||||||
|
'book content template': `书籍文本模板`,
|
||||||
|
'book content template desc 1': `设置选择书籍后导入的文本内容模板,`,
|
||||||
|
'book content template desc 2': `支持以下参数名称 :`,
|
||||||
|
'book content template desc 3': `{{id}}, {{title}}, {{originalTitle}}, {{subTitle}},`,
|
||||||
|
'book content template desc 4': `{{score}}, {{author}}, {{datePublished}}, {{type}},`,
|
||||||
|
'book content template desc 5': `{{publish}}, {{desc}}, {{translator}}, {{isbn}},`,
|
||||||
|
'book content template desc 6': `{{image}}, {{url}}, {{price}}, {{desc}}, {{totalPage}}`,
|
||||||
|
|
||||||
'Date format': `参数日期格式`,
|
'Date format': `参数日期格式`,
|
||||||
'This format will be used when available template variables contain date.':
|
'This format will be used when available template variables contain date.':
|
||||||
`这个格式是给上面获取到的参数进行格式化时显示的内容 .`,
|
`这个格式是给上面获取到的参数进行格式化时显示的内容 .`,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user