mirror of https://github.com/jlelse/GoBlog
Rename "trip" to "track"
This commit is contained in:
parent
1a6b1e6776
commit
581822dd88
5
geo.go
5
geo.go
|
@ -81,8 +81,9 @@ func (a *goBlog) proxyTiles(basePath string) http.HandlerFunc {
|
|||
osmUrl, _ := url.Parse("https://tile.openstreetmap.org/")
|
||||
tileProxy := http.StripPrefix(basePath, httputil.NewSingleHostReverseProxy(osmUrl))
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
proxyTarget := "https://tile.openstreetmap.org" + r.URL.Path
|
||||
proxyRequest, _ := http.NewRequest(http.MethodGet, proxyTarget, nil)
|
||||
targetUrl := *osmUrl
|
||||
targetUrl.Path = r.URL.Path
|
||||
proxyRequest, _ := http.NewRequest(http.MethodGet, targetUrl.String(), nil)
|
||||
// Copy request headers
|
||||
for _, k := range []string{
|
||||
"Accept-Encoding",
|
||||
|
|
|
@ -11,27 +11,27 @@ import (
|
|||
"golang.org/x/text/message"
|
||||
)
|
||||
|
||||
func (p *post) HasTrip() bool {
|
||||
func (p *post) HasTrack() bool {
|
||||
return p.firstParameter("gpx") != ""
|
||||
}
|
||||
|
||||
type tripRenderResult struct {
|
||||
type trackResult struct {
|
||||
HasPoints bool
|
||||
Paths [][]*tripPoint
|
||||
Paths [][]*trackPoint
|
||||
PathsJSON string
|
||||
Kilometers string
|
||||
Hours string
|
||||
Name string
|
||||
}
|
||||
|
||||
func (a *goBlog) renderTrip(p *post) (result *tripRenderResult, err error) {
|
||||
func (a *goBlog) getTrack(p *post) (result *trackResult, err error) {
|
||||
gpxString := p.firstParameter("gpx")
|
||||
if gpxString == "" {
|
||||
return nil, errors.New("no gpx parameter in post")
|
||||
}
|
||||
|
||||
// Parse GPX
|
||||
parseResult, err := tripParseGPX(gpxString)
|
||||
parseResult, err := trackParseGPX(gpxString)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ func (a *goBlog) renderTrip(p *post) (result *tripRenderResult, err error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
result = &tripRenderResult{
|
||||
result = &trackResult{
|
||||
HasPoints: len(parseResult.paths) > 0 && len(parseResult.paths[0]) > 0,
|
||||
Paths: parseResult.paths,
|
||||
PathsJSON: string(pathsJSON),
|
||||
|
@ -63,25 +63,25 @@ func (a *goBlog) renderTrip(p *post) (result *tripRenderResult, err error) {
|
|||
return result, nil
|
||||
}
|
||||
|
||||
type tripPoint struct {
|
||||
type trackPoint struct {
|
||||
Lat, Lon float64
|
||||
}
|
||||
|
||||
type tripParseResult struct {
|
||||
paths [][]*tripPoint
|
||||
type trackParseResult struct {
|
||||
paths [][]*trackPoint
|
||||
gpxData *gpx.GPX
|
||||
md *gpx.MovingData
|
||||
}
|
||||
|
||||
func tripParseGPX(gpxString string) (result *tripParseResult, err error) {
|
||||
result = &tripParseResult{}
|
||||
func trackParseGPX(gpxString string) (result *trackParseResult, err error) {
|
||||
result = &trackParseResult{}
|
||||
|
||||
type tripPath struct {
|
||||
type trackPath struct {
|
||||
gpxMovingData *gpx.MovingData
|
||||
points []*tripPoint
|
||||
points []*trackPoint
|
||||
}
|
||||
|
||||
var paths []*tripPath
|
||||
var paths []*trackPath
|
||||
|
||||
result.gpxData, err = gpx.ParseString(gpxString)
|
||||
if err != nil {
|
||||
|
@ -90,11 +90,11 @@ func tripParseGPX(gpxString string) (result *tripParseResult, err error) {
|
|||
for _, track := range result.gpxData.Tracks {
|
||||
for _, segment := range track.Segments {
|
||||
md := segment.MovingData()
|
||||
path := &tripPath{
|
||||
path := &trackPath{
|
||||
gpxMovingData: &md,
|
||||
}
|
||||
for _, point := range segment.Points {
|
||||
path.points = append(path.points, &tripPoint{
|
||||
path.points = append(path.points, &trackPoint{
|
||||
Lat: point.GetLatitude(), Lon: point.GetLongitude(),
|
||||
})
|
||||
}
|
|
@ -9,7 +9,7 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_renderTrip(t *testing.T) {
|
||||
func Test_geoTrack(t *testing.T) {
|
||||
app := &goBlog{
|
||||
cfg: &config{
|
||||
Db: &configDb{
|
||||
|
@ -41,7 +41,7 @@ func Test_renderTrip(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
resEn, err := app.renderTrip(post)
|
||||
resEn, err := app.getTrack(post)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.True(t, resEn.HasPoints)
|
||||
|
@ -50,7 +50,7 @@ func Test_renderTrip(t *testing.T) {
|
|||
|
||||
post.Blog = "de"
|
||||
|
||||
resDe, err := app.renderTrip(post)
|
||||
resDe, err := app.getTrack(post)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.True(t, resDe.HasPoints)
|
|
@ -61,7 +61,7 @@ func (a *goBlog) initRendering() error {
|
|||
"likelink": a.likeLink,
|
||||
"liketitle": a.likeTitle,
|
||||
"photolinks": a.photoLinks,
|
||||
"rendertrip": a.renderTrip,
|
||||
"gettrack": a.getTrack,
|
||||
// Others
|
||||
"dateformat": dateFormat,
|
||||
"isodate": isoDateFormat,
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<title>{{ with .Data.RenderedTitle }}{{ . }} - {{end}}{{ mdtitle .Blog.Title }}</title>
|
||||
{{ include "postheadmeta" . }}
|
||||
{{ with shorturl .Data }}<link rel="shortlink" href="{{ . }}">{{ end }}
|
||||
{{ include "tripheader" . }}
|
||||
{{ include "trackheader" . }}
|
||||
{{ end }}
|
||||
|
||||
{{ define "main" }}
|
||||
|
@ -18,7 +18,7 @@
|
|||
{{ content .Data false }}
|
||||
</div>
|
||||
{{ end }}
|
||||
{{ include "tripdetails" . }}
|
||||
{{ include "trackdetails" . }}
|
||||
{{ include "posttax" . }}
|
||||
</article>
|
||||
{{ include "author" . }}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
{{ define "trackdetails" }}
|
||||
{{ if .Data.HasTrack }}
|
||||
{{ $track := (gettrack .Data) }}
|
||||
{{ if $track.HasPoints }}
|
||||
{{ $lang := .Blog.Lang }}
|
||||
<p>{{ with $track.Name }}<b>{{ . }}</b> {{ end }}{{ with $track.Kilometers }}🏁 {{ . }} {{ string $lang "kilometers" }} {{ end }}{{ with $track.Hours }}⌛ {{ . }}{{ end }}</p>
|
||||
<div class="p" id="map" data-paths="{{ $track.PathsJSON }}" data-tiles="/tiles/{z}/{x}/{y}.png"></div>
|
||||
<script defer src="{{ asset "js/geotrack.js" }}"></script>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
|
@ -1,5 +1,5 @@
|
|||
{{ define "tripheader" }}
|
||||
{{ if .Data.HasTrip }}
|
||||
{{ define "trackheader" }}
|
||||
{{ if .Data.HasTrack }}
|
||||
<link rel="stylesheet" href="/x/leaflet/leaflet.css"/>
|
||||
<script src="/x/leaflet/leaflet.js"></script>
|
||||
{{ end }}
|
|
@ -1,11 +0,0 @@
|
|||
{{ define "tripdetails" }}
|
||||
{{ if .Data.HasTrip }}
|
||||
{{ $trip := (rendertrip .Data) }}
|
||||
{{ if $trip.HasPoints }}
|
||||
{{ $lang := .Blog.Lang }}
|
||||
<p>{{ with $trip.Name }}<b>{{ . }}</b> {{ end }}{{ with $trip.Kilometers }}🏁 {{ . }} {{ string $lang "kilometers" }} {{ end }}{{ with $trip.Hours }}⌛ {{ . }}{{ end }}</p>
|
||||
<div class="p" id="map" data-paths="{{ $trip.PathsJSON }}" data-tiles="/tiles/{z}/{x}/{y}.png"></div>
|
||||
<script defer src="{{ asset "js/geotrip.js" }}"></script>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
Loading…
Reference in New Issue