Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: voiceinthedark/markdown-create-file
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.6.1
Choose a base ref
...
head repository: voiceinthedark/markdown-create-file
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
  • 4 commits
  • 7 files changed
  • 1 contributor

Commits on Aug 4, 2023

  1. Code Cleanup

    voiceinthedark committed Aug 4, 2023
    Copy the full SHA
    19996f9 View commit details
  2. Updated Readme

    voiceinthedark committed Aug 4, 2023
    Copy the full SHA
    d8da10a View commit details
  3. Copy the full SHA
    02f811b View commit details
  4. fix package json

    voiceinthedark committed Aug 4, 2023
    Copy the full SHA
    236731e View commit details
Showing with 72 additions and 15 deletions.
  1. +8 −0 CHANGELOG.md
  2. +22 −3 README.md
  3. BIN add_new_file.gif
  4. +14 −4 package.json
  5. BIN save_file.gif
  6. +18 −2 src/app.js
  7. +10 −6 src/extension.js
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -24,3 +24,11 @@ The extension will search for a file called `markdown-blog.yaml` and will parse
- Added auto update field feature
Any markdown file that contains a Yaml front-matter field `updated_at`
will be automatically updated on save.

### [0.6.1] 2023-08-04
- Code cleanup
- Changed and optimized autoupdater to work only on the first occurence of `updated_at`

### [0.6.3] 2023-08-05
- Added extension configuration
`autoUpdateYaml` is set to true by default. Setting it to false will stop updating the yaml on save.
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
# Markdown Blog Companion Extension

<iframe src="https://ghbtns.com/github-btn.html?user=voiceinthedark&repo=markdown-blog-extension&type=star&count=true&size=large" frameborder="0" scrolling="0" width="170" height="30"></iframe>

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.
It can be used with my blog application or as a standalone extension to quickly create a markdown article with the Front matter already preconfigured.

## Features
- Create a new markdown file in the current directory
- Yaml front-matter parsing
- External yaml configuration
- Auto update on save (can be turned off in config)

![Add new file](add_new_file.gif)

![Save file](save_file.gif)



## Usage

`ctrl + shift + p` to open vscode command palette and search for `Markdown Blog: Create File`
@@ -31,7 +45,7 @@ image: /images/2023-07-31-04-22-45.png
tags: [vue, inertia, laravel, php, blog, layout]
```
The `published_at` and `updated_at` fields can be left empty since they will be automatically generated.
The title and link will also be automatically generated according to user input.
The `title` and `link` will also be automatically generated according to user input.

## Installation
To install an extension, run the following command:
@@ -59,13 +73,18 @@ Initial release of the extension
### 0.6.0
- Added auto update field feature

### 0.6.1
- Code cleanup
- Changed and optimized autoupdater to work only on the first occurence of `updated_at`

### 0.6.3
- Added extension configuration

## Future plans

- [x] Add external yaml configuration
- [x] Update Yaml front-matter on save


- [x] Add config option to turn off auto update

---
## For more information
Binary file added add_new_file.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 14 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
"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.6.0",
"version": "0.6.3",
"publisher": "voiceinthedark",
"license": "MIT",
"icon": "voiceinthedark.png",
@@ -15,7 +15,7 @@
},
"categories": [
"Other",
"Snippets"
"Snippets"
],
"activationEvents": [
"onLanguage:markdown"
@@ -35,7 +35,17 @@
"mac": "cmd+shift+c",
"when": "editorTextFocus"
}
]
],
"configuration": {
"title": "Markdown Blog",
"properties": {
"markdown-blog.autoUpdateYaml": {
"type": "boolean",
"default": true,
"description": "Automatically update the yaml file on save"
}
}
}
},
"scripts": {
"lint": "eslint .",
@@ -56,4 +66,4 @@
"dependencies": {
"js-yaml": "^4.1.0"
}
}
}
Binary file added save_file.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 18 additions & 2 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -28,12 +28,12 @@ class App {
getWorkspacePath() {
// Get the active workspace folder
let workspaceFolders = vscode.workspace.workspaceFolders;
console.log(`workspaceFolders: ${JSON.stringify(workspaceFolders)}`);
// console.log(`workspaceFolders: ${JSON.stringify(workspaceFolders)}`);
if (!workspaceFolders) {
return '';
}
const workspaceFolderPath = workspaceFolders[0].uri.fsPath;
console.log(`workspaceFolderPath: ${workspaceFolderPath}`);
// console.log(`workspaceFolderPath: ${workspaceFolderPath}`);
return workspaceFolderPath;
}

@@ -107,6 +107,15 @@ class App {
vscode.window.showErrorMessage(message);
}

showInfoMessage(message) {
vscode.window.showInformationMessage(message);
}

/**
* Retrieves the path to the configuration file.
*
* @return {string} The path to the configuration file, or null if the file does not exist.
*/
getConfigFilePath() {
// Step 1: Check if config file exists in workspace
const workspaceFolders = vscode.workspace.workspaceFolders;
@@ -125,6 +134,12 @@ class App {
return configFilePath;
}

/**
* Reads and parses a YAML file.
*
* @param {string} filePath - The path to the YAML file.
* @return {object | null} The parsed YAML content, or null if there was an error.
*/
readYmlFile(filePath) {
// Step 2: Read and parse YAML front-matter from config file
let config = null;
@@ -163,6 +178,7 @@ class App {
'updated_at: ' + new Date().toISOString()
);
});
break;
}
}
}
16 changes: 10 additions & 6 deletions src/extension.js
Original file line number Diff line number Diff line change
@@ -11,9 +11,9 @@ function activate(context) {
'markdown-blog-extension.createFile',
function () {
let currentDirectory = app.getCurrentDirectory();
console.log(currentDirectory);
// console.log(currentDirectory);
let workspacePath = app.getWorkspacePath();
console.log(workspacePath);
// console.log(workspacePath);
if (!currentDirectory) {
currentDirectory = workspacePath;
if (!currentDirectory) {
@@ -28,6 +28,7 @@ function activate(context) {
value: '',
ignoreFocusOut: true,
prompt: 'Enter file name',
title: 'Create a new Markdown File',
})
.then(function (fileName) {
// Create file in current directory
@@ -42,15 +43,18 @@ function activate(context) {
}
);

let disposable2 = vscode.workspace.onWillSaveTextDocument((event) => {
let disposableAutoUpdateYaml = vscode.workspace.onWillSaveTextDocument((event) => {
if (event.document.fileName.endsWith('.md')) {
console.log('saving ' + event.document.fileName);
app.updateField();
const config = vscode.workspace.getConfiguration('markdown-blog');
const autoUpdateYaml = config.get('autoUpdateYaml');
if(autoUpdateYaml){
app.updateField();
}
} else console.log(`${event.document.fileName} is not a markdown file`);
});

context.subscriptions.push(disposable);
context.subscriptions.push(disposable2);
context.subscriptions.push(disposableAutoUpdateYaml);
}

// This method is called when your extension is deactivated