Skip to content

Commit

Permalink
refactor: book search api
Browse files Browse the repository at this point in the history
  • Loading branch information
anpigon committed Aug 17, 2022
1 parent 76cbf8d commit ff8441c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 28 deletions.
56 changes: 36 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ Easily create book notes.

## Demo

![May-05-2022 18-01-01](https://user-images.githubusercontent.com/3969643/166892687-d36868ef-f966-41af-9bb1-88e17ea5753f.gif)
https://user-images.githubusercontent.com/3969643/184918274-8ad24546-2e01-4288-a855-c8eeb1feca7d.mp4

If this plugin helped you and you wish to contribute :)

<a href="https://www.buymeacoffee.com/anpigon" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a>
<a href="https://www.buymeacoffee.com/anpigon" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a>&nbsp;
<a href="https://anpigon.github.io/buymeacoffee/"><img src="https://user-images.githubusercontent.com/3969643/184924261-f0224843-08fa-4bce-af70-dc5db589979f.png" height="41"></a>

<br>

Expand All @@ -33,44 +34,59 @@ Click the link to install the Book Search plugin: [Install Link](https://anpigon

Or, Search in the Obsidian Community plugin. And install it.

![](https://user-images.githubusercontent.com/3969643/166097211-abb60f55-3d77-4de6-9e0d-b681f903aafc.png)
<img width="700" src="https://user-images.githubusercontent.com/3969643/184918934-585375a9-7b25-4905-81c8-5f092ed74991.png">

<br>

## How to use

1. Set the folder to new file location in plugin options. And you can also add a frontmatter that is inserted when creating a note.
![](https://user-images.githubusercontent.com/3969643/162614248-c60baab1-ef26-4f68-bf78-d0bc462e6c41.png)
### 1. Click the ribbon icon, or excute the command "Create new book note".

2. Excute the command "Create new book note".
![](https://user-images.githubusercontent.com/3969643/161973483-ab007598-e0b8-433f-9697-75ee0ef74195.png)
<img width="600" src="https://user-images.githubusercontent.com/3969643/161973483-ab007598-e0b8-433f-9697-75ee0ef74195.png">

3. Search for books by keywords.
![](https://user-images.githubusercontent.com/3969643/161973979-51f642c9-626a-4015-a7e9-dfdbe6ec2cbc.png)
### 2. Search for books by keywords.

4. Select the book from the search results.
![](https://user-images.githubusercontent.com/3969643/161974310-13c3b39b-51dc-472f-b787-db64f74caf74.png)
<img width="600" src="https://user-images.githubusercontent.com/3969643/161973979-51f642c9-626a-4015-a7e9-dfdbe6ec2cbc.png">

5. Voila! A note has been created.
![](https://user-images.githubusercontent.com/3969643/161974593-1b7bfe69-cb9d-47d7-a43d-1d725295a122.png)
### 3. Select the book from the search results.

<img width="600" src="https://user-images.githubusercontent.com/3969643/161974310-13c3b39b-51dc-472f-b787-db64f74caf74.png">

### 4. Voila! A note has been created.

<img width="600" src="https://user-images.githubusercontent.com/3969643/161974593-1b7bfe69-cb9d-47d7-a43d-1d725295a122.png">

<br>

## How to use settings

### <strike>(Deprecated) Text to insert into front matter</strike>
<img width="700" src="https://user-images.githubusercontent.com/3969643/184919550-68eff0e4-2b02-41bb-8f17-30a5354359a3.png">

<strike>You can add the following to the default Front Matter, or create a new Front Matter with the structure you want.</strike>
### New file location

<br>
Set the folder location where the new file is created. Otherwise, a new file is created in the Obsidian Root folder.

### <strike>(Deprecated) Text to insert into content</strike>
### New file name

<strike>You can add text to the content for [Dataview inline metadata](https://blacksmithgu.github.io/obsidian-dataview/data-annotation/#pages).</strike>
You can set the file name format. The default format is `{{title}} - {{author}}`.
You can use `{{DATE}}` or `{{DATE:YYYYMMDD}}` to set a unique file name.

<br>
### Template file

You can set the template file location. There is an example template at the bottom.

### Service Provider

You can set up the services that you use to search for books. Only Google and Naver(네이버) are available now.
To use Naver Book Search, clientId and clientSecret are required. I will explain how to get clientId and clientSecret from Naver on my blog.

### <strike>(Deprecated) Text to insert into front matter</strike>

<strike>You can add the following to the default Front Matter, or create a new Front Matter with the structure you want.</strike> Please use the template file described below.

### <strike>(Deprecated) Text to insert into content</strike>

Please use the template file described below.
<strike>You can add text to the content for [Dataview inline metadata](https://blacksmithgu.github.io/obsidian-dataview/data-annotation/#pages).</strike> Please use the template file described below.

<br>

Expand Down
12 changes: 6 additions & 6 deletions src/apis/google_books_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ export class GoogleBooksApi implements BaseBooksApiImpl {
}

createBookItem(item: VolumeInfo): Book {
const coverUrl = item.imageLinks?.thumbnail?.replace('http:', 'https:') ?? '';
const book: Book = {
title: item.title,
author: this.formatList(item.authors),
category: this.formatList(item.categories),
publisher: item.publisher,
totalPage: item.pageCount,
coverUrl: coverUrl,
coverSmallUrl: this.convertGoogleBookImageURLSize(coverUrl, 1),
coverMediumUrl: this.convertGoogleBookImageURLSize(coverUrl, 2),
coverLargeUrl: this.convertGoogleBookImageURLSize(coverUrl, 3),
publishDate: item.publishedDate ? `${new Date(item.publishedDate).getFullYear()}` : '',
coverUrl: item.imageLinks?.thumbnail ?? '',
coverSmallUrl: item.imageLinks?.smallThumbnail ?? '',
publishDate: item.publishedDate?.slice(0, 4) || '',
description: item.description,
link: item.canonicalVolumeLink || item.infoLink,
previewLink: item.previewLink,
...this.getISBN(item.industryIdentifiers),
};
return book;
Expand Down
2 changes: 1 addition & 1 deletion src/apis/naver_books_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class NaverBooksApi implements BaseBooksApiImpl {
author: item.author,
publisher: item.publisher,
coverUrl: item.image,
publishDate: item.pubdate ? item.pubdate?.slice(0, 4) : '',
publishDate: item.pubdate?.slice(0, 4) || '',
link: item.link,
description: item.description,
isbn: item.isbn,
Expand Down
3 changes: 3 additions & 0 deletions src/models/book.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface Book {
isbn?: string;
link?: string;
description?: string;
previewLink?: string;
}

export class BookModel implements Book {
Expand All @@ -46,6 +47,7 @@ export class BookModel implements Book {
isbn?: string;
link?: string;
description?: string;
previewLink?: string;

constructor(book: Book) {
this.title = book.title ?? '';
Expand All @@ -68,6 +70,7 @@ export class BookModel implements Book {
this.isbn = book.isbn ?? '';
this.link = book.link ?? '';
this.description = book.description ?? '';
this.previewLink = book.previewLink ?? '';
}

toJSON() {
Expand Down
1 change: 0 additions & 1 deletion src/views/book_search_modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export class BookSearchModal extends Modal {
this.okBtnRef.setDisabled(false);
this.okBtnRef.setButtonText('Requesting...');
const searchResults = await this.serviceProvider.getByQuery(this.query);
console.log(searchResults);
this.onSubmit(null, searchResults);
} catch (err) {
this.onSubmit(err);
Expand Down

0 comments on commit ff8441c

Please sign in to comment.