Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 7: Import fails. Blank Screen. No Error Messages. #9

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Google Keep Import Plugin

In case it's not glaringly obvious: This is a fork from [daledesilva/obsidian_google-keep-import](https://github.com/daledesilva/obsidian_google-keep-import)

Google Keep Import is a plugin for [Obsidian](https://obsidian.md) that enables easily importing an exported set of backup notes and related attachments from Google Keep.

<div>
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "google-keep-import",
"name": "Google Keep Import",
"description": "Allows import of Google Keep backup json files and their attachments. Can also be used to import other files.",
"version": "1.0.1",
"version": "1.0.3",
"author": "Dale de Silva",
"minAppVersion": "1.1.10",
"authorUrl": "https://designdebt.club",
Expand Down
45 changes: 44 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
},
"dependencies": {
"esbuild-plugin-copy": "^2.0.1",
"esbuild-sass-plugin": "^2.4.4"
"esbuild-sass-plugin": "^2.4.4",
"sanitize-filename": "^1.6.3"
}
}
41 changes: 36 additions & 5 deletions src/logic/import-logic.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DataWriteOptions, Notice, Plugin, TAbstractFile, TFile, TFolder, Vault } from "obsidian";
import GoogleKeepImportPlugin from "src/main";
import { ImportProgressModal } from "src/modals/import-progress-modal/import-progress-modal";
import { filenameSanitize, getFileExtension } from "./string-processes";
import { getFileExtension, stripFileExtension } from "./string-processes";
import { CreatedDateTypes, PluginSettings } from "src/types/plugin-settings";
import { KeepJson, objectIsKeepJson } from "src/types/keep-data";
import { IgnoreImportReason, ImportResult, LogStatus as LogStatus } from "src/types/results";
Expand Down Expand Up @@ -374,10 +374,13 @@ async function importJson(vault: Vault, folder: TFolder, file: File, settings: P
}




const path = `${folder.path}/${filenameSanitize(content.title || file.name)}`; // TODO: Strip file extension from filename

var sanitize = require("sanitize-filename");
let fileName = file.name ;
if (content.title === "")
{
fileName = stripFileExtension(file.name);
}
const path = `${folder.path}/${sanitize(content.title || fileName )}`; // TODO: Strip file extension from filename


// TODO: Refactor this as createNewMarkdownFile function
Expand Down Expand Up @@ -411,7 +414,35 @@ async function importJson(vault: Vault, folder: TFolder, file: File, settings: P
}


try {
if (content.annotations) //wild guess
{

await vault.append(fileRef, `\n\n`);
await vault.append(fileRef, `| | |\n`);
await vault.append(fileRef, `|---|----|\n`);
for(let i=0; i<content.annotations.length; i++) {
//Might be better as front-matter, but for righ now...
let sDescription = content.annotations[i].description;
sDescription = sDescription.replace("\n","<br>");

await vault.append(fileRef, `${`|**Description**| ${sDescription}|`}\n`);
await vault.append(fileRef, `${`|**Source**| ${content.annotations[i].source}|`}\n`);
await vault.append(fileRef, `${`|**Title**| ${content.annotations[i].title}|` }\n`);
await vault.append(fileRef, `${`|**URL**| ${content.annotations[i].url}|`}\n`);
await vault.append(fileRef, `|<hr>|<hr>|\n`);
}
}
}
catch (error) {
result.logStatus = LogStatus.Error;
result.error = error;
result.details = 'Error adding Annotations file.'
return resolve(result);
}



// TODO: Refactor this as appendTextContent
// Add in text content
try {
Expand Down
10 changes: 10 additions & 0 deletions src/logic/string-processes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,14 @@ export function getFileExtension(filename: string): string {
} else {
return '';
}
}

/**
* Strips the file extension when passed a filename string.
*/
export function stripFileExtension(filename: string): string {
let split = filename.split('.');
split.pop();
let finalName = split.join(".");
return finalName;
}
8 changes: 8 additions & 0 deletions src/types/keep-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ export interface KeepAttachment {
mimetype: string;
}

export interface KeepAnnotation {
description: string;
source: string;
title: string;
url: URL;

}
export interface KeepJson {
annotations: KeepAnnotation[];
color: string;
createdTimestampUsec: number;
isArchived: boolean;
Expand Down