Skip to content

Commit

Permalink
Support non-ascii b64, only transclude text
Browse files Browse the repository at this point in the history
  • Loading branch information
Ole Eskild Steensen committed Feb 24, 2022
1 parent 3e1c0ad commit 1c898e9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
11 changes: 7 additions & 4 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { App, Notice, Plugin, PluginSettingTab, Setting, getLinkpath, Editor, MarkdownView } from 'obsidian';
import { Octokit } from "@octokit/core";


import { Base64 } from "js-base64";
interface DigitalGardenSettings {
githubToken: string;
githubRepo: string;
Expand Down Expand Up @@ -84,7 +83,8 @@ export default class DigitalGarden extends Plugin {

const octokit = new Octokit({ auth: this.settings.githubToken });

const base64Content = window.btoa(content);

const base64Content = Base64.encode(content);
const path = `src/site/notes/${title}`

const payload = {
Expand Down Expand Up @@ -127,6 +127,9 @@ export default class DigitalGarden extends Plugin {
const tranclusionFileName = transclusionMatch.substring(transclusionMatch.indexOf('[') + 2, transclusionMatch.indexOf(']'));
const tranclusionFilePath = getLinkpath(tranclusionFileName);
const linkedFile = this.app.metadataCache.getFirstLinkpathDest(tranclusionFilePath, filePath);
if(["md", "txt"].indexOf(linkedFile.extension) == -1){
continue;
}
let fileText = await this.app.vault.cachedRead(linkedFile);
fileText = "\n```transclusion\n# " + tranclusionFileName + "\n\n" + fileText + '\n```\n'
//This should be recursive up to a certain depth
Expand Down Expand Up @@ -234,5 +237,5 @@ function arrayBufferToBase64(buffer: ArrayBuffer) {
for (let i = 0; i < len; i++) {
binary += String.fromCharCode(bytes[i]);
}
return window.btoa(binary);
return Base64.btoa(binary);
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"typescript": "4.4.4"
},
"dependencies": {
"@octokit/core": "^3.5.1"
"@octokit/core": "^3.5.1",
"js-base64": "^3.7.2"
}
}

0 comments on commit 1c898e9

Please sign in to comment.