Micropub endpoint for my blog https://jlelse.blog/posts/hugo-micropub/
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.

83 lines
2.3 KiB

package main
import (
type HugoFrontMatter struct {
Title string `yaml:"title,omitempty"`
Published string `yaml:"date,omitempty"`
Updated string `yaml:"lastmod,omitempty"`
Tags []string `yaml:"tags,omitempty"`
Series []string `yaml:"series,omitempty"`
ExternalURL string `yaml:"externalURL,omitempty"`
IndieWeb HugoFrontMatterIndieWeb `yaml:"indieweb,omitempty"`
Syndicate []string `yaml:"syndicate,omitempty"`
TranslationKey string `yaml:"translationKey,omitempty"`
Images []string `yaml:"images,omitempty"`
Audio string `yaml:"audio,omitempty"`
type HugoFrontMatterIndieWeb struct {
Reply HugoFrontMatterReply `yaml:"reply,omitempty"`
Like HugoFrontMatterLike `yaml:"like,omitempty"`
type HugoFrontMatterReply struct {
Link string `yaml:"link,omitempty"`
Title string `yaml:"title,omitempty"`
type HugoFrontMatterLike struct {
Link string `yaml:"link,omitempty"`
Title string `yaml:"title,omitempty"`
func writeFrontMatter(entry *Entry) (string, error) {
frontMatter := &HugoFrontMatter{
Title: entry.title,
Published: entry.date,
Updated: entry.lastmod,
Tags: entry.tags,
Series: entry.series,
ExternalURL: entry.link,
IndieWeb: HugoFrontMatterIndieWeb{
Reply: HugoFrontMatterReply{
Link: entry.replyLink,
Title: entry.replyTitle,
Like: HugoFrontMatterLike{
Link: entry.likeLink,
Title: entry.likeTitle,
Syndicate: entry.syndicate,
TranslationKey: entry.translationKey,
Audio: entry.audio,
for _, image := range entry.images {
frontMatter.Images = append(frontMatter.Images, image.url)
writer := new(bytes.Buffer)
err := yaml.NewEncoder(writer).Encode(&frontMatter)
if err != nil {
return "", errors.New("failed encoding frontmatter")
return writer.String(), nil
func WriteHugoPost(entry *Entry) (string, error) {
buff := new(bytes.Buffer)
f, err := writeFrontMatter(entry)
if err != nil {
return "", err
return buff.String(), nil