In VSCode, Code Snippets are templates that make it easier to enter repeating code patterns, such as loops or conditional-statements.
Code Snippets are templates that make it easier to enter repeating code patterns, such as loops or conditional-statements.
Read VS Code documentation on how to use custom code snippet
Here is the code snippet that I use for my hugo front matter creation.
"title_yaml": {
"prefix": "title_yaml",
"body": [
"---",
"title: \"Post Title\"",
"date: $CURRENT_YEAR-$CURRENT_MONTH-${CURRENT_DATE}",
"tags:",
" - hugo",
" - wordpress",
"summary: \"Post Summary\"",
"---"
],
"description": "title_yaml"
},
"title_json": {
"prefix": "title_json",
"body": [
"{",
" \"title\": \"Post Title\"",
" \"date\": \"$CURRENT_YEAR-$CURRENT_MONTH-${CURRENT_DATE}\",",
" \"tags\": [",
" \"hugo\",",
" \"wordpress\"",
" ],",
" \"summary\": \"post summary\"",
"}",
""
],
"description": "title_json"
}
To use the code snippet in Visual Studio Code, Ctrl+Space mixed with other suggestions, as well as in a dedicated snippet picker (Insert Snippet in the Command Palette).
Above will generate below output for yaml and json
---
title: "Post Title"
date: 2023-02-03
tags:
- hugo
- wordpress
summary: "Post Summary"
---
{
"title": "Post Title"
"date": "2023-02-03",
"tags": [
"hugo",
"wordpress"
],
"summary": "post summary"
}
I used this online generator to generate code snippet.