Skip to content

Commit

Permalink
file system clearings
Browse files Browse the repository at this point in the history
  • Loading branch information
slnsys committed Jun 24, 2024
1 parent 0248554 commit 2efabfa
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 31 deletions.
22 changes: 13 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
# Changelog for Obsidian Plugin **Canvas2Document**

# 15.05.2024: 1.2.0 Hierarchy, Ordering, more Metadata for navigation
# 2024-06-24: Filesystem clearings
- better filenames and no cluttering of folders: overwriting of files with same name with confirmation
- better filemanagement in writing temp files
- added "Step..." prefixes to commands

# 2024-05-15: 1.2.0 Hierarchy, Ordering, more Metadata for navigation

**Improvements**

* Hierarchy reading: brings the canvas hierarchical relations and ordering as TOC-tree to navigate
* Flexibility in Canvas Reading: recognizes multiple areas with multiple tree/graph structures
* Better metadata on navigational headings: data from nodes and files in navigational headers
* Filenames as headings in resultdoc
- Hierarchy reading: brings the canvas hierarchical relations and ordering as TOC-tree to navigate
- Flexibility in Canvas Reading: recognizes multiple areas with multiple tree/graph structures
- Better metadata on navigational headings: data from nodes and files in navigational headers
- Filenames as headings in resultdoc

# 22.04.2024: 1.1.0 Conversion processing
# 2024-04-22: 1.1.0 Conversion processing

**Feature completion**

Expand All @@ -27,6 +32,5 @@ Conversion now consists of 2 steps: generating a canvas level intermediate docum

## Initial Releases

11.04.

20.03.
2024-04-11: releases for submission
2024-03-20: releases for submission
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ This allows the headings of cards and notes in the outline to be ignored, which

<img src="images/canvas2document.png" alt="steps"/>

You find a more in depth information in the repos [Wiki](https://github.com/slnsys/obsidian-canvas2document/wiki)

# Handling of the generated documents
An adjustment or arrangement of the documents may be necessary because Obsidian Canvas is not necessarily used as a graph with a consistent hierarchical structure, as in the figure:

Expand All @@ -30,4 +32,3 @@ But an obsidian canvas can also look like this, making a simple hierarchical con

# Roadmap
* Options for selecting types of elements to convert to Doc like "only notefiles", "no media"
* Better recognizing of (simple) hierarchical structures in the canvas
88 changes: 68 additions & 20 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class Canvas2DocumentPlugin extends Plugin {

this.addCommand({
id: "run-conversion",
name: "Convert canvas to a longform document",
name: "Step 1 - Convert canvas to a longform document",
callback: async () => {
const canvStruct = await this.readCanvasStruct();
if (canvStruct == false) {
Expand All @@ -35,7 +35,7 @@ export default class Canvas2DocumentPlugin extends Plugin {

this.addCommand({
id: "run-redoc",
name: "Clear canvas2document target document",
name: "Step 2 - Clear canvas2document target document",
callback: async () => {
const canvStruct = await this.readC2Dtarget();
if (canvStruct == false) {
Expand Down Expand Up @@ -130,15 +130,42 @@ export default class Canvas2DocumentPlugin extends Plugin {

let docFilename
if (mdFolderPath == ".") {
docFilename = activeFile.basename + "_" + Math.round(new Date().getTime()/1000) + "_fromC2D.md"
docFilename = activeFile.basename + "_fromC2D.md"
} else {
docFilename = mdFolderPath + "/" + activeFile.basename + "_" + Math.round(new Date().getTime()/1000) + "_fromC2D.md"
docFilename = mdFolderPath + "/" + activeFile.basename + "_fromC2D.md"
}

try {
await this.app.vault.create(docFilename, doccontentstring)


const exists = await this.fsadapter.exists(docFilename);

if (exists) {
const confirmed = await new Promise(resolve => {
const notice = new Notice('File ' + docFilename + ' already exists. Overwrite?', 0);
notice.noticeEl.createEl('button', {text: 'Yes'}).onclick = () => {
notice.hide();
resolve(true);
};
notice.noticeEl.createEl('button', {text: 'No'}).onclick = () => {
notice.hide();
resolve(false);
};
});

if (!confirmed) {
return false; // User chose not to overwrite
}
}

await this.fsadapter.write(docFilename, doccontentstring);




// await this.app.vault.create(docFilename, doccontentstring)
} catch (e) {
console.log("error writing the new cleare doc file " + e)
console.log("error writing the new cleared doc file " + e)
}

const docftab = await this.app.vault.getAbstractFileByPath(docFilename);
Expand Down Expand Up @@ -421,9 +448,9 @@ export default class Canvas2DocumentPlugin extends Plugin {
let canvasFile
let canvasFilename
if (mdFolderPath == ".") {
canvasFilename = activeFile.basename + "_" + Math.round(new Date().getTime()/1000) + "_fromCanvas.md"
canvasFilename = activeFile.basename + "_fromCanvas.md"
} else {
canvasFilename = mdFolderPath + "/" + activeFile.basename + "_" + Math.round(new Date().getTime()/1000) + "_fromCanvas.md"
canvasFilename = mdFolderPath + "/" + activeFile.basename + "_fromCanvas.md"
}

let contentString = "> [!info] This is an automatically generated document from Plugin [Canvas2Document](https://github.com/slnsys/obsidian-canvas2document)\n\> arrange the document as you need with the outline, then call *Clear canvas2document target document*\n\n"
Expand Down Expand Up @@ -469,6 +496,16 @@ export default class Canvas2DocumentPlugin extends Plugin {
//Embedding
contentString += "\n ![[" + cnfname + "]]\n\n"

let canvasnodeFile

try {
let cnfabst = this.app.vault.getAbstractFileByPath(cnfname);
await this.fsadapter.write(cnfname, element[4])
} catch (e) {
console.log(e)
return
}

} else if (element[1] == "link") {
// cnfname = writeworkdir + "/" + "newdoc-node_" + element[0] + " _fromCanvas.md"

Expand Down Expand Up @@ -565,21 +602,33 @@ export default class Canvas2DocumentPlugin extends Plugin {
}
}

let canvasnodeFile

try {
let cnfabst = this.app.vault.getAbstractFileByPath(cnfname);
this.app.vault.delete(cnfabst, true)
canvasnodeFile = this.app.vault.create(cnfname, element[4])
} catch (e) {
console.log(e)
return
}

}

try {
canvasFile = await this.app.vault.create(canvasFilename, contentString)
const exists = await this.fsadapter.exists(canvasFilename);

if (exists) {
const confirmed = await new Promise(resolve => {
const notice = new Notice('File ' + canvasFilename + ' already exists. Overwrite?', 0);
notice.noticeEl.createEl('button', {text: 'Yes'}).onclick = () => {
notice.hide();
resolve(true);
};
notice.noticeEl.createEl('button', {text: 'No'}).onclick = () => {
notice.hide();
resolve(false);
};
});

if (!confirmed) {
return false; // User chose not to overwrite
}
}

await this.fsadapter.write(canvasFilename, contentString);

// canvasFile = await this.app.vault.create(canvasFilename, contentString)
} catch (e) {
console.log("error writing the new doc file " + e)
}
Expand All @@ -595,4 +644,3 @@ export default class Canvas2DocumentPlugin extends Plugin {

}
}

2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "canvas2document",
"name": "Canvas2Document",
"version": "1.2.0",
"version": "1.2.1",
"minAppVersion": "1.5.12",
"description": "Convert a complete Canvas to a long form document, integrating all cards, notes, images and other media content into a single markdown file.",
"author": "slnsys",
Expand Down

0 comments on commit 2efabfa

Please sign in to comment.