You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

55 lines
1.5 KiB

import {
Uri,
window
} from 'vscode';
import { FileController } from './api/controller';
function handleError(err) {
if (err) {
window.showErrorMessage(err);
}
return err;
}
export interface INewFileOptions {
relativeToRoot?: boolean;
}
export interface INewFolderOptions {
relativeToRoot?: boolean;
}
export const controller = new FileController();
export function newJekyllFile(options?: INewFileOptions) {
const { relativeToRoot = false } = options || {};
const delim: string = '-';
const ending: string = 'xxxxx.md';
const date: Date = new Date();
let monthDay: string = date.getDate().toString(); // Get the day as a number (1-31)
let month: number = date.getMonth(); // Get the month as a number (0-11) 2018-05-05-xxxxx.md
const fullYear: string = date.getFullYear().toString();
if (monthDay.length === 1) {
monthDay = '0'.concat(monthDay);
}
month++;
let monthStr: string = month.toString();
if (monthStr.length === 1) {
monthStr = '0'.concat(monthStr);
}
const outputStr: string = fullYear.concat(delim, monthStr, delim, monthDay, delim, ending);
// console.log(outputStr);
// console.log(date);
return controller.showNewJekyllFileDialog({ value: outputStr, valueSelection: [11, 16] })
.then((fileItem) => controller.create({ fileItem }))
.then((fileItem) => controller.openFileInEditor(fileItem))
.catch(handleError);
}