mirror of
https://github.com/Wanxp/obsidian-douban.git
synced 2026-04-04 00:28:43 +08:00
fix search by type error
This commit is contained in:
parent
ba0014a769
commit
5d288bda14
@ -27,7 +27,7 @@ export class DoubanSearchModal extends Modal {
|
||||
const searchInput = new TextComponent(inputs).onChange((searchTerm) => {
|
||||
this.searchTerm = searchTerm;
|
||||
});
|
||||
inputs.addClass("obsidian_douban_search_input");
|
||||
inputs.addClass("obsidian_douban_search_input_content");
|
||||
searchInput.inputEl.size = 40;
|
||||
|
||||
searchInput.inputEl.addEventListener("keydown", (event) => {
|
||||
@ -35,6 +35,7 @@ export class DoubanSearchModal extends Modal {
|
||||
this.close();
|
||||
}
|
||||
});
|
||||
inputs.addClass("obsidian_douban_search_input")
|
||||
|
||||
const typeSelect = content.createDiv("type-select");
|
||||
const typeSelectInput = new DropdownComponent(typeSelect)
|
||||
@ -43,10 +44,11 @@ export class DoubanSearchModal extends Modal {
|
||||
.onChange((value:SupportType) => {
|
||||
this.searchType = value;
|
||||
});
|
||||
typeSelect.addClass('obsidian_douban_search_input');
|
||||
typeSelect.addClass('obsidian_douban_search_input_type');
|
||||
|
||||
|
||||
const controls = contentEl.createDiv("controls");
|
||||
controls.addClass("obsidian_douban_search_controls")
|
||||
const searchButton = controls.createEl("button", {
|
||||
text: i18nHelper.getMessage('110004'),
|
||||
cls: "mod-cta",
|
||||
@ -59,7 +61,7 @@ export class DoubanSearchModal extends Modal {
|
||||
searchButton.addEventListener("click", this.close.bind(this));
|
||||
const cancelButton = controls.createEl("button", {text: i18nHelper.getMessage('110005')});
|
||||
cancelButton.addEventListener("click", this.close.bind(this));
|
||||
cancelButton.addClass("obsidian_douban_search_button");
|
||||
cancelButton.addClass("obsidian_douban_cancel_button");
|
||||
searchInput.inputEl.focus();
|
||||
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ import {SearchResultPageParserInterface} from "./SearchResultPageParserInterface
|
||||
import {SearchPage} from "../../model/SearchPage";
|
||||
import SearchParserHandlerV2 from "../SearchParserV2";
|
||||
|
||||
export class FistAllPageSearchResultPageParser implements SearchResultPageParserInterface {
|
||||
export class AllFirstPageSearchResultPageParser implements SearchResultPageParserInterface {
|
||||
support(type:SupportType, pageNum:number):boolean {
|
||||
return pageNum == 1 && type == SupportType.ALL;
|
||||
}
|
||||
@ -6,7 +6,7 @@ import SearchParserHandler from "../SearchParser";
|
||||
|
||||
export class NotAllPageSearchResultPageParser implements SearchResultPageParserInterface {
|
||||
support(type:SupportType, pageNum:number):boolean {
|
||||
return type != SupportType.ALL;
|
||||
return type != SupportType.ALL && !(pageNum ==1 && type == SupportType.NOTE);
|
||||
}
|
||||
parse(source:string, type:SupportType, pageNum:number, pageSize:number):SearchPage {
|
||||
log.debug("解析给多页面结果");
|
||||
|
||||
@ -0,0 +1,46 @@
|
||||
import {SupportType} from "../../../../constant/Constsant";
|
||||
import {SearchResultPageParserInterface} from "./SearchResultPageParserInterface";
|
||||
import {SearchPage} from "../../model/SearchPage";
|
||||
import SearchParserHandlerV2 from "../SearchParserV2";
|
||||
import {load} from "cheerio";
|
||||
import DoubanSearchResultSubject from "../../model/DoubanSearchResultSubject";
|
||||
|
||||
export class NoteFirstPageSearchResultPageParser implements SearchResultPageParserInterface {
|
||||
support(type:SupportType, pageNum:number):boolean {
|
||||
return pageNum == 1 && type == SupportType.NOTE;
|
||||
}
|
||||
parse(source:string, type:SupportType, pageNum:number, pageSize:number):SearchPage {
|
||||
const pageData = load(source);
|
||||
if (!pageData) {
|
||||
return SearchPage.empty(type);
|
||||
}
|
||||
const doubanSearchResultSubjects = pageData(".result")
|
||||
.get()
|
||||
.map(( item)=> {
|
||||
const title = pageData(item).find("h3 a").text();
|
||||
const url = pageData(item).find("h3 a").attr("href");
|
||||
const id = url.match(/(\d){5,10}/g)[0]
|
||||
const author = pageData(item).find(".info").text();
|
||||
const content = pageData(item).find("p").text();
|
||||
const data: DoubanSearchResultSubject =
|
||||
{
|
||||
id: id ??'',
|
||||
title: title ? title.replaceAll('\n', '').replaceAll(/\s+/g, '') : '-',
|
||||
score: null,
|
||||
cast: author? author.replaceAll('\n', '').replaceAll(/\s+/g, '') : '',
|
||||
type: '日记',
|
||||
desc: content ? content.replaceAll('\n', '').replaceAll(/\s+/g, '') : '-',
|
||||
url: url?? 'https://www.douban.com',
|
||||
image: "",
|
||||
imageUrl: "",
|
||||
publisher: "",
|
||||
datePublished: undefined,
|
||||
genre: []
|
||||
}
|
||||
return data;
|
||||
});
|
||||
return new SearchPage(2000, pageNum, pageSize, type, doubanSearchResultSubjects);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,18 +1,21 @@
|
||||
import {SearchResultPageParserInterface} from "./SearchResultPageParserInterface";
|
||||
import {FistAllPageSearchResultPageParser} from "./FistAllPageSearchResultPageParser";
|
||||
import {AllFirstPageSearchResultPageParser} from "./AllFirstPageSearchResultPageParser";
|
||||
import {OtherAllPageSearchResultPageParser} from "./OtherAllPageSearchResultPageParser";
|
||||
import {SearchPage} from "../../model/SearchPage";
|
||||
import {SupportType} from "../../../../constant/Constsant";
|
||||
import {NotAllPageSearchResultPageParser} from "./NotAllPageSearchResultPageParser";
|
||||
import {NoteFirstPageSearchResultPageParser} from "./NoteFirstPageSearchResultPageParser";
|
||||
|
||||
export class SearchResultPageParser {
|
||||
|
||||
private parsers:SearchResultPageParserInterface[] = [];
|
||||
|
||||
constructor() {
|
||||
this.parsers.push(new FistAllPageSearchResultPageParser());
|
||||
this.parsers.push(new AllFirstPageSearchResultPageParser());
|
||||
this.parsers.push(new OtherAllPageSearchResultPageParser());
|
||||
this.parsers.push(new NotAllPageSearchResultPageParser());
|
||||
this.parsers.push(new NoteFirstPageSearchResultPageParser());
|
||||
|
||||
}
|
||||
|
||||
public parse(source:string, type:SupportType, pageNum:number, pageSize:number):SearchPage {
|
||||
|
||||
@ -13,7 +13,7 @@ export abstract class AbstractSearchPageFetcher implements SearchPageFetcherInte
|
||||
this.settingsManager = settingsManager;
|
||||
}
|
||||
|
||||
support(type: SupportType): boolean {
|
||||
support(type: SupportType, pageNum?:number): boolean {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
fetch(keyword: string, pageNum: number, pageSize: number): Promise<string> {
|
||||
|
||||
@ -6,7 +6,7 @@ export class BookPageSearchPageFetcher extends AbstractSearchPageFetcher {
|
||||
return `https://www.douban.com/j/search?q=${keyword}&start=${start}&cat=1001`;
|
||||
}
|
||||
support(type: SupportType): boolean {
|
||||
return type == SupportType.MOVIE;
|
||||
return type == SupportType.BOOK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
import {AbstractSearchPageFetcher} from "./AbstractSearchPageFetcher";
|
||||
import { SupportType } from "src/org/wanxp/constant/Constsant";
|
||||
|
||||
export class GamePageSearchPageFetcher extends AbstractSearchPageFetcher {
|
||||
getUrl(keyword: string, start: number, pageSize: number): string {
|
||||
return `https://www.douban.com/j/search?q=${keyword}&start=${start}&cat=3114`;
|
||||
}
|
||||
support(type: SupportType): boolean {
|
||||
return type == SupportType.GAME;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
import {AbstractSearchPageFetcher} from "./AbstractSearchPageFetcher";
|
||||
import { SupportType } from "src/org/wanxp/constant/Constsant";
|
||||
|
||||
export class MusicPageSearchPageFetcher extends AbstractSearchPageFetcher {
|
||||
getUrl(keyword: string, start: number, pageSize: number): string {
|
||||
return `https://www.douban.com/j/search?q=${keyword}&start=${start}&cat=1003`;
|
||||
}
|
||||
support(type: SupportType): boolean {
|
||||
return type == SupportType.MUSIC;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
import {AbstractSearchPageFetcher} from "./AbstractSearchPageFetcher";
|
||||
import { SupportType } from "src/org/wanxp/constant/Constsant";
|
||||
|
||||
export class NoteFirstPageSearchPageFetcher extends AbstractSearchPageFetcher {
|
||||
getUrl(keyword: string, start: number, pageSize: number): string {
|
||||
return `https://www.douban.com/search?cat=1015&q=${keyword}`;
|
||||
}
|
||||
support(type: SupportType, pageNum:number): boolean {
|
||||
return type == SupportType.NOTE && pageNum == 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
import {AbstractSearchPageFetcher} from "./AbstractSearchPageFetcher";
|
||||
import { SupportType } from "src/org/wanxp/constant/Constsant";
|
||||
|
||||
export class NotePageSearchPageFetcher extends AbstractSearchPageFetcher {
|
||||
getUrl(keyword: string, start: number, pageSize: number): string {
|
||||
return `https://www.douban.com/j/search?q=${keyword}&start=${start}&cat=1015`;
|
||||
}
|
||||
support(type: SupportType, pageNum:number): boolean {
|
||||
return type == SupportType.NOTE && pageNum > 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -4,6 +4,11 @@ import SettingsManager from "../../../setting/SettingsManager";
|
||||
import {SupportType} from "../../../../constant/Constsant";
|
||||
import {MoviePageSearchPageFetcher} from "./MoviePageSearchPageFetcher";
|
||||
import {BookPageSearchPageFetcher} from "./BookPageSearchPageFetcher";
|
||||
import {GamePageSearchPageFetcher} from "./GamePageSearchPageFetcher";
|
||||
import {MusicPageSearchPageFetcher} from "./MusicPageSearchPageFetcher";
|
||||
import {TheaterPageSearchPageFetcher} from "./TheaterPageSearchPageFetcher";
|
||||
import {NotePageSearchPageFetcher} from "./NotePageSearchPageFetcher";
|
||||
import {NoteFirstPageSearchPageFetcher} from "./NoteFirstPageSearchPageFetcher";
|
||||
|
||||
export class SearchPageFetcher {
|
||||
|
||||
@ -12,12 +17,19 @@ export class SearchPageFetcher {
|
||||
constructor(settingsManager:SettingsManager) {
|
||||
this.fetchers.push(new AllPageSearchPageFetcher(settingsManager));
|
||||
this.fetchers.push(new MoviePageSearchPageFetcher(settingsManager));
|
||||
this.fetchers.push(new BookPageSearchPageFetcher(settingsManager))
|
||||
this.fetchers.push(new BookPageSearchPageFetcher(settingsManager));
|
||||
this.fetchers.push(new GamePageSearchPageFetcher(settingsManager));
|
||||
this.fetchers.push(new MusicPageSearchPageFetcher(settingsManager));
|
||||
this.fetchers.push(new TheaterPageSearchPageFetcher(settingsManager));
|
||||
this.fetchers.push(new NotePageSearchPageFetcher(settingsManager));
|
||||
this.fetchers.push(new NoteFirstPageSearchPageFetcher(settingsManager));
|
||||
|
||||
|
||||
}
|
||||
|
||||
fetch(keyword:string, type:SupportType, pageNum:number, pageSize:number):Promise<string> {
|
||||
for (const fetcher of this.fetchers) {
|
||||
if (fetcher.support(type)) {
|
||||
if (fetcher.support(type, pageNum)) {
|
||||
return fetcher.fetch(keyword, pageNum, pageSize);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@ import {SupportType} from "../../../../constant/Constsant";
|
||||
|
||||
export interface SearchPageFetcherInterface {
|
||||
|
||||
support(type:SupportType):boolean;
|
||||
support(type:SupportType, pageNum?:number):boolean;
|
||||
|
||||
fetch(keyword:string, pageNum:number, pageSize:number):Promise<string>;
|
||||
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
import {AbstractSearchPageFetcher} from "./AbstractSearchPageFetcher";
|
||||
import { SupportType } from "src/org/wanxp/constant/Constsant";
|
||||
|
||||
export class TheaterPageSearchPageFetcher extends AbstractSearchPageFetcher {
|
||||
getUrl(keyword: string, start: number, pageSize: number): string {
|
||||
return `https://www.douban.com/j/search?q=${keyword}&start=${start}&cat=3069`;
|
||||
}
|
||||
support(type: SupportType): boolean {
|
||||
return type == SupportType.THEATER;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -561,7 +561,7 @@ PS: This file could be delete if you want to.
|
||||
'TELEPLAY': `teleplay`,
|
||||
'THEATER': `theater`,
|
||||
|
||||
'MOVIE_AND_TELEPLAY': `movie&teleplay`,
|
||||
'MOVIE_AND_TELEPLAY': `movie&tv`,
|
||||
|
||||
|
||||
'DAY': `D`,
|
||||
|
||||
26
styles.css
26
styles.css
@ -35,21 +35,37 @@
|
||||
|
||||
.obsidian_douban_search_input {
|
||||
margin-left: 5px;
|
||||
float: left;
|
||||
}
|
||||
|
||||
.obsidian_douban_search_input_type {
|
||||
margin-left: 5px;
|
||||
float: right;
|
||||
}
|
||||
|
||||
.obsidian_douban_search_input_content {
|
||||
margin-left: 5px;
|
||||
margin-right: 5px;
|
||||
width: 90%;
|
||||
width: 80%;
|
||||
float: left;
|
||||
|
||||
}
|
||||
|
||||
.obsidian_douban_search_controls {
|
||||
margin-top: 20px;
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
.obsidian_douban_search_button {
|
||||
margin-top: 30px;
|
||||
margin-right: 10px;
|
||||
margin-top: 20px;
|
||||
margin-right: 5px;
|
||||
float:right;
|
||||
}
|
||||
|
||||
.obsidian_douban_cancel_button {
|
||||
margin-top: 20px;
|
||||
margin-right: 5px;
|
||||
float: right;
|
||||
}
|
||||
|
||||
.obsidian_douban_status_button {
|
||||
margin-top: 5px;
|
||||
margin-right: 10px;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user