Skip to content

Commit

Permalink
Fixed user input issues
Browse files Browse the repository at this point in the history
  • Loading branch information
voiceinthedark committed Aug 4, 2023
1 parent 227a455 commit cfce2d5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ All notable changes to the "markdown-create-file" extension will be documented i
- Added Yaml front-matter config file parsing
The extension will search for a file called `markdown-blog.yaml` and will parse the front-matter from it. The file needs to be in a correct yaml format.

### [0.5.1] 2023-08-04
- Fixed issue with userinput containing spaces
- Fixed issue with user input not ending with a `.md`
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ Initial release of the extension
- Added Yaml front-matter config file parsing.
The extension will search for a file called `markdown-blog.yaml` and will parse the front-matter from it. The file needs to be in a correct yaml format.

### 0.5.1
- Fixed issue with userinput containing spaces
- Fixed issue with user input not ending with a `.md`


## Future plans

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.5.0",
"version": "0.5.1",
"publisher": "voiceinthedark",
"license": "MIT",
"icon": "voiceinthedark.png",
Expand Down
19 changes: 14 additions & 5 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const vscode = require('vscode');
const path = require('path');
const fs = require('fs');
const yaml = require('js-yaml');
const { title } = require('process');

class App {
/**
Expand Down Expand Up @@ -46,6 +45,16 @@ class App {
* @return {string} The path of the created file.
*/
createFile(currentDirectory, fileName) {
if(!fileName.endsWith('.md')) {
fileName += '.md';
}
// if the name contains spaces or special characters, replace them with dashes
if(fileName.includes(' ')) {
fileName = fileName.split(/\s+/g).join('-');
}

// if the file already exists, ask the user if they want to overwrite it

const originalFilename = fileName;
// prefixes filename with the current date
fileName = `${new Date().getFullYear()}-${new Date().getMonth()}-${new Date().getDate()}-${fileName}`;
Expand Down Expand Up @@ -97,7 +106,7 @@ class App {
const folderPath = folder.uri.fsPath;
const filePath = `${folderPath}/markdown-blog.yaml`;
if (fs.existsSync(filePath)) {
console.log(`configFilePath: ${filePath}`);
// console.log(`configFilePath: ${filePath}`);
configFilePath = filePath;
break;
}
Expand All @@ -111,12 +120,12 @@ class App {
let config = null;
if (filePath) {
try {
console.log('Reading file:', filePath);
// console.log('Reading file:', filePath);
const configContent = fs.readFileSync(filePath, 'utf8');
console.log('File content:', configContent);
// console.log('File content:', configContent);

config = yaml.load(configContent);
console.log('Parsed config:', config);
// console.log('Parsed config:', config);
} catch (error) {
console.error('Error reading YAML file:', error);
}
Expand Down
1 change: 0 additions & 1 deletion src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ function activate(context) {
value: '',
ignoreFocusOut: true,
}).then(function (fileName) {
app.readYmlFile(app.getConfigFilePath());
// Create file in current directory
let filepath = app.createFile(currentDirectory, fileName);
if(!filepath) {
Expand Down

0 comments on commit cfce2d5

Please sign in to comment.