Hugo template support #93
Unanswered
stanbar
asked this question in
Q&A — Template
Replies: 1 comment
-
Hey @stanbar, it's 2 years to the date but thought I'd share a workflow that's working for me: I use templater to configure the frontmatter needed for Hugo, then hit publish in Enveloppe. It's working well right now. Templater: <%*
// Function to convert title to slug format - without ../
const slugify = (text) => {
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}
// Function to format date for Hugo
const formatHugoDate = (dateStr) => {
// Parse the date string more explicitly
const date = moment(dateStr, ["YYYY-MM-DD", "YYYY-MM-DD ddd h:mma"]);
if (date.isValid()) {
return `${date.format('YYYY-MM-DD')}`;
}
return '2025-01-01'; // Fallback date if parsing fails
}
// Get current file
const file = tp.file.find_tfile(tp.file.path(true));
// Process frontmatter directly
await app.fileManager.processFrontMatter(file, (frontmatter) => {
// First ensure we can get a valid date
const createdDate = moment(frontmatter.created, ["YYYY-MM-DD", "YYYY-MM-DD ddd h:mma"]);
const datePrefix = createdDate.isValid() ? createdDate.format('YYYY-MM-DD') : '2025-01-16';
// Update Hugo-specific fields
frontmatter["title"] = tp.file.title;
frontmatter["slug"] = "../" + slugify(tp.file.title);
frontmatter["filename"] = `${datePrefix}-${slugify(tp.file.title)}`;
frontmatter["date"] = formatHugoDate(frontmatter.created);
frontmatter["blog"] = true;
});
-%> & the Enveloppe JSON: {
"github": {
"branch": "main",
"automaticallyMergePR": true,
"dryRun": {
"enable": false,
"folderName": "content/articles/test"
},
"tokenPath": "%configDir%/plugins/%pluginID%/env",
"api": {
"tiersForApi": "Github Free/Pro/Team (default)",
"hostname": ""
},
"workflow": {
"commitMessage": "[🌱] Publish Post ",
"name": ""
},
"verifiedRepo": true
},
"upload": {
"behavior": "fixed",
"defaultName": "content/articles",
"rootFolder": "",
"yamlFolderKey": "",
"frontmatterTitle": {
"enable": true,
"key": "filename"
},
"replaceTitle": [],
"replacePath": [],
"autoclean": {
"includeAttachments": true,
"enable": false,
"excluded": []
},
"folderNote": {
"enable": false,
"rename": "index.md",
"addTitle": {
"enable": false,
"key": "title"
}
},
"metadataExtractorPath": ""
},
"conversion": {
"hardbreak": false,
"dataview": true,
"censorText": [
{
"entry": "==",
"replace": "**",
"flags": "",
"after": false
},
{
"entry": "- [!@$]",
"replace": "- ",
"flags": "",
"after": false
}
],
"tags": {
"inline": false,
"exclude": [],
"fields": []
},
"links": {
"internal": true,
"unshared": false,
"wiki": true,
"slugify": "lower",
"unlink": true
}
},
"embed": {
"attachments": true,
"overrideAttachments": [],
"keySendFile": [],
"notes": true,
"folder": "",
"convertEmbedToLinks": "bake",
"charConvert": "->",
"unHandledObsidianExt": [],
"sendSimpleLinks": false,
"forcePush": false,
"bake": {
"textBefore": "",
"textAfter": ""
}
},
"plugin": {
"shareKey": "blog",
"excludedFolder": [],
"copyLink": {
"enable": true,
"links": "mbbroberg.fun",
"removePart": [],
"transform": {
"toUri": true,
"slugify": "strict",
"applyRegex": []
}
},
"setFrontmatterKey": "up",
"saveTabId": true
},
"tabsId": "text-conversion"
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello, I would like to use this plugin with my Hugo project.
Have anyone managed to integrate those two?
Is there any template for Hugo pipeline?
Beta Was this translation helpful? Give feedback.
All reactions