Skip to content

Commit

Permalink
Added command Keybinding
Browse files Browse the repository at this point in the history
  • Loading branch information
voiceinthedark committed Aug 3, 2023
1 parent ed8ca93 commit 638763e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 54 deletions.
58 changes: 12 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,65 +1,31 @@
# markdown-create-file README
# Markdown Blog Companion Extension

This is the README for your extension "markdown-create-file". After writing up a brief description, we recommend including the following sections.
A markdown extension which is a companion to my [markdown-blog](https://github.com/voiceinthedark/markdown-blog).
A new markdown file will be created in the current directory with the required Yaml front-matter required to display the blog's articles.

## Features
## Usage

Describe specific features of your extension including screenshots of your extension in action. Image paths are relative to this README file.
`ctrl + shift + p` to open vscode command palette and search for `Markdown Blog: Create File`
Or inside the active text editor press `ctrl + shift + c`

For example if there is an image subfolder under your extension project workspace:
## Installation

\!\[feature X\]\(images/feature-x.png\)

> Tip: Many popular extensions utilize animations. This is an excellent way to show off your extension! We recommend short, focused animations that are easy to follow.
## Requirements

If you have any requirements or dependencies, add a section describing those and how to install and configure them.

## Extension Settings

Include if your extension adds any VS Code settings through the `contributes.configuration` extension point.

For example:

This extension contributes the following settings:

* `myExtension.enable`: Enable/disable this extension.
* `myExtension.thing`: Set to `blah` to do something.

## Known Issues

Calling out known issues can help limit users opening duplicate issues against your extension.

## Release Notes
### 0.4.0

Users appreciate release notes as you update your extension.

### 1.0.0
Initial release of the extension

Initial release of ...

### 1.0.1

Fixed issue #.

### 1.1.0

Added features X, Y, and Z.

---

## Working with Markdown

You can author your README using Visual Studio Code. Here are some useful editor keyboard shortcuts:

* Split the editor (`Cmd+\` on macOS or `Ctrl+\` on Windows and Linux)
* Toggle preview (`Shift+Cmd+V` on macOS or `Shift+Ctrl+V` on Windows and Linux)
* Press `Ctrl+Space` (Windows, Linux, macOS) to see a list of Markdown snippets

## For more information

* [Visual Studio Code's Markdown Support](http://code.visualstudio.com/docs/languages/markdown)
* [Markdown Syntax Reference](https://help.github.com/articles/markdown-basics/)
- [GitHub repo](https://github.com/voiceinthedark/markdown-blog-extension)
- [Markdown Blog](https://github.com/voiceinthedark/markdown-blog)


**Enjoy!**
18 changes: 12 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
{
"name": "markdown-create-file",
"displayName": "markdown-create-file",
"name": "markdown-blog-extension",
"displayName": "Markdown Blog Extension",
"description": "A companion extension to my markdown-blog which will create a new file in the current directory complete with the required Yaml scaffolding",
"version": "0.0.1",
"version": "0.4.0",
"engines": {
"vscode": "^1.80.0"
},
"categories": [
"Other", "Snippets"
],
"activationEvents": [],
"main": "./extension.js",
"main": "./src/extension.js",
"contributes": {
"commands": [{
"command": "markdown-create-file.createFile",
"title": "Markdown create file: Create File"
"command": "markdown-blog-extension.createFile",
"title": "Markdown Blog: Create File"
}],
"keybindings": [{
"command": "markdown-blog-extension.createFile",
"key": "ctrl+shift+c",
"mac": "cmd+shift+c",
"when": "editorTextFocus"
}]
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion app.js → src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class App{

const filePath = path.join(currentDirectory, fileName);
// fill the file with a YAML frontmatter
const data = `---\ntitle: ${originalFilename.split('.')[0]}\npublished_at: ${new Date().toISOString()}\nupdated_at: ${new Date().toISOString()}\ntype: article\ndescription: Enter description here\nlink: /${new Date().getFullYear()}/${originalFilename}\nimage: image.png\ntags: [tag1,tag2]\n---`;
const data = `---\ntitle: ${originalFilename.split('.')[0]}\npublished_at: ${new Date().toISOString()}\nupdated_at: ${new Date().toISOString()}\ntype: article\ndescription: Enter description here\nlink: /${new Date().getFullYear()}/${originalFilename}\nimage: images/image.png\ntags: [tag1,tag2]\n---`;

fs.writeFile(filePath, data.trim(), err => {
if(err) {
Expand Down
6 changes: 5 additions & 1 deletion extension.js → src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function activate(context) {
// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
let disposable = vscode.commands.registerCommand('markdown-create-file.createFile', function () {
let disposable = vscode.commands.registerCommand('markdown-blog-extension.createFile', function () {
// The code you place here will be executed every time your command is executed

let currentDirectory = app.getCurrentDirectory();
Expand All @@ -40,6 +40,10 @@ function activate(context) {
}).then(function (fileName) {
// Create file in current directory
let filepath = app.createFile(currentDirectory, fileName);
if(!filepath) {
app.showErrorMessage('Failed to create file');
return;
}
// get the last created file and show it
vscode.window.showTextDocument(vscode.Uri.file(filepath));
})
Expand Down

0 comments on commit 638763e

Please sign in to comment.