mirror of https://github.com/jlelse/GoBlog
Add option to add "location" to posts and display link to OSM
This commit is contained in:
parent
bf9dc3f11a
commit
cf316c4d18
|
@ -179,6 +179,7 @@ type configMicropub struct {
|
|||
AudioParam string `mapstructure:"audioParam"`
|
||||
PhotoParam string `mapstructure:"photoParam"`
|
||||
PhotoDescriptionParam string `mapstructure:"photoDescriptionParam"`
|
||||
LocationParam string `mapstructure:"locationParam"`
|
||||
MediaStorage *configMicropubMedia `mapstructure:"mediaStorage"`
|
||||
}
|
||||
|
||||
|
@ -251,6 +252,7 @@ func initConfig() error {
|
|||
viper.SetDefault("micropub.audioParam", "audio")
|
||||
viper.SetDefault("micropub.photoParam", "images")
|
||||
viper.SetDefault("micropub.photoDescriptionParam", "imagealts")
|
||||
viper.SetDefault("micropub.locationParam", "location")
|
||||
viper.SetDefault("activityPub.keyPath", "data/private.pem")
|
||||
viper.SetDefault("activityPub.tagsTaxonomies", []string{"tags"})
|
||||
viper.SetDefault("webmention.disableSending", false)
|
||||
|
|
1
go.mod
1
go.mod
|
@ -6,6 +6,7 @@ go 1.16
|
|||
replace github.com/yuin/goldmark-emoji => github.com/jlelse/goldmark-emoji v1.0.2-0.20210524171342-a1615b7be38a
|
||||
|
||||
require (
|
||||
git.jlel.se/jlelse/go-geouri v0.0.0-20210525190615-a9c1d50f42d6
|
||||
git.jlel.se/jlelse/goldmark-mark v0.0.0-20210522162520-9788c89266a4
|
||||
git.jlel.se/jlelse/template-strings v0.0.0-20210523080439-57437f8d23ee
|
||||
github.com/PuerkitoBio/goquery v1.6.1
|
||||
|
|
2
go.sum
2
go.sum
|
@ -12,6 +12,8 @@ cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqCl
|
|||
cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I=
|
||||
cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw=
|
||||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
||||
git.jlel.se/jlelse/go-geouri v0.0.0-20210525190615-a9c1d50f42d6 h1:d7k1NKd9fr+Eq7EtUrqUly+HDqDzpx9T9v8Gl2jJvpo=
|
||||
git.jlel.se/jlelse/go-geouri v0.0.0-20210525190615-a9c1d50f42d6/go.mod h1:eKL81ZHiGWZ4cdv9MI0ADmPiG9p0C+ajkSldNTr2ftQ=
|
||||
git.jlel.se/jlelse/goldmark-mark v0.0.0-20210522162520-9788c89266a4 h1:p3c/vCY6MUADNXWCYI/hsZ8ZEvN7LtvwHzK2B8Y6BSk=
|
||||
git.jlel.se/jlelse/goldmark-mark v0.0.0-20210522162520-9788c89266a4/go.mod h1:ZFhxwbX+afhgbzh5rpkSJUp6vIduNPtIGDrsWpIcHTE=
|
||||
git.jlel.se/jlelse/template-strings v0.0.0-20210523080439-57437f8d23ee h1:zun+B6UygGTYm+OBxK9eoPUHSd3M7AebIxXJyFyZzR4=
|
||||
|
|
29
micropub.go
29
micropub.go
|
@ -198,56 +198,81 @@ func convertMPValueMapToPost(values map[string][]string) (*post, error) {
|
|||
if h, ok := values["h"]; ok && (len(h) != 1 || h[0] != "entry") {
|
||||
return nil, errors.New("only entry type is supported so far")
|
||||
}
|
||||
delete(values, "h")
|
||||
entry := &post{
|
||||
Parameters: map[string][]string{},
|
||||
}
|
||||
if content, ok := values["content"]; ok {
|
||||
entry.Content = content[0]
|
||||
delete(values, "content")
|
||||
}
|
||||
if published, ok := values["published"]; ok {
|
||||
entry.Published = published[0]
|
||||
delete(values, "published")
|
||||
}
|
||||
if updated, ok := values["updated"]; ok {
|
||||
entry.Updated = updated[0]
|
||||
delete(values, "updated")
|
||||
}
|
||||
if status, ok := values["post-status"]; ok {
|
||||
entry.Status = postStatus(status[0])
|
||||
delete(values, "post-status")
|
||||
}
|
||||
if slug, ok := values["mp-slug"]; ok {
|
||||
entry.Slug = slug[0]
|
||||
delete(values, "mp-slug")
|
||||
}
|
||||
// Parameter
|
||||
if name, ok := values["name"]; ok {
|
||||
entry.Parameters["title"] = name
|
||||
delete(values, "name")
|
||||
}
|
||||
if category, ok := values["category"]; ok {
|
||||
entry.Parameters[appConfig.Micropub.CategoryParam] = category
|
||||
delete(values, "category")
|
||||
} else if categories, ok := values["category[]"]; ok {
|
||||
entry.Parameters[appConfig.Micropub.CategoryParam] = categories
|
||||
delete(values, "category[]")
|
||||
}
|
||||
if inReplyTo, ok := values["in-reply-to"]; ok {
|
||||
entry.Parameters[appConfig.Micropub.ReplyParam] = inReplyTo
|
||||
delete(values, "in-reply-to")
|
||||
}
|
||||
if likeOf, ok := values["like-of"]; ok {
|
||||
entry.Parameters[appConfig.Micropub.LikeParam] = likeOf
|
||||
delete(values, "like-of")
|
||||
}
|
||||
if bookmarkOf, ok := values["bookmark-of"]; ok {
|
||||
entry.Parameters[appConfig.Micropub.BookmarkParam] = bookmarkOf
|
||||
delete(values, "bookmark-of")
|
||||
}
|
||||
if audio, ok := values["audio"]; ok {
|
||||
entry.Parameters[appConfig.Micropub.AudioParam] = audio
|
||||
delete(values, "audio")
|
||||
} else if audio, ok := values["audio[]"]; ok {
|
||||
entry.Parameters[appConfig.Micropub.AudioParam] = audio
|
||||
delete(values, "audio[]")
|
||||
}
|
||||
if photo, ok := values["photo"]; ok {
|
||||
entry.Parameters[appConfig.Micropub.PhotoParam] = photo
|
||||
delete(values, "photo")
|
||||
} else if photos, ok := values["photo[]"]; ok {
|
||||
entry.Parameters[appConfig.Micropub.PhotoParam] = photos
|
||||
delete(values, "photo[]")
|
||||
}
|
||||
if photoAlt, ok := values["mp-photo-alt"]; ok {
|
||||
entry.Parameters[appConfig.Micropub.PhotoDescriptionParam] = photoAlt
|
||||
delete(values, "mp-photo-alt")
|
||||
} else if photoAlts, ok := values["mp-photo-alt[]"]; ok {
|
||||
entry.Parameters[appConfig.Micropub.PhotoDescriptionParam] = photoAlts
|
||||
delete(values, "mp-photo-alt[]")
|
||||
}
|
||||
if slug, ok := values["mp-slug"]; ok {
|
||||
entry.Slug = slug[0]
|
||||
if location, ok := values["location"]; ok {
|
||||
entry.Parameters[appConfig.Micropub.LocationParam] = location
|
||||
delete(values, "location")
|
||||
}
|
||||
for n, p := range values {
|
||||
entry.Parameters[n] = append(entry.Parameters[n], p...)
|
||||
}
|
||||
err := entry.computeExtraPostParameters()
|
||||
if err != nil {
|
||||
|
|
11
render.go
11
render.go
|
@ -15,6 +15,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
gogeouri "git.jlel.se/jlelse/go-geouri"
|
||||
"github.com/araddon/dateparse"
|
||||
servertiming "github.com/mitchellh/go-server-timing"
|
||||
)
|
||||
|
@ -170,6 +171,16 @@ func initRendering() error {
|
|||
"urlToString": func(u url.URL) string {
|
||||
return u.String()
|
||||
},
|
||||
"geouri": func(u string) *gogeouri.Geo {
|
||||
g, _ := gogeouri.Parse(u)
|
||||
return g
|
||||
},
|
||||
"geourip": func(g *gogeouri.Geo, parameter string) (s string) {
|
||||
if gp := g.Parameters[parameter]; len(gp) > 0 {
|
||||
return gp[0]
|
||||
}
|
||||
return
|
||||
},
|
||||
}
|
||||
|
||||
baseTemplate, err := template.New("base").Funcs(templateFunctions).ParseFiles(path.Join(templatesDir, templateBase+templatesExt))
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{{ define "title" }}
|
||||
<title>{{ with p .Data "title" }}{{ . }} - {{end}}{{ .Blog.Title }}</title>
|
||||
<title>{{ with title .Data }}{{ . }} - {{end}}{{ .Blog.Title }}</title>
|
||||
{{ include "postheadmeta" . }}
|
||||
{{ with shorturl .Data }}<link rel="shortlink" href="{{ . }}">{{ end }}
|
||||
{{ end }}
|
||||
|
|
|
@ -1,6 +1,21 @@
|
|||
{{ define "postmeta" }}
|
||||
<div class="p">
|
||||
{{ include "summaryandpostmeta" . }}
|
||||
{{ $loc := ( p .Data "location" ) }}
|
||||
{{ if $loc }}
|
||||
{{ with geouri $loc }}
|
||||
<div>📍 <a class="p-location h-geo" href="https://www.openstreetmap.org/?mlat={{ .Latitude }}&mlon={{ .Longitude }}" target="_blank" rel="nofollow noopener noreferrer">
|
||||
{{ $geoname := ( geourip . "name" ) }}
|
||||
{{ if $geoname }}
|
||||
<span class="p-name">{{ $geoname }}</span>
|
||||
<data class="p-longitude" value="{{ .Longitude }}" />
|
||||
<data class="p-latitude" value="{{ .Latitude }}" />
|
||||
{{ else }}
|
||||
<span class="p-latitude">{{ .Latitude }}</span>, <span class="p-longitude">{{ .Longitude }}</span>
|
||||
{{ end }}
|
||||
</a></div>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ $translations := (translations .Data) }}
|
||||
{{ if gt (len $translations) 0 }}
|
||||
<div>{{ string .Blog.Lang "translations" }}: {{ $delimiter := "" }}{{ range $i, $t := $translations }}{{ $delimiter }}<a href="{{ $t.Path }}" translate="no">{{ title $t }}</a>{{ $delimiter = ", " }}{{ end }}</div>
|
||||
|
|
Loading…
Reference in New Issue