generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
288 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,4 @@ jobs: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
pnpm run release | ||
pnpm run version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
# Obsidian ibook Plugin(WIP) | ||
# Obsidian ibook Plugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,5 +31,8 @@ | |
"obsidian": "latest", | ||
"tslib": "2.4.0", | ||
"typescript": "4.7.4" | ||
}, | ||
"dependencies": { | ||
"handlebars": "^4.7.7" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { getAllBookId, getBookById, getAnnotationBookId } from "@/api"; | ||
import { IbookPluginSettings } from '@/config'; | ||
import { Renderer } from '@/renderer'; | ||
import IbookPlugin from '@/plugin' | ||
import * as path from "path"; | ||
export interface IExport { | ||
start(): void; | ||
} | ||
|
||
export class IBookExport implements IExport { | ||
private settings: IbookPluginSettings; | ||
private renderer: Renderer; | ||
public plugin: IbookPlugin; | ||
constructor(settings: IbookPluginSettings, plugin: IbookPlugin) { | ||
this.settings = settings; | ||
this.renderer = new Renderer(this.settings); | ||
this.plugin = plugin; | ||
} | ||
|
||
/** | ||
* During the develop, the following problems will be found | ||
1. ZAEANNOTATION has data, but ZBKLIBRARYASSET has no book information | ||
*/ | ||
async start() { | ||
const getBookId = await getAllBookId(); | ||
|
||
if (getBookId.length > 0) { | ||
for (let i = 0; i < getBookId.length; i++) { | ||
const renderData = await this.getRenderDataById(getBookId[i].ZASSETID); | ||
|
||
if (renderData.annotation.length === 0 || renderData.library.ZTITLE === null) { | ||
continue; | ||
} | ||
const content = this.renderer.render(renderData); | ||
this.save(renderData.library.ZTITLE, content); | ||
} | ||
} | ||
} | ||
|
||
async getRenderDataById(bookId: string) { | ||
const library = await getBookById(bookId); | ||
const annotation = await getAnnotationBookId(bookId); | ||
return { "library": library[0], "annotation": annotation } | ||
} | ||
|
||
|
||
save(contentName: string, content: string) { | ||
try { | ||
this.plugin.app.vault.create( | ||
path.join(this.plugin.settings.output, `${contentName}.md`), | ||
content | ||
); | ||
} catch (error) { | ||
if (!error.message.contains("file already exists")) { | ||
throw error; | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import * as Handlebars from 'handlebars'; | ||
import { IbookPluginSettings } from '@/config'; | ||
import { RendererData } from '@/types'; | ||
|
||
export class Renderer { | ||
private settings: IbookPluginSettings; | ||
|
||
constructor(settings: IbookPluginSettings) { | ||
this.settings = settings; | ||
} | ||
|
||
public render(data: RendererData) { | ||
const source = this.settings.template; | ||
const template = Handlebars.compile(source); | ||
return template(data); | ||
} | ||
} |
Oops, something went wrong.