Skip to content

Commit

Permalink
Merge pull request #7 from JonasSchatz/dailynotes
Browse files Browse the repository at this point in the history
Dailynotes
  • Loading branch information
JonasSchatz authored Dec 18, 2020
2 parents 03b3b2b + dfb38c6 commit acfe0a2
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 32 deletions.
31 changes: 17 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,45 @@ If you don't know what a Zettelkasten is, there are many resources on the web, b
## Recommended Extensions
To harness the full power of markdown documents in VS Code, [Markdown Preview Enhanced](https://marketplace.visualstudio.com/items?itemName=shd101wyy.markdown-preview-enhanced) is recommended.
For visualizing the relationships between nodes, [Markdown Links](https://marketplace.visualstudio.com/items?itemName=tchayen.markdown-links) is also recommended. It uses D3's Force Graph under the hood, so it is likely to not be a scaleable solution. Codekasten has its own graph visualization view, heavily based on Markdown Links. In future versions I plan to move this implementation to use [force-graph](https://github.com/vasturiano/force-graph) instead. However, this needs to wait until either [this issue](https://github.com/foambubble/foam/issues/378) or [this issue](https://github.com/microsoft/vscode/issues/112396) get solved.
For easy pasting of images, use [Paste Image](https://marketplace.visualstudio.com/items?itemName=mushan.vscode-paste-image). Note that this is not maintained anymore, but forks do exists.
For easy insertion of images, use [Paste Image](https://marketplace.visualstudio.com/items?itemName=mushan.vscode-paste-image). Note that this is not maintained anymore, but forks do exists.

## Features
Currently supported:
- Create a new Note, based on a user-provided template, and the currently selected text
- Easily create new Notes:
- Based on user-supplied templates
- Selected text can be used to pre-fill these templates
- Automatically create daily notes
- Search for notes and insert them as links
- See the notes that link to the currently open node in the left sidebar
- See the notes that share tags with the currently open node, also in the left sidebar
- Graph visualization using D3 (for issues see above)
- Graph visualization


## Setup and Extension Settings
There are no changeable settings in VS Code.
When creating a new note, the extension expects a folder `.codekasten/templates`, containing templates as `.md` files.

## Roadmap

Short-term:
- Solve the bug with the graph-visualization
- Support Daily Notes
- Clean up duplicate/messy code, write more docstrings and tests
- Cleanup Scripts: Find Stubs and unlinked images. Maybe find unlinked notes and make it a challenge to connect them to the bulk of knowledge.
- Add more information to the Graphviz

Mid-term:
- Make the extension more customizable, e.g. let the user provide glob-patterns for which files should be included in the graph visualization.
- Include a Template with the neccessary folder structure and some smart initial values for the settings into the Repo.
- Cleanup Scripts: Find Stubs and unlinked images. Maybe find unlinked notes and make it a challenge to connect them to the bulk of knowledge.
- Handle images: Right-click to change to HTML image tags with size.

Long-term:
- Implement or find a more robust Markdown Parser. Do own syntax highlighting (e.g. detected links), which might be cool and also help with debugging.

## Release Notes

### 0.0.2
Current working version.
I have not made a release yet, because last time it broke my debugging pipeline.
Also I have no idea what changed between this and 0.0.1. I'm bad at this.

### 0.0.1
Initial release.
## 0.1.0
Date: 2020-12-18
New Features:
- Create new notes
- Search for notes and insert them as links
- See backlinks and notes with shared tags in the left sidebar
- Graph visualization
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"url": "https://github.com/JonasSchatz/codekasten",
"type": "git"
},
"version": "0.0.1",
"version": "0.1.0",
"license": "MIT",
"publisher": "jonasschatz",
"engines": {
Expand Down
4 changes: 4 additions & 0 deletions src/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { Config, createConfigFromVsCode } from "./config";
import { NoteGraph } from "./NoteGraph";
import { MarkdownLink } from "./Link";
import { Note} from "./Note";

export {
Config,
createConfigFromVsCode,
MarkdownLink,
Note,
NoteGraph
};
25 changes: 17 additions & 8 deletions src/features/create-note.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as vscode from 'vscode';
import { Feature } from "./feature";
import { NoteGraph } from "../core";
import { letUserChooseTemplate, letUserChooseText } from "../vscode/Inputs";

import { NoteGraph, MarkdownLink } from "../core";
import { letUserChooseFolder, letUserChooseTemplate, letUserChooseText } from "../vscode/Inputs";
import { createNote, openNoteInWorkspace } from "../vscode/NoteActions";
import { MarkdownLink } from "../core/Link";
import { Logger } from "../services";

import { Feature } from "./feature";


const feature: Feature = {
activate: (context: vscode.ExtensionContext, graph: NoteGraph) => {
Expand All @@ -23,11 +24,20 @@ const feature: Feature = {
} catch(err) {
return;
}

// QuickPick: Folder
try {
var folder: string = await letUserChooseFolder();
} catch(err) {
return;
}

// InputBox: Title
try{
if (selection !== undefined && !selection.isEmpty && selection.isSingleLine) {
var titleSuggestion: string = selectionText;
} else if (folder === 'dailynotes') {
var titleSuggestion: string = new Date().toISOString().split('T')[0];
} else {
var titleSuggestion: string = '';
}
Expand All @@ -52,7 +62,7 @@ const feature: Feature = {
const content: string = await createNoteContentFromTemplate(templatePath, {'title': title, 'body': body});

const rootDir: string = vscode.workspace.workspaceFolders[0].uri.fsPath;
var filePath: string = `${rootDir}/notes/${filename}.md`;
var filePath: string = `${rootDir}/${folder}/${filename}.md`;
filePath = await createNote(filePath, content, false);

// If there was an non-empty selection: Insert a markdown link instead of the selection
Expand Down Expand Up @@ -82,8 +92,7 @@ async function createNoteContentFromTemplate(templatePath: string, placeholders:

function convertToKebabCase(str: string): string {
return str
.replace(/\W/g, '')
.replace(/([a-z])([A-Z])/g, '$1-$2')
.replace(/[^a-zA-Z0-9_-\s]/g, '')
.replace(/\s+/g, '-')
.toLowerCase();
}
Expand Down
21 changes: 17 additions & 4 deletions src/vscode/Inputs.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as vscode from 'vscode';
import { NoteGraph } from '../core';
import { Note } from '../core/Note';
import * as path from "path";
import * as fs from 'fs';
import * as md5 from 'md5';
import * as path from "path";
import * as vscode from 'vscode';

import { NoteGraph, Note } from '../core';

export function letUserSearchNoteByTitle(graph: NoteGraph): Promise<Note> {
const noteQuickPick = vscode.window.createQuickPick();
Expand Down Expand Up @@ -59,4 +60,16 @@ export async function letUserChooseTemplate(): Promise<string> {
);
const selectedQuickPickItem: vscode.QuickPickItem = await vscode.window.showQuickPick(templateQuickPickItems);
return selectedQuickPickItem.description;
}

export async function letUserChooseFolder(): Promise<string> {
const rootFolder: string = vscode.workspace.workspaceFolders[0].uri.fsPath;
const folders: string[] = fs.readdirSync(rootFolder, {withFileTypes: true})
.filter(dirent => dirent.isDirectory() && !['.codekasten', '.vscode'].includes(dirent.name) ) // ToDo: Put this in settings
.map(dirent => dirent.name);
const filterQuickPickItems: vscode.QuickPickItem[] = folders.map(folder => {
return {label: folder};
});
const selectedQuickPickItem: vscode.QuickPickItem = await vscode.window.showQuickPick(filterQuickPickItems);
return selectedQuickPickItem.label;
}
5 changes: 0 additions & 5 deletions static/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,3 @@ if (window.data) {
});
console.log(`Local testing. Found ${graphData.nodes.length} nodes and ${graphData.links.length} edges`);
}





0 comments on commit acfe0a2

Please sign in to comment.