Skip to content

Commit

Permalink
Merge pull request #10 from etopeter/init
Browse files Browse the repository at this point in the history
Minor fixes and improvements
  • Loading branch information
etopeter authored Jan 15, 2023
2 parents d42df46 + 77762c4 commit c5a68e8
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 43 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,12 @@ Changing page prefix/postfix will create new pages and existing pages will need
### Running the Plugin

- `Load unpacked plugin` in Logseq Desktop client.

## Development

- Install Dependencies run `pnpm i`
- Develop code run `pnpm dev`
- Fomat code run `pnpm format`
- Open Pull Request to main branch.

>Release and Tag will be created automatically on merge to main branch.
62 changes: 31 additions & 31 deletions release.config.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
module.exports = {
branches: ["main"],
plugins: [
[
"@semantic-release/commit-analyzer",
{
preset: "conventionalcommits",
},
],
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
[
"@semantic-release/npm",
{
npmPublish: false,
},
],
"@semantic-release/git",
[
"@semantic-release/exec",
{
prepareCmd:
"zip -qq -r logseq-plugin-audiobookshelf-import-${nextRelease.version}.zip dist docs audiobookshelf.png README.md LICENSE package.json",
},
],
[
"@semantic-release/github",
{
assets: "logseq-plugin-audiobookshelf-import-*.zip",
},
],
branches: ["main"],
plugins: [
[
"@semantic-release/commit-analyzer",
{
preset: "conventionalcommits",
},
],
};
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
[
"@semantic-release/npm",
{
npmPublish: false,
},
],
"@semantic-release/git",
[
"@semantic-release/exec",
{
prepareCmd:
"zip -qq -r logseq-plugin-audiobookshelf-import-${nextRelease.version}.zip dist docs audiobookshelf.png README.md LICENSE package.json",
},
],
[
"@semantic-release/github",
{
assets: "logseq-plugin-audiobookshelf-import-*.zip",
},
],
],
};
33 changes: 22 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
IBatchBlock,
LSPluginBaseInfo,
PageEntity,
IAppProxy,
} from "@logseq/libs/dist/LSPlugin";

import { format } from "date-fns";
Expand All @@ -21,6 +20,7 @@ import {
createFilter,
abLog,
seconds_human_readable,
updateStatus,
} from "./utils";

import { render } from "mustache";
Expand Down Expand Up @@ -113,7 +113,8 @@ async function createPage(
sibling: false,
}
);
//await logseq.Editor.insertBatchBlock(firstBlock!.uuid, blocks.slice(1), {sibling: true})

updateStatus("Created page: " + title);
return true;
} else if (pageBlocksTree !== null && pageBlocksTree.length === 1) {
// createFirstBlock: false creates a block to title if the name contains invalid characters
Expand All @@ -122,10 +123,11 @@ async function createPage(
_first!.uuid,
_first.content + "\n" + blocks[0].content
);
//await logseq.Editor.insertBatchBlock(_first!.uuid, blocks.slice(1), {sibling: true})

updateStatus("Updated page: " + title);
return true;
}
logseq.App.showMsg(`Error creating "${title}", page not created`, "warning");
logseq.UI.showMsg(`Error creating "${title}", page not created`, "warning");
return false;
}

Expand Down Expand Up @@ -155,10 +157,19 @@ async function updatePage(page: PageEntity, blocks: Array<IBatchBlock>) {

// Update only if update property is set to true or is not set at all
if (updateBlock || updateBlock === null) {
await logseq.Editor.updateBlock(_first!.uuid, blocks[0].content);
// Update only if content is different
const currentBlock = await logseq.Editor.getBlock(_first!.uuid);
if (currentBlock?.content !== blocks[0].content) {
if (currentBlock) {
abLog("index", currentBlock.content.toString());
}
abLog("index", blocks[0].content.toString());
await logseq.Editor.updateBlock(_first!.uuid, blocks[0].content);
updateStatus("Updated page: " + page.originalName);
}
}
} else {
logseq.App.showMsg(
logseq.UI.showMsg(
`Error updating "${page.originalName}", page not loaded`,
"error"
);
Expand Down Expand Up @@ -210,7 +221,7 @@ const fetchAudiobookshelf = async (inBackground = false) => {
let singlePageStateTargetBlock: BlockEntity | null = null;

try {
!inBackground && (await logseq.App.showMsg("🚀 Fetching books ..."));
!inBackground && updateStatus(fetchingTitle);

// SinglePage prep
if (singlePageModeEnabled) {
Expand Down Expand Up @@ -342,7 +353,7 @@ const fetchAudiobookshelf = async (inBackground = false) => {
);

abLog(
"fetchAudiobookshelf",
"index",
book.media.metadata.title + " started " + itemStartedDate
);
const singlePageRenderedTemplate = render(singlePageItemTemplate, {
Expand Down Expand Up @@ -473,20 +484,20 @@ const fetchAudiobookshelf = async (inBackground = false) => {

// Check if page exists
if (page !== null && updatePages) {
abLog("fetchAudiobookshelf", "Updating page " + renderedTitle);
abLog("index", "Updating page " + renderedTitle);
const updated = await updatePage(page, [block]);

if (updated) {
abLog(
"fetchAudiobookshelf",
"index",
"Updating page " + renderedTitle + " completed"
);
} else {
console.info("Error updating page " + renderedTitle);
}
} else {
// new page
abLog("fetchAudiobookshelf", "Creating page " + renderedTitle);
abLog("index", "Creating page " + renderedTitle);

const created = await createPage(renderedTitle, [block]);
if (created) {
Expand Down
2 changes: 1 addition & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export const settingsSchema: SettingSchemaDesc[] = [
type: "enum",
default: [],
title: "Enable debugging? (Default: None)",
enumChoices: ["fetchAudiobookshelf", "utils"],
enumChoices: ["index", "utils"],
enumPicker: "checkbox",
description: "Select the files to enable debugging for.",
},
Expand Down
4 changes: 4 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,7 @@ export function seconds_human_readable(seconds: number) {
"s"
);
}

export function updateStatus(msg: string) {
logseq.UI.showMsg(msg);
}

0 comments on commit c5a68e8

Please sign in to comment.