Skip to content

Commit

Permalink
feat(SinglePage): Publish updates for 1 page only
Browse files Browse the repository at this point in the history
Publish the currently open page only. This will still create blank pages for any other pages not created yet to support Wikilinks but will not publish their content just an empty body saying "Page not published yet".
  • Loading branch information
andymac4182 committed Apr 11, 2023
1 parent 5e8a4a5 commit 41e5ac4
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Publisher.ts
Expand Up @@ -80,7 +80,7 @@ function flattenTree(

export class Publisher {
confluenceClient: ConfluenceClient;
blankPageAdf: string = JSON.stringify(doc(p("Blank page to replace")));
blankPageAdf: string = JSON.stringify(doc(p("Page not published yet")));
adaptor: LoaderAdaptor;
settings: MyPluginSettings;
mermaidRenderer: MermaidRenderer;
Expand All @@ -98,7 +98,7 @@ export class Publisher {
this.confluenceClient = confluenceClient;
}

async doPublish(): Promise<UploadResults> {
async doPublish(publishFilter?: string): Promise<UploadResults> {
const parentPage = await this.confluenceClient.content.getContentById({
id: this.settings.confluenceParentId,
expand: ["body.atlas_doc_format", "space"],
Expand All @@ -118,7 +118,7 @@ export class Publisher {
parentPage.id,
false
);
const confluencePagesToPublish = flattenTree(confluencePageTree);
let confluencePagesToPublish = flattenTree(confluencePageTree);

const fileToPageIdMap: Record<string, AdfFile> = {};

Expand Down Expand Up @@ -170,6 +170,12 @@ export class Publisher {
}) as JSONDocNode;
});

if (publishFilter) {
confluencePagesToPublish = confluencePagesToPublish.filter(
(file) => file.file.absoluteFilePath === publishFilter
);
}

const adrFileTasks = confluencePagesToPublish.map((file) => {
return this.publishFile(file);
});
Expand Down
43 changes: 43 additions & 0 deletions src/main.ts
Expand Up @@ -148,6 +148,49 @@ export default class MyPlugin extends Plugin {
}
);

this.addCommand({
id: "obsidian-confluence-publish-current",
name: "Publish Current File to Confluence",
checkCallback: (checking: boolean) => {
if (!this.isSyncing) {
if (!checking) {
this.isSyncing = true;
this.publisher
.doPublish(this.activeLeafPath(this.workspace))
.then((stats) => {
new CompletedModal(this.app, {
uploadResults: stats,
}).open();
})
.catch((error) => {
if (error instanceof Error) {
new CompletedModal(this.app, {
uploadResults: {
successfulUploads: 0,
errorMessage: error.message,
failedFiles: [],
},
}).open();
} else {
new CompletedModal(this.app, {
uploadResults: {
successfulUploads: 0,
errorMessage:
stringifyObject(error),
failedFiles: [],
},
}).open();
}
})
.finally(() => {
this.isSyncing = false;
});
}
return true;
}
},
});

this.addCommand({
id: "obsidian-confluence-publish-all",
name: "Publish All to Confluence",
Expand Down

0 comments on commit 41e5ac4

Please sign in to comment.