Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hnykda committed Dec 25, 2024
1 parent 505b320 commit a40f368
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 731 deletions.
407 changes: 0 additions & 407 deletions CHANGELOG.md

Large diffs are not rendered by default.

72 changes: 0 additions & 72 deletions README.ja.md

This file was deleted.

80 changes: 18 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,70 +1,26 @@
[日本語](https://github.com/omnivore-app/logseq-omnivore/blob/develop/README.ja.md)
# logseq-wallabag

# logseq-omnivore
**Heavily under development, not ready for production use yet!**

This plugin enables importing and syncing web clippings, articles, and highlights from the web app [Omnivore.app](https://omnivore.app/) (its server) into a Logseq graph.
This plugin is heavily based on https://github.com/omnivore-app/logseq-omnivore (thank you!). This is an attempt to migrate it to use wallabag. Me - the author - decided to give it a shot after Omnivore closed the shop and I migrated to Wallabag.

## Utilizing "Omnivore.app"
I am very open to accepting more authors and contributors!

1. Register for an account on [Omnivore.app](https://omnivore.app).
- "Omnivore.app" functions as a web tool (web app) specifically designed for web clippings. Instead of simply bookmarking interesting pages in a browser, users can manage them as web clippings, alongside highlights, and organize multiple sites.
- This application is available for free on both desktop and mobile devices, and web clipping data is stored on the server (cloud). With this plugin, one can import and save this data in Logseq. Additionally, any attached notes related to the articles can also be imported.
## How to use
Currently you won't be able to install the plugin in other way then manually building it and loading it as in Development section. Once you have it installed though, you should be able to put in your Wallabag API credentials (similarly to the Chrome plugin, that is Client ID, Client secret, URL, username, password) and run `Cmd+K` and then `Sync wallabag`. It should sync your Wallabag articles.

### Showcase

* Sorted by Date: In Logseq, web clippings and highlights are automatically categorized based on their respective dates.
* Tagging and Referencing: Labels attached to web clippings act as tags with links, allowing users to associate web-clipped pages and their highlights with existing pages (displayed in the "Linked References" section of the page).
> Labeling can be done in Omnivore.app, permitting users to group articles. These labels serve the same role as linking to pages within the Logseq graph but only for articles imported from Omnivore.app to Logseq.
* Filtering: Article data can be filtered using [advanced search syntax](https://docs.omnivore.app/using/search.html).
* As a Storage Location for Web Clippings: Create a graph based on article data from Omnivore.app.
> Whether one wants to add it to an existing graph or create a new one.
* Customization: Custom templates for article data.
### TODO:
- [ ] remove all necessary bloat from the old plugin (the original plugin had much more knobs and switches which we currently do not support). Note that it might be easier to just start from scratch and manually copying the functionality than going from the previous repo first.
- [ ] rename all functions appropriately, ideally in a way where fetching data would be located in the API and the rest of the codebase could be generic
- [ ] make a proper logseq plugin release to use for everyone
- [ ] add more cool features!

## Usage Instructions
## Development
1. install `pnpm`
2. install dependencies `pnpm install`
3. run `pnpm build`
4. go to logseq, enable developer mode, go to plugins, click `load unpacked` and locate the root repository
5. set up the plugin

1. Typically, the plugin is installed from the marketplace.
1. Once the plugin is enabled, the API key issuance page will open (Omnivore's [API Key Issuance Page](https://omnivore.app/settings/api)).
1. Open the plugin settings and register the API key.
1. Click the 🔨 button in the top right toolbar to enable the Omnivore toolbar icon. Clicking that icon opens the [[Omnivore]] page, and synchronization begins at that point. This process may take some time.
> If there are no articles in Omnivore.app's INBOX, importing articles won't be possible. Therefore, it's recommended to add articles to Omnivore.app's INBOX first.
## Synchronization Details

1. The plugin generates a dedicated page named "Omnivore" for synchronization.
1. Content with highlights and additional notes added in Omnivore.app is inserted into article blocks, and custom templates from the plugin settings are applied. This includes attribute data and label links.
1. Synchronization Timing: Synchronization with Omnivore.app starts when the plugin is opened and whenever changes are made to the settings.
> Moreover, adjustments to the API key, search filters, and synchronization frequency can be made in the plugin settings. Manual synchronization with Omnivore.app can also be initiated by clicking the Omnivore icon in the toolbar.
## Demo

### Fetching

![fetching](screenshots/fetching.gif)

### Settings

![settings](screenshots/settings.gif)

## Contacts

Developer: [Hongbo Wu](https://github.com/sywhb) @ [Omnivore](https://github.com/omnivore-app)

## Contributing

- Kudos to [@Brian](https://twitter.com/Bsunter) for the great [guide](https://briansunter.com/graph/#/page/omnivore-logseq-guide?anchor=ls-block-62b28de3-0e9e-456e-bf29-7e2541213aa5) on how to use Omnivore.app and this plugin. [Chinese translation](https://sywhb.github.io/#/page/omnivore-logseq%20指南) by [@吴洪博](https://twitter.com/Sy98715020), Japanese translation by [YU000jp](https://github.com/YU000jp)

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

## License

[MIT](https://choosealicense.com/licenses/mit/)

## FAQ

### I got `TypeError: Cannot read properties of null (reading:’uuid’)` when trying to fetch articles.

This has been fixed in the latest version of the plugin. If you still encounter this issue, please try to click on the empty block on the "Omnivore" page.

### The button to sync with Omnivore is not working after updating settings.

This has been fixed in the latest version of the plugin. If you still encounter this issue, please try to reload the plugin and if it is still not working, please open on issue.
It should pick up the build and as you load it, it should refetch your articles.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "logseq-omnivore",
"name": "logseq-wallabag",
"version": "1.16.5",
"description": "Import Omnivore highlights and articles into Logseq.",
"description": "Import wallabag highlights and articles into Logseq.",
"main": "dist/index.html",
"targets": {
"main": false
},
"default": "dist/index.html",
"author": "Omnivore",
"author": "wallabag",
"repository": {
"type": "git",
"url": "https://github.com/omnivore-app/logseq-omnivore"
"url": "https://github.com/hnykda/wallabag-logseq-sync"
},
"scripts": {
"dev": "vite dev public --base=./",
Expand All @@ -19,8 +19,8 @@
},
"license": "MIT",
"logseq": {
"id": "_logseq-omnivore",
"title": "Omnivore",
"id": "_logseq-wallabag",
"title": "wallabag",
"icon": "./public/icon.png"
},
"dependencies": {
Expand Down
47 changes: 26 additions & 21 deletions src/api/wallabag.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Settings } from '../settings'

interface WallabagTokenResponse {
access_token: string
refresh_token: string
Expand All @@ -23,8 +25,8 @@ export interface WallabagArticle {
title: string
url: string
content: string
created_at: string // Format: "2024-01-20T15:30:45+0100"
updated_at: string // Format: "2024-01-20T15:30:45+0100"
created_at: string // Format: "2024-01-20T15:30:45+0100"
updated_at: string // Format: "2024-01-20T15:30:45+0100"
annotations: WallabagAnnotation[]
tags: string[]
domain_name?: string
Expand Down Expand Up @@ -72,9 +74,9 @@ export class WallabagClient {
this.expireDate = settings.expireDate
}

private async getHeaders(token?: string) {
private getHeaders(token?: string) {
const headers: HeadersInit = {
'Accept': 'application/json',
Accept: 'application/json',
'Content-Type': 'application/json',
}
if (token) {
Expand All @@ -95,42 +97,42 @@ export class WallabagClient {

const response = await fetch(`${this.baseUrl}/oauth/v2/token`, {
method: 'POST',
headers: await this.getHeaders(),
headers: this.getHeaders(),
body: JSON.stringify({
grant_type: 'refresh_token',
refresh_token: this.refreshToken,
client_id: this.clientId,
client_secret: this.clientSecret
})
client_secret: this.clientSecret,
}),
})

if (!response.ok) {
await this.getNewAccessToken()
return
}

const data = await response.json() as WallabagTokenResponse
const data = (await response.json()) as WallabagTokenResponse
this.updateTokens(data)
}

private async getNewAccessToken(): Promise<void> {
const response = await fetch(`${this.baseUrl}/oauth/v2/token`, {
method: 'POST',
headers: await this.getHeaders(),
headers: this.getHeaders(),
body: JSON.stringify({
grant_type: 'password',
client_id: this.clientId,
client_secret: this.clientSecret,
username: this.userLogin,
password: this.userPassword
})
password: this.userPassword,
}),
})

if (!response.ok) {
throw new Error('Failed to get access token')
}

const data = await response.json() as WallabagTokenResponse
const data = (await response.json()) as WallabagTokenResponse
this.updateTokens(data)
}

Expand All @@ -144,7 +146,7 @@ export class WallabagClient {
apiToken: this.apiToken,
refreshToken: this.refreshToken,
expireDate: this.expireDate,
isTokenExpired: false
isTokenExpired: false,
})
}

Expand All @@ -163,7 +165,7 @@ export class WallabagClient {

async getArticles(page = 1): Promise<WallabagResponse> {
console.log(`getArticles called for page ${page}`)

if (this.isTokenExpired()) {
console.log('Token expired, refreshing')
await this.refreshAccessToken()
Expand All @@ -173,30 +175,33 @@ export class WallabagClient {
console.log(`Fetching articles from: ${url}`)

const response = await fetch(url, {
headers: await this.getHeaders(this.apiToken)
headers: this.getHeaders(this.apiToken),
})

if (!response.ok) {
console.error('Failed to fetch articles:', {
status: response.status,
statusText: response.statusText
statusText: response.statusText,
})
throw new Error('Failed to fetch articles')
}

const data = await response.json()
console.log('Response data:', {
const data = (await response.json()) as WallabagResponse
console.debug('Response data:', {
page: data.page,
pages: data.pages,
total: data.total,
itemCount: data._embedded?.items?.length
itemCount: data._embedded?.items?.length,
})

// Log the first article's full data to see the exact format
if (page === 1 && data._embedded?.items?.length > 0) {
console.log('Sample article data:', JSON.stringify(data._embedded.items[0], null, 2))
console.debug(
'Sample article data:',
JSON.stringify(data._embedded.items[0], null, 2)
)
}

return data
}
}
}
Loading

0 comments on commit a40f368

Please sign in to comment.