Skip to content

Commit 546ee39

Browse files
committed
feat(blog): add author field
1 parent 6f31015 commit 546ee39

File tree

7 files changed

+36
-10
lines changed

7 files changed

+36
-10
lines changed

articles/How I deploy Nix + Docker.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
title: How I deploy Nix + Docker
33
date: 2024-06-09
44
uri: deploy-nix-docker
5+
author:
6+
name: drawbu
7+
email: contact@drawbu.dev
58
---
69

710
Hello everyone :)

articles/Install NixOS on Contabo server.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
title: How to install NixOS on a Contabo Server
33
date: 2023-08-02
44
uri: install-nixos-contabo-vps
5+
author:
6+
name: drawbu
7+
email: contact@drawbu.dev
58
---
69

710
In this guide, we'll see how to setup NixOS on a Ubuntu 22.04 Contabo VPS.

articles/Server block Ubuntu + Nginx + systemd.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
title: How to setup a server block with Nginx + systemd on Ubuntu with HTTPS
33
date: 2023-05-02
44
uri: server-block-nginx-systemd-ubuntu-https
5+
author:
6+
name: drawbu
7+
email: contact@drawbu.dev
58
---
69

710
In this guide, we are going to use the keyword for you to replace. There will be `REPOSITORY ` and `DOMAIN_NAME` to replace.

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/yuin/goldmark v1.7.8
1212
github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc
1313
github.com/yuin/goldmark-meta v1.1.0
14-
gopkg.in/yaml.v2 v2.4.0
14+
gopkg.in/yaml.v3 v3.0.1
1515
)
1616

1717
require (
@@ -28,4 +28,5 @@ require (
2828
github.com/rivo/uniseg v0.4.7 // indirect
2929
golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa // indirect
3030
golang.org/x/sys v0.30.0 // indirect
31+
gopkg.in/yaml.v2 v2.4.0 // indirect
3132
)

pkg/routes/blog/article.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,30 @@ import (
1414
highlighting "github.com/yuin/goldmark-highlighting/v2"
1515
meta "github.com/yuin/goldmark-meta"
1616
mdParser "github.com/yuin/goldmark/parser"
17-
"gopkg.in/yaml.v2"
17+
"gopkg.in/yaml.v3"
1818
)
1919

2020
type article struct {
2121
Title string
2222
Date time.Time
2323
Content []byte
2424
Uri string
25+
Author articleAuthor
26+
}
27+
28+
type articleAuthor struct {
29+
Name string
30+
Email string
2531
}
2632

2733
type articleMetadata struct {
28-
Title string `yaml:"title"`
29-
Date ArticleDate `yaml:"date"`
30-
Uri string `yaml:"uri"`
34+
Title string `yaml:"title"`
35+
Date ArticleDate `yaml:"date"`
36+
Uri string `yaml:"uri"`
37+
Author struct {
38+
Name string `yaml:"name"`
39+
Email string `yaml:"email,omitempty"`
40+
} `yaml:"author"`
3141
}
3242

3343
func NewArticle(file fs.File) (*article, error) {
@@ -53,11 +63,15 @@ func NewArticle(file fs.File) (*article, error) {
5363
Date: metadata.Date.Time,
5464
Content: buf.Bytes(),
5565
Uri: uri,
66+
Author: articleAuthor{
67+
Email: metadata.Author.Email,
68+
Name: metadata.Author.Name,
69+
},
5670
}, nil
5771
}
5872

5973
func getMetadata(context mdParser.Context) (*articleMetadata, error) {
60-
metadata, err := meta.TryGetItems(context)
74+
metadata, err := meta.TryGet(context)
6175
if err != nil {
6276
return nil, fmt.Errorf("Could not get article metadata: %s", err)
6377
}
@@ -67,9 +81,11 @@ func getMetadata(context mdParser.Context) (*articleMetadata, error) {
6781
return nil, fmt.Errorf("Could not Marshal metadata: %s", err)
6882
}
6983
var final articleMetadata
70-
err = yaml.Unmarshal(out, &final)
84+
if err = yaml.Unmarshal(out, &final); err != nil {
85+
return nil, fmt.Errorf("Failed to unmarshal metadata: %s", err)
86+
}
7187

72-
return &final, err
88+
return &final, nil
7389
}
7490

7591
func fileToMarkdown(file fs.File, buf *bytes.Buffer) (mdParser.Context, error) {

pkg/routes/blog/article.templ

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package blog
33
templ articleShow(article article) {
44
<div class="flex flex-col gap-4">
55
<h1>{ article.Title }</h1>
6-
<span class="text-gray-500">Written the { article.Date.Format("2 January 2006") } by drawbu</span>
6+
<span class="text-gray-500">Written the { article.Date.Format("2 January 2006") } by { article.Author.Name }</span>
77
<a href="/blog">Back to blog</a>
88
<div id="article" class="flex flex-col gap-4" hx-disable>
99
@templ.Raw(string(article.Content))

pkg/routes/blog/rss.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func makeFeed() feeds.Feed {
5050
Title: item.Title,
5151
Link: &feeds.Link{Href: fmt.Sprintf("https://drawbu.dev/blog/%s", item.Uri)},
5252
// Description: "A discussion on controlled parallelism in golang",
53-
Author: &feeds.Author{Name: "Clément (drawbu)", Email: "contact@drawbu.dev"},
53+
Author: &feeds.Author{Name: item.Author.Name, Email: item.Author.Email},
5454
Created: item.Date,
5555
})
5656
}

0 commit comments

Comments
 (0)