Skip to content

Commit

Permalink
Added rich text to blog posts
Browse files Browse the repository at this point in the history
  • Loading branch information
compscidr committed Jul 22, 2023
1 parent 3fe51f7 commit dba54b7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
11 changes: 11 additions & 0 deletions blog/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package blog

import (
"bytes"
"regexp"
"time"
)

Expand Down Expand Up @@ -47,3 +48,13 @@ func (p Post) Adminlink() string {
func (t Tag) Permalink() string {
return "/tag/" + t.Name
}

func (p Post) ExtractImages() []string {
var result []string
pattern := regexp.MustCompile(`\[file\]\((.+)\)`)
substrings := pattern.FindAllStringSubmatch("![file](/uploads/image-1637721856608.png)", -1)
for _, r := range substrings {
result = append(result, r[1])
}
return result
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/stretchr/testify v1.8.4
gorm.io/driver/mysql v1.5.1
gorm.io/driver/sqlite v1.5.2
gorm.io/gorm e61b98d69677
gorm.io/gorm v1.25.2-0.20230530020048-26663ab9bf55
)

require (
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
Expand Down Expand Up @@ -135,11 +134,8 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/mysql v1.5.1 h1:WUEH5VF9obL/lTtzjmML/5e6VfFR/788coz2uaVCAZw=
gorm.io/driver/mysql v1.5.1/go.mod h1:Jo3Xu7mMhCyj8dlrb3WoCaRd1FhsVh+yMXb1jUInf5o=
gorm.io/driver/sqlite v1.5.1 h1:hYyrLkAWE71bcarJDPdZNTLWtr8XrSjOWyjUYI6xdL4=
gorm.io/driver/sqlite v1.5.1/go.mod h1:7MZZ2Z8bqyfSQA1gYEV6MagQWj3cpUkJj9Z+d1HEMEQ=
gorm.io/driver/sqlite v1.5.2 h1:TpQ+/dqCY4uCigCFyrfnrJnrW9zjpelWVoEVNy5qJkc=
gorm.io/driver/sqlite v1.5.2/go.mod h1:qxAuCol+2r6PannQDpOP1FP6ag3mKi4esLnB/jHed+4=
gorm.io/gorm v1.25.1 h1:nsSALe5Pr+cM3V1qwwQ7rOkw+6UeLrX5O4v3llhHa64=
gorm.io/gorm v1.25.1/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
gorm.io/gorm v1.25.2-0.20230530020048-26663ab9bf55 h1:sC1Xj4TYrLqg1n3AN10w871An7wJM0gzgcm8jkIkECQ=
gorm.io/gorm v1.25.2-0.20230530020048-26663ab9bf55/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
Expand Down
20 changes: 20 additions & 0 deletions templates/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@
<meta name="description" content="{{ .post.PreviewContent 155 }}">
<meta name="robots" content="index, follow" />
<title>Jason Ernst: {{ .post.Title }}</title>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "BlogPosting",
"headline": "{{ .post.Title }}",
"image": [
{{range .post.ExtractImages}}
"https://www.jasonernst.com{{.}}",
{{end}}
"https://www.jasonernst.com/img/jason.jpg"
],
"datePublished": "{{ .post.CreatedAt }}",
"dateModified": "{{ .post.UpdatedAt }}",
"author": [{
"@type": "Person",
"name": "Jason Ernst",
"url": "https://www.jasonernst.com"
}]
}
</script>
{{ else }}
<meta name="description" content="Jason Ernst's blog, code, projects and publications">
<title>Jason Ernst: {{ .title }}</title>
Expand Down

0 comments on commit dba54b7

Please sign in to comment.