diff --git a/CHANGELOG.md b/CHANGELOG.md index 674ae01..e323a24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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` diff --git a/README.md b/README.md index 26bb1f9..1835a53 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/package.json b/package.json index 3376bd8..70b6ca5 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/app.js b/src/app.js index 2596055..0158569 100644 --- a/src/app.js +++ b/src/app.js @@ -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 { /** @@ -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}`; @@ -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; } @@ -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); } diff --git a/src/extension.js b/src/extension.js index c2f3d9e..5ee676e 100644 --- a/src/extension.js +++ b/src/extension.js @@ -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) {