Action for creating tags in front matter for a post on my blog

I’ve got an action that creates the front matter and markdown for posting to a static blog or site. Tagging has to be done like below where each tag is on a line and starts with a dash. Is there any way to get drafts to output the tags that way?

author: hallm
pubDatetime: [[date|%Y-%m-%dT%H:%M:%S]]
title: [[title]]
featured: true
draft: false
tags:
- tag1
- tag2
description: [[selection_only]]

[[body]]

Can you share the action you’ve worked on thus far?

The template language does not have an explicit tag for that format. You could use a mustache template, which has more logic support, but it might be easier just to build your own tag value with a script. If you add a script step like the below, then in steps after that script, you would have available a [[formatted-tags]] template tag that has the tags in that format.

let s = ""
if (draft.tags.length > 0) {
	s = draft.tags.map(t => `- ${t}`).join("\n")
}
draft.setTemplateTag("formatted-tags", s)
1 Like

Ok played with it and got it to work. Had to add four spaces before the -. Now it works perfectly. I really appreciate it. Thanks.

let s = ""
if (draft.tags.length > 0) {
	s = draft.tags.map(t => `    - ${t}`).join("\n")
}
draft.setTemplateTag("formatted-tags", s)

I can’t actually post the share to the script. It keeps flagging it for some reason.