hugofy-vscode icon indicating copy to clipboard operation
hugofy-vscode copied to clipboard

Custom content/posts folder setting

Open Marhc opened this issue 4 years ago • 2 comments

How can I set a custom content/posts folder like /src/site/content ?

Marhc avatar May 15 '20 11:05 Marhc

I see that this part of the code is responsible for it (src/extension.ts):

const newPost = () => {
    vscode.window.showInputBox({ placeHolder: 'Enter filename' }).then((filename) => {
        const newPostPath = path.join(vscode.workspace.rootPath, 'content', 'post', filename);
        const postPath = 'post' + path.sep + filename;
        const newPostCmd = spawn('hugo', ['new', postPath, `-s="${vscode.workspace.rootPath}"`], { shell: true });
        newPostCmd.stdout.on('data', (data) => {
            vscode.window.showInformationMessage(data);
        });
        newPostCmd.stderr.on('data', (data) => {
            console.log(`stderr: ${data}`);
            vscode.window.showInformationMessage(`Error creating new post.`);
        });
        newPostCmd.on('close', (code) => {
            if (code === 0) {
                let uripath = vscode.Uri.file(newPostPath);
                vscode.workspace.openTextDocument(uripath).then((document) => {
                    vscode.window.showTextDocument(document);
                }, err => {
                    console.log(err);
                });
            } else {
                vscode.window.showErrorMessage(`Error creating new post.`);
            }

        });
    });
};

The "post" word would need to be made a variable which can be set in the extension configuration. At the moment, the extension is not configurable. Unfortunately, I have never done TypeScript or VScode extensions. If you know how to, or know someone who knows how to, please create a PR.

theramiyer avatar Oct 11 '20 00:10 theramiyer

Try this Extension: https://marketplace.visualstudio.com/items?itemName=phoenisx.gohugo

phoenisx avatar Apr 03 '21 05:04 phoenisx